List of usage examples for java.util SortedMap size
int size();
From source file:org.ambraproject.article.service.BrowseServiceSolrTest.java
@Test(dataProvider = "articleCategoryCount") public void testGetArticleCountsByCategory(String journalKey, Map<String, Long> expectedCounts) { SortedMap<String, Long> results = browseService.getSubjectsForJournal(journalKey); assertNotNull(results, "returned null results"); assertEquals(results.size(), expectedCounts.size(), "returned incorrect number of categories"); for (String category : expectedCounts.keySet()) { assertTrue(results.containsKey(category), "didn't return expected category " + category); assertEquals(results.get(category), expectedCounts.get(category), "Returned incorrect count for category " + category); }//w ww . j av a 2 s.c o m }
From source file:com.cloudera.oryx.kmeans.computation.local.SamplingRun.java
@Override public Collection<RealVector> call() throws Exception { SortedMap<Double, RealVector> reservoir = Maps.newTreeMap(); for (RealVector v : vecs) { Distance d = index.getDistance(v, foldId, true); if (d.getSquaredDistance() > 0.0) { double score = Math.log(random.nextDouble()) / d.getSquaredDistance(); if (reservoir.size() < sampleCount) { reservoir.put(score, v); } else if (score > reservoir.firstKey()) { reservoir.remove(reservoir.firstKey()); reservoir.put(score, v); }/*from www.jav a 2 s .c om*/ } } return reservoir.values(); }
From source file:com.haulmont.cuba.web.sys.WebJarResourceResolver.java
protected String getFullPath(SortedMap<String, String> pathIndex, String partialPath) { if (partialPath.charAt(0) == '/') { partialPath = partialPath.substring(1); }//from w w w . ja v a 2s. c om String reversePartialPath = reversePath(partialPath); SortedMap<String, String> fullPathTail = pathIndex.tailMap(reversePartialPath); if (fullPathTail.size() == 0) { if (log.isTraceEnabled()) { printNotFoundTraceInfo(pathIndex, partialPath); } throwNotFoundException(partialPath); } Iterator<Map.Entry<String, String>> fullPathTailIterator = fullPathTail.entrySet().iterator(); Map.Entry<String, String> fullPathEntry = fullPathTailIterator.next(); if (!fullPathEntry.getKey().startsWith(reversePartialPath)) { if (log.isTraceEnabled()) { printNotFoundTraceInfo(pathIndex, partialPath); } throwNotFoundException(partialPath); } String fullPath = fullPathEntry.getValue(); if (fullPathTailIterator.hasNext()) { List<String> matches = null; while (fullPathTailIterator.hasNext()) { Map.Entry<String, String> next = fullPathTailIterator.next(); if (next.getKey().startsWith(reversePartialPath)) { if (matches == null) { matches = new ArrayList<>(); } matches.add(next.getValue()); } else { break; } } if (matches != null) { matches.add(fullPath); throw new MultipleMatchesException("Multiple matches found for " + partialPath + ". Please provide a more specific path, for example by including a version number.", matches); } } return fullPath; }
From source file:com.github.joshelser.accumulo.DelimitedIngestMiniClusterTest.java
@Test public void testIngest() throws Exception { final File csvData = generateCsvData(); FS.copyFromLocalFile(new Path(csvData.getAbsolutePath()), new Path(csvData.getName())); // Create a table final String tableName = testName.getMethodName(); Connector conn = MAC.getConnector("root", new PasswordToken(ROOT_PASSWORD)); conn.tableOperations().create(tableName); ARGS.setTableName(tableName);/*from w w w . j a v a 2 s . c om*/ ARGS.setInput(Collections.singletonList(csvData.getName())); ARGS.setColumnMapping(DelimitedIngest.ROW_ID + ",f1:q1,f1:q2,f1:q3,f1:q4,f1:q5,f1:q6,f1:q7,f1:q8,f1:q9"); DelimitedIngest ingester = new DelimitedIngest(ARGS); assertEquals(ReturnCodes.NORMAL, ingester.call().intValue()); BatchScanner bs = conn.createBatchScanner(tableName, new Authorizations(), 4); bs.addScanIterator(new IteratorSetting(50, WholeRowIterator.class)); bs.setRanges(Collections.singleton(new Range())); long numRows = 0; try { for (Entry<Key, Value> entry : bs) { SortedMap<Key, Value> row = WholeRowIterator.decodeRow(entry.getKey(), entry.getValue()); // One "column" is the rowId assertEquals("Unexpected columns in row: " + row, NUM_COLUMNS - 1, row.size()); int csvColumns = 0; for (Entry<Key, Value> rowEntry : row.entrySet()) { Key k = rowEntry.getKey(); Value v = rowEntry.getValue(); if (csvColumns == 0) { assertEquals("column" + String.format("%05d", numRows) + "_" + csvColumns, k.getRow().toString()); csvColumns++; } assertEquals("f1", k.getColumnFamily().toString()); assertEquals("q" + csvColumns, k.getColumnQualifier().toString()); assertEquals("column" + String.format("%05d", numRows) + "_" + csvColumns, v.toString()); csvColumns++; } numRows++; } } finally { if (null != bs) { bs.close(); } } assertEquals(NUM_ROWS, numRows); }
From source file:com.redhat.rhn.frontend.action.kickstart.PowerManagementAction.java
/** * Sets the page attributes./*from ww w . jav a 2 s.c o m*/ * * @param request the request * @param context the context * @param server the server * @param user the user * @param strutsDelegate the Struts delegate * @param errors ActionErrors that might have already been raised */ private void setAttributes(HttpServletRequest request, RequestContext context, Server server, User user, StrutsDelegate strutsDelegate, ActionErrors errors) { request.setAttribute(RequestContext.SID, server.getId()); request.setAttribute(RequestContext.SYSTEM, server); SortedMap<String, String> types = setUpPowerTypes(request, strutsDelegate, errors); ensureAgentInstalled(request, strutsDelegate, errors); if (types.size() > 0) { SystemRecord record = getSystemRecord(user, server); if (record == null) { request.setAttribute(POWER_TYPE, types.get(types.firstKey())); } else { request.setAttribute(POWER_TYPE, record.getPowerType()); request.setAttribute(POWER_ADDRESS, record.getPowerAddress()); request.setAttribute(POWER_USERNAME, record.getPowerUsername()); request.setAttribute(POWER_PASSWORD, record.getPowerPassword()); request.setAttribute(POWER_ID, record.getPowerId()); } } }
From source file:com.espertech.esper.epl.join.table.PropertySortedEventTable.java
private Set<EventBean> normalize(SortedMap<Object, Set<EventBean>> submap) { if (submap.size() == 0) { return null; }/*from w w w . jav a 2s .c o m*/ if (submap.size() == 1) { return submap.get(submap.firstKey()); } Set<EventBean> result = new LinkedHashSet<EventBean>(); for (Map.Entry<Object, Set<EventBean>> entry : submap.entrySet()) { result.addAll(entry.getValue()); } return result; }
From source file:com.espertech.esper.epl.join.table.PropertySortedEventTable.java
private Collection<EventBean> normalizeCollection(SortedMap<Object, Set<EventBean>> submap) { if (submap.size() == 0) { return null; }// w ww. j av a 2s .com if (submap.size() == 1) { return submap.get(submap.firstKey()); } Deque<EventBean> result = new ArrayDeque<EventBean>(); for (Map.Entry<Object, Set<EventBean>> entry : submap.entrySet()) { result.addAll(entry.getValue()); } return result; }
From source file:net.sourceforge.msscodefactory.cfcore.v1_11.GenKbRam.GenKbRamISOCurrencyTable.java
public GenKbISOCurrencyBuff[] readDerivedByCcyCdIdx(GenKbAuthorization Authorization, String ISOCode) { final String S_ProcName = "GenKbRamISOCurrency.readDerivedByCcyCdIdx() "; GenKbISOCurrencyByCcyCdIdxKey key = schema.getFactoryISOCurrency().newCcyCdIdxKey(); key.setRequiredISOCode(ISOCode);/*w w w . j a v a2s . co m*/ GenKbISOCurrencyBuff[] recArray; if (dictByCcyCdIdx.containsKey(key)) { SortedMap<GenKbISOCurrencyPKey, GenKbISOCurrencyBuff> subdictCcyCdIdx = dictByCcyCdIdx.get(key); recArray = new GenKbISOCurrencyBuff[subdictCcyCdIdx.size()]; Iterator<GenKbISOCurrencyBuff> iter = subdictCcyCdIdx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new GenKbISOCurrencyBuff[0]; } return (recArray); }
From source file:com.espertech.esper.epl.join.table.PropertySortedEventTable.java
private Collection<EventBean> normalizeCollection(SortedMap<Object, Set<EventBean>> submapOne, SortedMap<Object, Set<EventBean>> submapTwo) { if (submapOne.size() == 0) { return normalizeCollection(submapTwo); }//from ww w . j a v a2 s . c om if (submapTwo.size() == 0) { return normalizeCollection(submapOne); } ArrayDeque<EventBean> result = new ArrayDeque<EventBean>(); for (Map.Entry<Object, Set<EventBean>> entry : submapOne.entrySet()) { result.addAll(entry.getValue()); } for (Map.Entry<Object, Set<EventBean>> entry : submapTwo.entrySet()) { result.addAll(entry.getValue()); } return result; }
From source file:com.espertech.esper.epl.join.table.PropertySortedEventTable.java
private Set<EventBean> normalize(SortedMap<Object, Set<EventBean>> submapOne, SortedMap<Object, Set<EventBean>> submapTwo) { if (submapOne.size() == 0) { return normalize(submapTwo); }//from ww w .j a v a 2 s .c o m if (submapTwo.size() == 0) { return normalize(submapOne); } Set<EventBean> result = new LinkedHashSet<EventBean>(); for (Map.Entry<Object, Set<EventBean>> entry : submapOne.entrySet()) { result.addAll(entry.getValue()); } for (Map.Entry<Object, Set<EventBean>> entry : submapTwo.entrySet()) { result.addAll(entry.getValue()); } return result; }