List of usage examples for java.util SortedMap headMap
SortedMap<K, V> headMap(K toKey);
From source file:org.neo4j.gis.spatial.OsmAnalysisTest.java
public void testAnalysis(String osm, int years, int days) throws Exception { Node osmRoot = ReferenceNodes.getReferenceNode(graphDb(), "osm_root"); Node osmImport = osmRoot.getSingleRelationship(OSMRelation.OSM, Direction.OUTGOING).getEndNode(); Node usersNode = osmImport.getSingleRelationship(OSMRelation.USERS, Direction.OUTGOING).getEndNode(); Map<String, User> userIndex = collectUserChangesetData(usersNode); SortedSet<User> topTen = getTopTen(userIndex); SpatialDatabaseService spatialService = new SpatialDatabaseService(graphDb()); SortedMap<String, Layer> layers = exportPoints(osm, spatialService, topTen); layers = removeEmptyLayers(layers);/*from w w w.j a v a2 s. c o m*/ ReferencedEnvelope bbox = getEnvelope(layers.values()); StyledImageExporter imageExporter = new StyledImageExporter(graphDb()); String exportDir = "target/export/" + osm + "/analysis"; imageExporter.setExportDir(exportDir); imageExporter.setZoom(2.0); imageExporter.setOffset(-0.05, -0.05); imageExporter.setSize(1280, 800); for (String layerName : layers.keySet()) { SortedMap<String, Layer> layersSubset = new TreeMap<String, Layer>(layers.headMap(layerName)); String[] to_render = new String[Math.min(10, layersSubset.size() + 1)]; to_render[0] = layerName; if (layersSubset.size() > 0) { for (int i = 1; i < to_render.length; i++) { String name = layersSubset.lastKey(); layersSubset.remove(name); to_render[i] = name; } } System.out.println("exporting " + layerName); imageExporter.saveLayerImage(to_render, // (String[]) // layersSubset.keySet().toArray(new // String[] {}), "/Users/davidesavazzi/Desktop/amanzi/awe trial/osm_germany/germany_poi_small.sld", new File(layerName + ".png"), bbox); } }
From source file:org.omnaest.utils.table.TableTest.java
@Test public void testMoreComplexManagedBeanListAdapter() { final Table<Object> table = new ArrayTable<Object>(Object.class) .setExceptionHandler(new ExceptionHandlerEPrintStackTrace()); table.setColumnTitles(Arrays.asList("fieldDate", "fieldDouble", "fieldLong", "fieldString")); final SortedMap<Date, Set<TestDomain>> sortedMap = table.index().of(new KeyExtractor<Date, TestDomain>() { private static final long serialVersionUID = -2612713147012980832L; @Override/* w w w . jav a 2 s. co m*/ public Date extractKey(TestDomain testDomain) { final Date date = testDomain.getFieldDate(); return date; } }, TestDomain.class); final List<TestDomain> domainList = table.as().managedBeanList(TestDomain.class); final Date date = new Date(); for (int ii = 0; ii < 30; ii++) { TestDomain testDomain = new TestDomain(); final Date fieldDate = newRelativeDate(date, ii / 2); testDomain.setFieldDate(fieldDate); testDomain.setFieldDouble(123.5 + ii); testDomain.setFieldLong(134l + ii); testDomain.setFieldString("test" + ii); domainList.add(testDomain); assertEquals(1 + ii, domainList.size()); assertEquals(domainList.size(), table.rowSize()); assertEquals(Math.round(domainList.size() / 2.0), sortedMap.size()); } { final int daysBack = 5; SortedMap<Date, Set<TestDomain>> headMap = sortedMap.headMap(newRelativeDate(date, daysBack)); //System.out.println( headMap ); Set<TestDomain> mergeAll = SetUtils.mergeAll(headMap.values()); //System.out.println( mergeAll ); assertEquals(daysBack * 2, mergeAll.size()); } //System.out.println( table ); //System.out.println( MapUtils.toString( sortedMap ) ); }
From source file:org.omnaest.utils.table.TableTest.java
@Test public void testIndexOfArbitraryKeyExtractor() { Table<String> table = this.filledTable(100, 5); KeyExtractor<Integer, RowDataReader<String>> keyExtractor = new KeyExtractor<Integer, RowDataReader<String>>() { private static final long serialVersionUID = -4201644938610833630L; @Override//from w w w . j a v a 2 s .c o m public Integer extractKey(RowDataReader<String> rowDataReader) { String[] elements = rowDataReader.getElements(); String[] tokens = elements[1].split(":"); return Integer.valueOf(tokens[0]); } }; SortedMap<Integer, Set<Row<String>>> sortedMap = table.index().of(keyExtractor); { assertNotNull(sortedMap); assertEquals(table.rowSize(), sortedMap.size()); assertTrue(sortedMap.containsKey(0)); } table.removeRow(0); { assertFalse(sortedMap.containsKey(0)); assertTrue(sortedMap.containsKey(1)); assertFalse(sortedMap.containsKey(101)); table.setElement(0, 1, "101:88"); assertTrue(sortedMap.containsKey(101)); Set<Row<String>> rowSet = sortedMap.get(101); assertEquals(1, rowSet.size()); } { assertSame(sortedMap, table.index().of(keyExtractor)); } table.setRowElements(1, "0:0", "200:0"); { assertTrue(sortedMap.containsKey(200)); } { SortedMap<Integer, Set<Row<String>>> tailMap = sortedMap.tailMap(90); assertEquals(100 - 90 + 2, tailMap.size()); assertEquals(90, tailMap.firstKey().intValue()); assertEquals(200, tailMap.lastKey().intValue()); } { SortedMap<Integer, Set<Row<String>>> headMap = sortedMap.headMap(10); assertEquals(9 - 2, headMap.size()); assertEquals(3, headMap.firstKey().intValue()); assertEquals(9, headMap.lastKey().intValue()); } { table.clear(); assertTrue(sortedMap.isEmpty()); } }
From source file:org.springframework.amqp.rabbit.support.PublisherCallbackChannelImpl.java
private void processAck(long seq, boolean ack, boolean multiple) { if (multiple) { /*//w ww . j a v a 2s .c o m * Piggy-backed ack - extract all Listeners for this and earlier * sequences. Then, for each Listener, handle each of it's acks. */ synchronized (this.pendingConfirms) { Map<Long, Listener> involvedListeners = this.listenerForSeq.headMap(seq + 1); // eliminate duplicates Set<Listener> listeners = new HashSet<Listener>(involvedListeners.values()); for (Listener involvedListener : listeners) { // find all unack'd confirms for this listener and handle them SortedMap<Long, PendingConfirm> confirmsMap = this.pendingConfirms.get(involvedListener); if (confirmsMap != null) { Map<Long, PendingConfirm> confirms = confirmsMap.headMap(seq + 1); Iterator<Entry<Long, PendingConfirm>> iterator = confirms.entrySet().iterator(); while (iterator.hasNext()) { Entry<Long, PendingConfirm> entry = iterator.next(); iterator.remove(); doHandleConfirm(ack, involvedListener, entry.getValue()); } } } } } else { Listener listener = this.listenerForSeq.get(seq); if (listener != null) { PendingConfirm pendingConfirm = this.pendingConfirms.get(listener).remove(seq); if (pendingConfirm != null) { doHandleConfirm(ack, listener, pendingConfirm); } } else { logger.error("No listener for seq:" + seq); } } }
From source file:therian.operator.immutablecheck.DefaultImmutableChecker.java
private static void addTypeTo(final Set<Class<?>> target, final SortedMap<String, ?> sortedMap) { addTypeTo(target, (Map<String, ?>) sortedMap); addTypeTo(target, (Map<String, ?>) sortedMap.headMap("foo")); addTypeTo(target, (Map<String, ?>) sortedMap.tailMap("foo")); addTypeTo(target, (Map<String, ?>) sortedMap.subMap("foo", "foo")); }