Example usage for java.util SortedMap values

List of usage examples for java.util SortedMap values

Introduction

In this page you can find the example usage for java.util SortedMap values.

Prototype

Collection<V> values();

Source Link

Document

Returns a Collection view of the values contained in this map.

Usage

From source file:fr.gael.dhus.util.functional.collect.SortedMapTest.java

/** Constructor: Empty map param. */
@Test//from w w w  .jav a2s  .  co  m
public void emptyMapTest() {
    SortedMap sorted_map = new SortedMap(Collections.emptyMap(), cmp);
    Assert.assertTrue(sorted_map.isEmpty());
    Assert.assertEquals(sorted_map.size(), 0);
    Assert.assertFalse(sorted_map.keySet().iterator().hasNext());
    Assert.assertFalse(sorted_map.values().iterator().hasNext());
    Assert.assertFalse(sorted_map.entrySet().iterator().hasNext());
}

From source file:org.archive.modules.fetcher.BdbCookieStore.java

protected Collection<Cookie> hostSubset(String host) {
    try {/* w  w  w . ja va  2 s .c o  m*/
        byte[] startKey = (host + ";").getBytes("UTF-8");

        char chAfterDelim = (char) (((int) ';') + 1);
        byte[] endKey = (host + chAfterDelim).getBytes("UTF-8");

        SortedMap<byte[], Cookie> submap = cookies.subMap(startKey, endKey);
        return submap.values();

    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e); // impossible
    }
}

From source file:org.elasticsoftware.elasticactors.geoevents.actors.Region.java

private void handle(ScanRequest message, ActorRef receiver) {
    State state = getState(State.class);
    long lastSeen = System.currentTimeMillis();
    SortedMap<Long, PublishLocation> publishedLocations = state.prunePublishedLocations(lastSeen);
    List<ScanResponse.ScanResult> scanResults = new LinkedList<ScanResponse.ScanResult>();
    for (PublishLocation publishedLocation : publishedLocations.values()) {
        double distance = publishedLocation.getLocation().distance(message.getLocation(), LengthUnit.METRES);
        if (distance <= message.getRadiusInMetres()) {
            scanResults.add(new ScanResponse.ScanResult(publishedLocation, (int) distance));
        }//  www.  j ava 2  s. co  m
    }
    receiver.tell(new ScanResponse(message.getId(), scanResults), getSelf());
}

From source file:com.jts.rest.profileservice.utils.RestServiceHelper.java

/**
 * Uses MemberChallenge service to get all the associated challenge information for a user
 * Sorts the challenge information with end date
 * Returns all the active challenges and 3 most recent past challenge 
 * @param sessionId//w w w.  j  a va  2s  .  com
 * @param username
 * @return
 * @throws MalformedURLException
 * @throws IOException
 */
@SuppressWarnings("unchecked")
public static JSONObject getProcessedChallengesM1(String sessionId, String username)
        throws MalformedURLException, IOException {
    //get all challenges
    JSONArray challenges = getChallenges(sessionId, username);

    JSONArray activeChallenges = new JSONArray();
    JSONArray pastChallenges = new JSONArray();
    SortedMap<Long, JSONObject> pastChallengesByDate = new TreeMap<Long, JSONObject>();
    Iterator<JSONObject> iterator = challenges.iterator();

    DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-ddhh:mm:ss");

    while (iterator.hasNext()) {
        JSONObject challenge = iterator.next();
        //identify active challenge with status
        if (challenge.get("Status__c").equals(PSContants.STATUS_CREATED)) {
            activeChallenges.add(challenge);
        } else {
            String endDateStr = ((String) challenge.get("End_Date__c")).replace("T", "");
            Date date = new Date();
            try {
                date = dateFormat.parse(endDateStr);
            } catch (ParseException pe) {
                logger.log(Level.SEVERE, "Error occurent while parsing date " + endDateStr);
            }
            pastChallengesByDate.put(date.getTime(), challenge);
        }
    }

    //from the sorted map extract the recent challenge
    int pastChallengeSize = pastChallengesByDate.size();
    if (pastChallengeSize > 0) {
        Object[] challengeArr = (Object[]) pastChallengesByDate.values().toArray();
        int startIndex = pastChallengeSize > 3 ? pastChallengeSize - 3 : 0;
        for (int i = startIndex; i < pastChallengeSize; i++) {
            pastChallenges.add(challengeArr[i]);
        }
    }
    JSONObject resultChallenges = new JSONObject();
    resultChallenges.put("activeChallenges", activeChallenges);
    resultChallenges.put("pastChallenges", pastChallenges);
    resultChallenges.put("totalChallenges", challenges.size());
    return resultChallenges;
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.Step6GraphTransitivityCleaner.java

@SuppressWarnings("unchecked")
public static void printResultStatistics(File xmlFile) throws IllegalAccessException {
    Map<String, Map<String, GraphCleaningResults>> results = (Map<String, Map<String, GraphCleaningResults>>) XStreamTools
            .getXStream().fromXML(xmlFile);

    //        System.out.println(results);

    SortedMap<String, List<GraphCleaningResults>> resultsGroupedByMethod = new TreeMap<>();

    for (Map.Entry<String, Map<String, GraphCleaningResults>> entry : results.entrySet()) {
        //            System.out.println(entry.getKey());

        for (Map.Entry<String, GraphCleaningResults> e : entry.getValue().entrySet()) {
            //                System.out.println(e.getKey());
            //                System.out.println(e.getValue());

            if (!resultsGroupedByMethod.containsKey(e.getKey())) {
                resultsGroupedByMethod.put(e.getKey(), new ArrayList<GraphCleaningResults>());
            }//from   ww  w. j  a v  a2 s  .c o m

            resultsGroupedByMethod.get(e.getKey()).add(e.getValue());
        }
    }

    String header = null;

    // collect statistics
    for (Map.Entry<String, List<GraphCleaningResults>> entry : resultsGroupedByMethod.entrySet()) {
        List<GraphCleaningResults> value = entry.getValue();
        SortedMap<String, DescriptiveStatistics> stringDescriptiveStatisticsMap = collectStatisticsOverGraphCleaningResults(
                value);

        if (header == null) {
            header = StringUtils.join(stringDescriptiveStatisticsMap.keySet(), "\t");
            System.out.println("\t\t" + header);
        }

        List<Double> means = new ArrayList<>();
        List<Double> stdDevs = new ArrayList<>();
        for (DescriptiveStatistics statistics : stringDescriptiveStatisticsMap.values()) {
            means.add(statistics.getMean());
            stdDevs.add(statistics.getStandardDeviation());
        }

        List<String> meansString = new ArrayList<>();
        for (Double mean : means) {
            meansString.add(String.format(Locale.ENGLISH, "%.2f", mean));
        }

        List<String> stdDevString = new ArrayList<>();
        for (Double stdDev : stdDevs) {
            stdDevString.add(String.format(Locale.ENGLISH, "%.2f", stdDev));
        }

        System.out.println(entry.getKey() + "\tmean\t" + StringUtils.join(meansString, "\t"));
        //            System.out.println(entry.getKey() + "\tstdDev\t" + StringUtils.join(stdDevString, "\t"));
    }
}

From source file:gridool.routing.strategy.ConsistentHash.java

public List<GridNode> listSuccessorsInVirtualChain(@Nonnull final byte[] fromKey, final int maxNodesToSelect,
        final boolean exclusive) {
    if (circle.isEmpty()) {
        return Collections.emptyList();
    }/*from  ww  w  .ja v  a 2s . co  m*/
    int numToGets = Math.min(maxNodesToSelect, liveNodes.size());
    final List<GridNode> retNodes = new ArrayList<GridNode>(numToGets);
    int accquired = 0;

    final Long hash = hashFunction.hash(fromKey);

    if (exclusive && LOG.isWarnEnabled()) {
        if (!circle.containsKey(hash)) {
            LOG.warn("Routing table does not have a required node");
        }
    }

    final SortedMap<Long, GridNode> tailMap = circle.tailMap(hash);
    final boolean noTail = tailMap.isEmpty();
    if (!noTail) {
        final Iterator<GridNode> tail = tailMap.values().iterator();
        if (exclusive) {
            assert (tail.hasNext());
            tail.next(); // skip
        }
        for (; tail.hasNext() && accquired < numToGets;) {
            GridNode n = tail.next();
            if (!retNodes.contains(n)) {
                retNodes.add(n);
                accquired++;
            }
        }
    }
    if (accquired < numToGets) {
        final Iterator<GridNode> head = circle.values().iterator();
        if (exclusive && noTail) {
            assert (head.hasNext());
            head.next(); // skip
        }
        for (; head.hasNext() && accquired < numToGets;) {
            GridNode n = head.next();
            if (!retNodes.contains(n)) {
                retNodes.add(n);
                accquired++;
            }
        }
    }
    return retNodes;
}

From source file:gridool.routing.strategy.ConsistentHash.java

public List<GridNode> listSuccessorsInPhysicalChain(@Nonnull final GridNode node, final int maxNodesToSelect,
        final boolean exclusive) {
    int numToGets = Math.min(maxNodesToSelect, liveNodes.size());
    final List<GridNode> retNodes = new ArrayList<GridNode>(numToGets);
    int accquired = 0;

    final SortedMap<GridNode, GridNode> tailMap = liveNodes.tailMap(node);
    final boolean noTail = tailMap.isEmpty();
    if (!noTail) {// has tail
        final Iterator<GridNode> tail = tailMap.values().iterator();
        if (exclusive) {
            assert (tail.hasNext());
            tail.next(); // skip
        }//from w w  w .j  a  va  2  s . c  o m
        for (; tail.hasNext() && accquired < numToGets; accquired++) {
            GridNode n = tail.next();
            retNodes.add(n);
        }
    }
    if (accquired < numToGets) {
        final Iterator<GridNode> head = liveNodes.values().iterator();
        if (exclusive && noTail) {
            assert (head.hasNext());
            head.next(); // skip
        }
        for (; head.hasNext() && accquired < numToGets; accquired++) {
            GridNode n = head.next();
            retNodes.add(n);
        }
    }
    return retNodes;
}

From source file:com.basho.riak.client.raw.pbc.ConversionUtil.java

/**
 * Take a link walked m/r result and make it into a WalkResult.
 *
 * This is a little bit nasty since the JSON is parsed to a Map.
 *
 * @param secondPhaseResult//from   w  ww .  ja va 2 s  .  co m
 *            the contents of which *must* be a json array of {step: int, v:
 *            riakObjectMap}
 * @return a WalkResult of RiakObjects grouped by first-phase step
 * @throws IOException
 */
@SuppressWarnings({ "rawtypes" })
static WalkResult convert(MapReduceResult secondPhaseResult) throws IOException {
    final SortedMap<Integer, Collection<IRiakObject>> steps = new TreeMap<Integer, Collection<IRiakObject>>();

    try {
        Collection<Map> results = secondPhaseResult.getResult(Map.class);
        for (Map o : results) {
            final int step = Integer.parseInt((String) o.get("step"));
            Collection<IRiakObject> stepAccumulator = steps.get(step);

            if (stepAccumulator == null) {
                stepAccumulator = new ArrayList<IRiakObject>();
                steps.put(step, stepAccumulator);
            }

            final Map data = (Map) o.get("v");

            stepAccumulator.add(mapToRiakObject(data));
        }
    } catch (ConversionException e) {
        throw new IOException(e.getMessage());
    }
    // create a result instance
    return new WalkResult() {
        public Iterator<Collection<IRiakObject>> iterator() {
            return new UnmodifiableIterator<Collection<IRiakObject>>(steps.values().iterator());
        }
    };
}

From source file:net.sourceforge.msscodefactory.cfcore.v1_11.GenKbRam.GenKbRamISOCurrencyTable.java

public GenKbCursor openISOCurrencyCursorByCcyCdIdx(GenKbAuthorization Authorization, String ISOCode) {
    GenKbCursor cursor;/*from w ww .  java  2 s.  co  m*/
    GenKbISOCurrencyByCcyCdIdxKey key = schema.getFactoryISOCurrency().newCcyCdIdxKey();
    key.setRequiredISOCode(ISOCode);

    if (dictByCcyCdIdx.containsKey(key)) {
        SortedMap<GenKbISOCurrencyPKey, GenKbISOCurrencyBuff> subdictCcyCdIdx = dictByCcyCdIdx.get(key);
        cursor = new GenKbRamISOCurrencyCursor(Authorization, schema, subdictCcyCdIdx.values());
    } else {
        cursor = new GenKbRamISOCurrencyCursor(Authorization, schema, new ArrayList<GenKbISOCurrencyBuff>());
    }
    return (cursor);
}

From source file:com.edmunds.etm.runtime.api.ApplicationSeries.java

private void updateActiveVersion(SortedMap<ApplicationVersion, Application> versions) {

    // Find the version with the largest pool size
    Application majorityVersion = null;//from w  w  w.  j a  v  a2s.  c  o m
    Application activeVersion = null;
    int maxPoolSize = Integer.MIN_VALUE;
    for (Application app : versions.values()) {
        int poolSize = app.getPoolSize();

        // The use of '>' gives us the oldest version in the case of a tie because
        // the values from the map are sorted in ascending version number order.
        if (poolSize > maxPoolSize) {
            maxPoolSize = poolSize;
            majorityVersion = app;
        }

        if (app.isActive()) {
            activeVersion = app;
        }
    }

    if (majorityVersion == null) {
        // Majority version is null only if no versions exist
        return;
    }

    // Has the active version changed?
    if (majorityVersion.equals(activeVersion)) {
        return;
    }

    versions.put(majorityVersion.getVersion(), new Application(majorityVersion, true));

    if (activeVersion != null) {
        versions.put(activeVersion.getVersion(), new Application(activeVersion, false));
    }
}