Example usage for java.util SortedMap entrySet

List of usage examples for java.util SortedMap entrySet

Introduction

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

Prototype

Set<Map.Entry<K, V>> entrySet();

Source Link

Document

Returns a Set view of the mappings contained in this map.

Usage

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

private void handle(UnpublishLocation message) {
    State state = getState(State.class);
    // generate lastSeen for new publish event
    long lastSeen = System.currentTimeMillis();
    SortedMap<Long, PublishLocation> publishedLocations = state.prunePublishedLocations(lastSeen);
    Iterator<Map.Entry<Long, PublishLocation>> entryIterator = publishedLocations.entrySet().iterator();
    while (entryIterator.hasNext()) {
        Map.Entry<Long, PublishLocation> entry = entryIterator.next();
        if (entry.getValue().getLocation().equals(message.getLocation())
                && entry.getValue().getRef().equals(message.getRef())) {
            entryIterator.remove();/*from   www  .  j a va  2  s  . com*/
            for (RegisterInterest listener : state.getListeners()) {
                if (!listener.getActorRef().equals(message.getRef())) {
                    double distance = listener.getLocation().distance(message.getLocation(), LengthUnit.METRES);
                    if (distance <= listener.getRadiusInMetres()) {
                        fireLeaveEvent(listener.getActorRef(), message);
                    }
                }
            }
        }
    }
}

From source file:com.espertech.esper.epl.metric.MetricScheduleService.java

/**
 * Evaluate the schedule and populates executions, if any.
 * @param handles to populate/*from w  w  w . ja v  a 2s  . c  o m*/
 */
public synchronized final void evaluate(Collection<MetricExec> handles) {
    SortedMap<Long, List<MetricExec>> headMap = timeHandleMap.headMap(currentTime + 1);

    // First determine all triggers to shoot
    List<Long> removeKeys = new LinkedList<Long>();
    for (Map.Entry<Long, List<MetricExec>> entry : headMap.entrySet()) {
        Long key = entry.getKey();
        List<MetricExec> value = entry.getValue();
        removeKeys.add(key);
        for (MetricExec handle : value) {
            handles.add(handle);
        }
    }

    // Remove all triggered msec values
    for (Long key : removeKeys) {
        timeHandleMap.remove(key);
    }

    if (!timeHandleMap.isEmpty()) {
        nearestTime = timeHandleMap.firstKey();
    } else {
        nearestTime = null;
    }
}

From source file:net.ripe.rpki.commons.crypto.x509cert.X509ResourceCertificate.java

protected X509ResourceCertificate(X509Certificate certificate) {
    super(certificate);
    ResourceExtensionParser parser = new ResourceExtensionParser();

    inheritedResourceTypes = EnumSet.noneOf(IpResourceType.class);
    resources = new IpResourceSet();

    byte[] ipAddressBlocksExtension = getCertificate()
            .getExtensionValue(ResourceExtensionEncoder.OID_IP_ADDRESS_BLOCKS.getId());
    if (ipAddressBlocksExtension != null) {
        SortedMap<AddressFamily, IpResourceSet> ipResources = parser
                .parseIpAddressBlocks(ipAddressBlocksExtension);
        for (Entry<AddressFamily, IpResourceSet> resourcesByType : ipResources.entrySet()) {
            if (resourcesByType.getValue() == null) {
                inheritedResourceTypes.add(resourcesByType.getKey().toIpResourceType());
            } else {
                resources.addAll(resourcesByType.getValue());
            }//w w w.  j  ava  2  s .co  m
        }
    }

    byte[] asnExtension = getCertificate()
            .getExtensionValue(ResourceExtensionEncoder.OID_AUTONOMOUS_SYS_IDS.getId());
    if (asnExtension != null) {
        IpResourceSet asResources = parser.parseAsIdentifiers(asnExtension);
        if (asResources == null) {
            inheritedResourceTypes.add(IpResourceType.ASN);
        } else {
            resources.addAll(asResources);
        }
    }
    Validate.isTrue(!inheritedResourceTypes.isEmpty() || !resources.isEmpty(), "empty resource set");
}

From source file:org.apache.fop.tools.fontlist.FontListMain.java

private void writeToConsole(SortedMap fontFamilies)
        throws TransformerConfigurationException, SAXException, IOException {
    Iterator iter = fontFamilies.entrySet().iterator();
    while (iter.hasNext()) {
        Map.Entry entry = (Map.Entry) iter.next();
        String firstFamilyName = (String) entry.getKey();
        System.out.println(firstFamilyName + ":");
        List list = (List) entry.getValue();
        Iterator fonts = list.iterator();
        while (fonts.hasNext()) {
            FontSpec f = (FontSpec) fonts.next();
            System.out.println("  " + f.getKey() + " " + f.getFamilyNames());
            Iterator triplets = f.getTriplets().iterator();
            while (triplets.hasNext()) {
                FontTriplet triplet = (FontTriplet) triplets.next();
                System.out.println("    " + triplet.toString());
            }/*  w  w  w  .java2  s  . com*/
        }
    }
}

From source file:org.apache.hcatalog.hcatmix.load.HCatMapper.java

@Override
public void map(LongWritable longWritable, Text text, OutputCollector<LongWritable, IntervalResult> collector,
        final Reporter reporter) throws IOException {
    LOG.info(MessageFormat.format("Input: {0}={1}", longWritable, text));
    final List<Future<SortedMap<Long, IntervalResult>>> futures = new ArrayList<Future<SortedMap<Long, IntervalResult>>>();

    // Initialize tasks
    List<org.apache.hcatalog.hcatmix.load.tasks.Task> tasks;
    try {//  w w  w  .  ja  v  a 2  s .c  o m
        tasks = initializeTasks(jobConf);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    ThreadCreatorTimer createNewThreads = new ThreadCreatorTimer(new TimeKeeper(timeKeeper), tasks,
            threadIncrementCount, futures, reporter);

    // Create timer thread to automatically keep on increasing threads at fixed interval
    Timer newThreadCreator = new Timer(true);
    newThreadCreator.scheduleAtFixedRate(createNewThreads, 0, threadIncrementIntervalInMillis);

    // Sleep and let the tasks get expired
    long remainingTime = timeKeeper.getRemainingTimeIncludingBuffer();
    final long sleepPeriod = 2000;
    for (long i = remainingTime; i > 0; i = i - sleepPeriod) {
        try {
            Thread.sleep(sleepPeriod);
            reporter.progress();
        } catch (InterruptedException e) {
            LOG.error("Got interrupted while sleeping for timer thread to finish");
        }
    }

    newThreadCreator.cancel();
    LOG.info("Time is over, will collect the futures now. Total number of threads: " + futures.size());
    SortedMap<Long, IntervalResult> stopWatchAggregatedTimeSeries = new TreeMap<Long, IntervalResult>();

    // Merge the corresponding time interval results received from all the threads for each time interval
    for (TaskExecutor taskExecutor : createNewThreads.getTaskExecutors()) {
        try {
            SortedMap<Long, IntervalResult> threadTimeSeries = taskExecutor.getTimeSeriesResult();
            for (Map.Entry<Long, IntervalResult> entry : threadTimeSeries.entrySet()) {
                Long timeStamp = entry.getKey();
                IntervalResult intervalResult = entry.getValue();

                if (stopWatchAggregatedTimeSeries.containsKey(timeStamp)) {
                    stopWatchAggregatedTimeSeries.get(timeStamp).addIntervalResult(intervalResult);
                } else {
                    stopWatchAggregatedTimeSeries.put(timeStamp, intervalResult);
                }
                LOG.info(MessageFormat.format("{0}: Added {1} stopwatches. Current stopwatch number: {2}",
                        timeStamp, intervalResult.getStopWatchList().size(),
                        stopWatchAggregatedTimeSeries.get(timeStamp).getStopWatchList().size()));
            }
        } catch (Exception e) {
            LOG.error("Error while getting thread results", e);
        }
    }

    // Output the consolidated result for this map along with the number of threads against time
    LOG.info("Collected all the statistics for #threads: " + createNewThreads.getThreadCount());
    SortedMap<Long, Integer> threadCountTimeSeries = createNewThreads.getThreadCountTimeSeries();
    int threadCount = 0;
    for (Map.Entry<Long, IntervalResult> entry : stopWatchAggregatedTimeSeries.entrySet()) {
        long timeStamp = entry.getKey();
        IntervalResult intervalResult = entry.getValue();
        if (threadCountTimeSeries.containsKey(timeStamp)) {
            threadCount = threadCountTimeSeries.get(timeStamp);
        }
        intervalResult.setThreadCount(threadCount);
        collector.collect(new LongWritable(timeStamp), intervalResult);
    }
}

From source file:com.mitre.core.search.solrfacetsearch.provider.impl.SolrFirstVariantCategoryManager.java

/**
 * Builds a String to be used in first category name list Solr property.
 *
 * @param categoryVariantPairs/* w  ww .  jav a  2 s .  c o m*/
 *           Sorted pairs of {@link VariantValueCategoryModel} and {@link GenericVariantProductModel}.code.
 * @return String to be used in Solr property.
 */
public String buildSolrPropertyFromCategoryVariantPairs(
        final SortedMap<VariantValueCategoryModel, GenericVariantProductModel> categoryVariantPairs) {
    final StringBuilder builder = new StringBuilder();
    if (categoryVariantPairs != null) {
        for (final Entry<VariantValueCategoryModel, GenericVariantProductModel> entry : categoryVariantPairs
                .entrySet()) {
            builder.append(BEFORE_BEAN + localizeForKey(entry.getKey().getName()) + FIELD_SEPARATOR
                    + entry.getValue().getCode());
        }
    }
    return builder.toString();
}

From source file:org.apache.nifi.processors.solr.SolrUtils.java

public static Map<String, String[]> getRequestParams(ProcessContext context, FlowFile flowFile) {
    final Map<String, String[]> paramsMap = new HashMap<>();
    final SortedMap<String, String> repeatingParams = new TreeMap<>();

    for (final Map.Entry<PropertyDescriptor, String> entry : context.getProperties().entrySet()) {
        final PropertyDescriptor descriptor = entry.getKey();
        if (descriptor.isDynamic()) {
            final String paramName = descriptor.getName();
            final String paramValue = context.getProperty(descriptor).evaluateAttributeExpressions(flowFile)
                    .getValue();//from  w w w  .  ja v a  2s  .  com

            if (!paramValue.trim().isEmpty()) {
                if (paramName.matches(REPEATING_PARAM_PATTERN)) {
                    repeatingParams.put(paramName, paramValue);
                } else {
                    MultiMapSolrParams.addParam(paramName, paramValue, paramsMap);
                }
            }
        }
    }

    for (final Map.Entry<String, String> entry : repeatingParams.entrySet()) {
        final String paramName = entry.getKey();
        final String paramValue = entry.getValue();
        final int idx = paramName.lastIndexOf(".");
        MultiMapSolrParams.addParam(paramName.substring(0, idx), paramValue, paramsMap);
    }

    return paramsMap;
}

From source file:playground.benjamin.scenarios.zurich.analysis.charts.BkDeltaUtilsQuantilesChart.java

/**
 * Dependent on what to plot this method has to be adapted
 * @param populationInformation (Map from Id to Row (all desired information))
 * @return Map from income to the chosen information (e.g. scoreDiff)
 * /*from  w w w.j a v a 2  s .com*/
 */
private SortedMap<Double, Double> personalIncomeInQuantiles2Scores(
        SortedMap<Id, WinnerLoserAnalysisRow> populationInformation) {
    SortedMap<Double, Double> result = new TreeMap<Double, Double>();

    //iterating over a map and getting the desired values out of Row (personal income and score difference)
    for (Entry<Id, WinnerLoserAnalysisRow> entry : populationInformation.entrySet()) {
        WinnerLoserAnalysisRow winnerLoserAnalysisRow = entry.getValue();
        Double personalIncome = winnerLoserAnalysisRow.getPersonalIncome();
        Double scoreDiff = winnerLoserAnalysisRow.getScoreDiff();
        result.put(personalIncome, scoreDiff);
    }
    return result;
}

From source file:nl.gridline.zieook.data.controller.UserController.java

/**
 * Delete a {@code user}, the user object is removed, but also all of its given ratings and views
 * @param cp content provider//from  www.ja v  a 2s .c om
 * @param user user id
 */
public void removeUser(String cp, Long user) {
    // also delete all user views and recommended items
    // delete all user ratings

    SortedMap<String, List<String>> map = dataController.getCollectionsRecommenders(cp);
    for (Map.Entry<String, List<String>> entry : map.entrySet()) {
        userTable.deleteRatings(cp, entry.getKey(), user);
        for (String r : entry.getValue()) {
            eventLogTable.deleteViews(cp, r, user);
            eventLogTable.deleteRecommend(cp, r, user);
        }
    }
    userTable.removeUser(cp, user);
}

From source file:playground.benjamin.scenarios.zurich.analysis.charts.BkDeltaUtilsChart.java

/**
 * Dependent on what to plot this method has to be adapted
 * @param populationInformation (Map from Id to Row (all desired information))
 * @return Map from income to the chosen information (e.g. scoreDiff)
 * /* w  w  w  . jav  a 2 s . c  om*/
 */
private SortedMap<Double, Double> personalIncome2Scores(
        SortedMap<Id, WinnerLoserAnalysisRow> populationInformation) {
    SortedMap<Double, Double> result = new TreeMap<Double, Double>();

    //iterating over a map and getting the desired values out of Row (personal income and score difference)
    for (Entry<Id, WinnerLoserAnalysisRow> entry : populationInformation.entrySet()) {
        WinnerLoserAnalysisRow winnerLoserAnalysisRow = entry.getValue();
        Double personalIncome = winnerLoserAnalysisRow.getPersonalIncome();
        Double scoreDiff = winnerLoserAnalysisRow.getScoreDiff();
        result.put(personalIncome, scoreDiff);
    }
    return result;
}