List of usage examples for java.util SortedMap get
V get(Object key);
From source file:com.citic.zxyjs.zwlscx.mapreduce.join.api.DataJoinReducerBase.java
@SuppressWarnings("unchecked") protected void reduce(Text key, Iterable<TaggedMapOutput> values, Context context) throws IOException, InterruptedException { SortedMap<Text, ResetableIterator<TaggedMapOutput>> groups = regroup(key, values.iterator(), context); Text[] tags = groups.keySet().toArray(new Text[0]); ResetableIterator<TaggedMapOutput>[] groupValues = new ResetableIterator[tags.length]; for (int i = 0; i < tags.length; i++) { groupValues[i] = groups.get(tags[i]); }/*from w ww. j a va 2 s . c o m*/ joinAndCollect(tags, groupValues, key, context); for (int i = 0; i < tags.length; i++) { groupValues[i].close(); } }
From source file:org.libreplan.web.common.components.finders.ResourceMultipleFiltersFinderByResourceAndCriterion.java
private List<FilterPair> fillWithFirstTenFiltersCriterions() { SortedMap<CriterionType, List<Criterion>> mapCriterions = getMapCriterions(); Iterator<CriterionType> iteratorCriterionType = mapCriterions.keySet().iterator(); while (iteratorCriterionType.hasNext() && getListMatching().size() < 10) { CriterionType type = iteratorCriterionType.next(); for (int i = 0; getListMatching().size() < 10 && i < mapCriterions.get(type).size(); i++) { Criterion criterion = mapCriterions.get(type).get(i); addCriterion(type, criterion); }/*from w ww. java 2s . c o m*/ } return getListMatching(); }
From source file:co.rsk.remasc.RemascStorageProviderTest.java
@Test public void setAndGetSiblings() { String accountAddress = randomAddress(); Repository repository = new RepositoryImpl(); RemascStorageProvider provider = new RemascStorageProvider(repository, accountAddress); Block genesis = BlockGenerator.getGenesisBlock(); Block block = BlockGenerator.createChildBlock(genesis); Sibling sibling1 = new Sibling(genesis.getHeader(), genesis.getCoinbase(), 1); Sibling sibling2 = new Sibling(block.getHeader(), block.getCoinbase(), 2); List<Sibling> siblings = new ArrayList<>(); siblings.add(sibling1);/*from ww w.j a va2 s . co m*/ siblings.add(sibling2); provider.getSiblings().put(Long.valueOf(1), siblings); SortedMap<Long, List<Sibling>> map = provider.getSiblings(); Assert.assertNotNull(map); Assert.assertFalse(map.isEmpty()); Assert.assertTrue(map.containsKey(Long.valueOf(1))); Assert.assertEquals(2, map.get(Long.valueOf(1)).size()); }
From source file:com.lingeringsocket.mobflare.RpcCoordinator.java
List<String> listFlares(Location location) throws Exception { String uri = serverUri + "/list?latitude=" + location.getLatitude() + "&longitude=" + location.getLongitude() + "&radius=" + Prefs.getSearchRadius(context); HttpGet httpGet = new HttpGet(uri); try {/*w w w . ja v a2 s .c om*/ HttpResponse httpResponse = execute(httpGet); String json = readInputStream(httpResponse.getEntity().getContent()); JSONTokener tokener = new JSONTokener(json); JSONArray jsonArray = new JSONArray(tokener); // sort flares by distance; fake a multimap just to deal // with the pathological case of equal distances, // which actually comes up during testing on // an emulator SortedMap<Double, List<String>> sortedMap = new TreeMap<Double, List<String>>(); for (int i = 0; i < jsonArray.length(); ++i) { JSONObject jsonObj = jsonArray.getJSONObject(i); String name = jsonObj.getString("name"); double distance = jsonObj.getDouble("km"); List<String> list = sortedMap.get(distance); if (list == null) { list = new ArrayList<String>(); sortedMap.put(distance, list); } list.add(name); } List<String> flareList = new ArrayList<String>(); for (List<String> list : sortedMap.values()) { flareList.addAll(list); } return flareList; } catch (Exception ex) { Log.e(LOGTAG, "HTTP GET failed", ex); throw ex; } }
From source file:co.rsk.remasc.RemascStorageProviderTest.java
@Test public void setSaveRetrieveAndGetSiblings() throws IOException { String accountAddress = randomAddress(); Repository repository = new RepositoryImplForTesting(); RemascStorageProvider provider = new RemascStorageProvider(repository, accountAddress); Block genesis = BlockGenerator.getGenesisBlock(); Block block = BlockGenerator.createChildBlock(genesis); Sibling sibling1 = new Sibling(genesis.getHeader(), genesis.getCoinbase(), 1); Sibling sibling2 = new Sibling(block.getHeader(), block.getCoinbase(), 2); List<Sibling> siblings = new ArrayList<>(); siblings.add(sibling1);//from ww w . j a v a 2 s .com siblings.add(sibling2); provider.getSiblings().put(Long.valueOf(1), siblings); provider.save(); RemascStorageProvider newProvider = new RemascStorageProvider(repository, accountAddress); SortedMap<Long, List<Sibling>> map = newProvider.getSiblings(); Assert.assertNotNull(map); Assert.assertFalse(map.isEmpty()); Assert.assertTrue(map.containsKey(Long.valueOf(1))); Assert.assertEquals(2, map.get(Long.valueOf(1)).size()); }
From source file:org.fcrepo.kernel.impl.rdf.impl.RootRdfContext.java
private void concatRepositoryTriples() throws RepositoryException { LOGGER.trace("Creating RDF triples for repository description"); final Repository repository = resource().getNode().getSession().getRepository(); final ImmutableSet.Builder<Triple> b = builder(); for (final String key : repository.getDescriptorKeys()) { final String descriptor = repository.getDescriptor(key); if (descriptor != null) { // Create a URI from the jcr.Repository constant values, // converting them from dot notation (identifier.stability) // to the camel case that is more common in RDF properties. final StringBuilder uri = new StringBuilder(REPOSITORY_NAMESPACE); uri.append("repository"); for (final String segment : key.split("\\.")) { uri.append(StringUtils.capitalize(segment)); }//from ww w .jav a2 s . c o m b.add(create(subject(), createURI(uri.toString()), createLiteral(descriptor))); } } final NodeTypeManager nodeTypeManager = resource().getNode().getSession().getWorkspace() .getNodeTypeManager(); final NodeTypeIterator nodeTypes = nodeTypeManager.getAllNodeTypes(); while (nodeTypes.hasNext()) { final NodeType nodeType = nodeTypes.nextNodeType(); b.add(create(subject(), HAS_NODE_TYPE.asNode(), createLiteral(nodeType.getName()))); } /* FIXME: removing due to performance problems, esp. w/ many files on federated filesystem see: https://www.pivotaltracker.com/story/show/78647248 b.add(create(subject(), HAS_OBJECT_COUNT.asNode(), createLiteral(String .valueOf(getRepositoryCount(repository))))); b.add(create(subject(), HAS_OBJECT_SIZE.asNode(), createLiteral(String .valueOf(getRepositorySize(repository))))); */ // Get the cluster configuration, if available // this ugly test checks to see whether this is an ordinary JCR // repository or a ModeShape repo, which will possess the extra info if (JcrRepository.class.isAssignableFrom(repository.getClass())) { final Map<String, String> config = new GetClusterConfiguration().apply(repository); assert (config != null); for (final Map.Entry<String, String> entry : config.entrySet()) { b.add(create(subject(), createURI(REPOSITORY_NAMESPACE + entry.getKey()), createLiteral(entry.getValue()))); } } // retrieve the metrics from the service final SortedMap<String, Counter> counters = registryService.getMetrics().getCounters(); // and add the repository metrics to the RDF model if (counters.containsKey("LowLevelStorageService.fixity-check-counter")) { b.add(create(subject(), HAS_FIXITY_CHECK_COUNT.asNode(), createTypedLiteral(counters .get("org.fcrepo.services." + "LowLevelStorageService." + "fixity-check-counter") .getCount()).asNode())); } if (counters.containsKey("LowLevelStorageService.fixity-error-counter")) { b.add(create(subject(), HAS_FIXITY_ERROR_COUNT.asNode(), createTypedLiteral(counters .get("org.fcrepo.services." + "LowLevelStorageService." + "fixity-error-counter") .getCount()).asNode())); } if (counters.containsKey("LowLevelStorageService.fixity-repaired-counter")) { b.add(create(subject(), HAS_FIXITY_REPAIRED_COUNT.asNode(), createTypedLiteral(counters .get("org.fcrepo.services." + "LowLevelStorageService." + "fixity-repaired-counter") .getCount()).asNode())); } // offer all these accumulated triples concat(b.build()); }
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 ww . j a va2s. 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; }/*from w w w .j a v a 2 s.c om*/ 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:org.kalypso.model.hydrology.operation.evaporation.AbstractEvaporationCalculator.java
private TupleModelDataSet getDataSet(final ITimeseriesCache humidity, final Calendar ptr, final String type) { final TreeMap<Date, TupleModelDataSet[]> valueMap = humidity.getValueMap(); final Date base = ptr.getTime(); final SortedMap<Date, TupleModelDataSet[]> headMap = valueMap.headMap(base); final SortedMap<Date, TupleModelDataSet[]> tailMap = valueMap.tailMap(base); if (!headMap.isEmpty() && DateUtils.isSameDay(headMap.lastKey(), base)) return getDataSet(headMap.get(headMap.lastKey()), type); else if (!tailMap.isEmpty() && DateUtils.isSameDay(tailMap.firstKey(), base)) return getDataSet(tailMap.get(tailMap.firstKey()), type); return null;//from w w w .j a v a 2 s. c om }
From source file:org.libreplan.web.common.components.finders.OrderElementsMultipleFiltersFinder.java
private List<FilterPair> fillWithFirstTenFiltersCriterions() { SortedMap<CriterionType, List<Criterion>> mapCriterions = getMapCriterions(); Iterator<CriterionType> iteratorCriterionType = mapCriterions.keySet().iterator(); while (iteratorCriterionType.hasNext() && getListMatching().size() < 10) { CriterionType type = iteratorCriterionType.next(); for (int i = 0; getListMatching().size() < 10 && i < mapCriterions.get(type).size(); i++) { Criterion criterion = mapCriterions.get(type).get(i); addCriterion(type, criterion); }/* www.jav a 2s. c o m*/ } return getListMatching(); }