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:com.espertech.esper.filter.FilterParamIndexRange.java

public final void matchEvent(EventBean eventBean, Collection<FilterHandle> matches,
        ExprEvaluatorContext exprEvaluatorContext) {
    Object objAttributeValue = this.getGetter().get(eventBean);

    if ((ExecutionPathDebugLog.isDebugEnabled) && (log.isDebugEnabled())) {
        log.debug(".match Finding range matches, attribute=" + this.getPropertyName() + "  attrValue="
                + objAttributeValue);/*from  w  ww .  ja va 2s .c o m*/
    }

    if (objAttributeValue == null) {
        return;
    }

    double attributeValue = ((Number) objAttributeValue).doubleValue();

    DoubleRange rangeStart = new DoubleRange(attributeValue - largestRangeValueDouble, attributeValue);
    DoubleRange rangeEnd = new DoubleRange(attributeValue, Double.MAX_VALUE);

    SortedMap<DoubleRange, EventEvaluator> subMap = ranges.subMap(rangeStart, rangeEnd);

    // For not including either endpoint
    // A bit awkward to duplicate the loop code, however better than checking the boolean many times over
    // This may be a bit of an early performance optimization - the optimizer after all may do this better
    if (this.getFilterOperator() == FilterOperator.RANGE_OPEN) // include neither endpoint
    {
        for (Map.Entry<DoubleRange, EventEvaluator> entry : subMap.entrySet()) {
            if ((attributeValue > entry.getKey().getMin()) && (attributeValue < entry.getKey().getMax())) {
                entry.getValue().matchEvent(eventBean, matches, exprEvaluatorContext);
            }
        }
    } else if (this.getFilterOperator() == FilterOperator.RANGE_CLOSED) // include all endpoints
    {
        for (Map.Entry<DoubleRange, EventEvaluator> entry : subMap.entrySet()) {
            if ((attributeValue >= entry.getKey().getMin()) && (attributeValue <= entry.getKey().getMax())) {
                entry.getValue().matchEvent(eventBean, matches, exprEvaluatorContext);
            }
        }
    } else if (this.getFilterOperator() == FilterOperator.RANGE_HALF_CLOSED) // include high endpoint not low endpoint
    {
        for (Map.Entry<DoubleRange, EventEvaluator> entry : subMap.entrySet()) {
            if ((attributeValue > entry.getKey().getMin()) && (attributeValue <= entry.getKey().getMax())) {
                entry.getValue().matchEvent(eventBean, matches, exprEvaluatorContext);
            }
        }
    } else if (this.getFilterOperator() == FilterOperator.RANGE_HALF_OPEN) // include low endpoint not high endpoint
    {
        for (Map.Entry<DoubleRange, EventEvaluator> entry : subMap.entrySet()) {
            if ((attributeValue >= entry.getKey().getMin()) && (attributeValue < entry.getKey().getMax())) {
                entry.getValue().matchEvent(eventBean, matches, exprEvaluatorContext);
            }
        }
    } else {
        throw new IllegalStateException("Invalid filter operator " + this.getFilterOperator());
    }
}

From source file:org.apache.accumulo.server.master.balancer.ChaoticLoadBalancer.java

@Override
public void getAssignments(SortedMap<TServerInstance, TabletServerStatus> current,
        Map<KeyExtent, TServerInstance> unassigned, Map<KeyExtent, TServerInstance> assignments) {
    long total = assignments.size() + unassigned.size();
    long avg = (long) Math.ceil(((double) total) / current.size());
    Map<TServerInstance, Long> toAssign = new HashMap<TServerInstance, Long>();
    List<TServerInstance> tServerArray = new ArrayList<TServerInstance>();
    for (Entry<TServerInstance, TabletServerStatus> e : current.entrySet()) {
        long numTablets = 0;
        for (TableInfo ti : e.getValue().getTableMap().values()) {
            numTablets += ti.tablets;/*from  ww  w .j  a v a2  s .  c  o m*/
        }
        if (numTablets < avg) {
            tServerArray.add(e.getKey());
            toAssign.put(e.getKey(), avg - numTablets);
        }
    }

    if (tServerArray.isEmpty()) {
        // No tservers to assign to
        return;
    }

    for (KeyExtent ke : unassigned.keySet()) {
        int index = r.nextInt(tServerArray.size());
        TServerInstance dest = tServerArray.get(index);
        assignments.put(ke, dest);
        long remaining = toAssign.get(dest).longValue() - 1;
        if (remaining == 0) {
            tServerArray.remove(index);
            toAssign.remove(dest);
        } else {
            toAssign.put(dest, remaining);
        }
    }
}

From source file:ocr.sapphire.image.EdgeBasedImagePreprocessor.java

private Point[][] findEdgePoints(int[] edgeData) {
    List<Deque<Point>> components = new ArrayList<Deque<Point>>();
    // find close paths
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            if (edgeData[x + y * width] == BLACK && isBridge(edgeData, x, y)) {
                edgeData[x + y * width] = WHITE;
                Deque<Point> firstPart = null, secondPart = null;
                for (int k = 0; k < DX.length; k++) {
                    int x2 = x + DX[k];
                    int y2 = y + DY[k];
                    if (x2 < 0 || x2 >= width || y2 < 0 || y2 >= height) {
                        continue;
                    }//from w  w  w.  j  a v a  2s . co m
                    if (edgeData[x2 + y2 * width] == BLACK) {
                        Deque<Point> points = findConnectedComponent(edgeData, x2, y2);
                        if (firstPart == null) {
                            firstPart = points;
                        } else {
                            secondPart = points;
                        }
                    }
                }
                firstPart.addFirst(new Point(x, y));
                if (secondPart != null) { // the path is not closed
                    join(firstPart, true, secondPart, true);
                }
                components.add(firstPart);
            }
        }
    }

    // remove contained components
    for (int i = 0; i < components.size() - 1; i++) {
        Rectangle r1 = getBounds(components.get(i));
        for (int j = i + 1; j < components.size();) {
            Rectangle r2 = getBounds(components.get(j));
            if (r1.contains(r2)) {
                components.remove(j);
            } else if (r2.contains(r1)) {
                components.set(i, components.get(j));
                components.remove(j);
            } else {
                j++;
            }
        }
    }

    // try to connect some paths
    int connectedCount;
    do {
        connectedCount = 0;
        for (int i = 0; i < components.size() - 1; i++) {
            for (int j = i + 1; j < components.size(); j++) {
                Deque<Point> a = components.get(i);
                Deque<Point> b = components.get(j);

                double d0 = d(a.getFirst(), a.getLast()) + d(b.getFirst(), b.getLast());
                double d1 = d(a.getFirst(), b.getFirst()) + d(a.getLast(), b.getLast());
                double d2 = d(a.getFirst(), b.getLast()) + d(a.getLast(), b.getFirst());
                double d3 = d(a.getFirst(), b.getFirst());
                double d4 = d(a.getFirst(), b.getLast());
                double d5 = d(a.getLast(), b.getFirst());
                double d6 = d(a.getLast(), b.getLast());

                if (d3 <= CLOSE_THRESHOLD && d3 <= d4) {
                    join(a, true, b, true);
                    components.remove(j);
                    connectedCount++;
                } else if (d4 <= CLOSE_THRESHOLD && d4 <= d3) {
                    join(a, true, b, false);
                    components.remove(j);
                    connectedCount++;
                } else if (d5 <= CLOSE_THRESHOLD && d5 <= d6) {
                    join(a, false, b, true);
                    components.remove(j);
                    connectedCount++;
                } else if (d6 <= CLOSE_THRESHOLD && d6 <= d5) {
                    join(a, false, b, false);
                    components.remove(j);
                    connectedCount++;
                } else if (d1 <= d0 && d1 <= d2) {
                    if (d3 < d6) {
                        join(a, true, b, true);
                    } else {
                        join(a, false, b, false);
                    }
                    components.remove(j);
                    connectedCount++;
                } else if (d2 <= d0 && d2 <= d1) {
                    if (d4 < d5) {
                        join(a, true, b, false);
                    } else {
                        join(a, false, b, true);
                    }
                    components.remove(j);
                    connectedCount++;
                }
            } // end of for j
        } // end of for i
    } while (connectedCount > 0);

    // choose (componentCount) biggest components
    SortedMap<Integer, Deque<Point>> componentMap = new TreeMap<Integer, Deque<Point>>();
    for (Deque<Point> c : components) {
        componentMap.put(-c.size(), c);
    }

    // remove noise
    boolean firstPoint = true;
    for (Iterator<Entry<Integer, Deque<Point>>> iterator = componentMap.entrySet().iterator(); iterator
            .hasNext();) {
        Entry<Integer, Deque<Point>> entry = iterator.next();
        Rectangle r = getBounds(entry.getValue());
        if (r.width <= 10 && r.height <= 10) {
            if (firstPoint) {
                firstPoint = false;
            } else {
                iterator.remove();
            }
        }
    }

    // convert components: normalize points, to array
    int foundComponentCount = Math.min(componentCount, componentMap.size());
    componentArr = new Point[foundComponentCount][];
    Rectangle r = getBounds(componentMap.get(componentMap.firstKey()));
    for (int c = 0; c < foundComponentCount; c++) {
        int key = componentMap.firstKey();
        componentArr[c] = new Point[componentMap.get(key).size()];
        normalize(componentMap.get(key)).toArray(componentArr[c]);
        componentMap.remove(key);

        for (int i = 0; i < componentArr[c].length; i++) {
            componentArr[c][i].x = (componentArr[c][i].x - r.x) / r.width;
            componentArr[c][i].y = (componentArr[c][i].y - r.y) / r.height;
        }
    }
    return componentArr;
}

From source file:org.eclipse.ebr.maven.AboutFilesUtil.java

private String getThirdPartyInfo(final SortedMap<Artifact, Model> dependencies, final File outputDirectory)
        throws MojoExecutionException {
    final StrBuilder thirdPartyInfoText = new StrBuilder();

    for (final Entry<Artifact, Model> entry : dependencies.entrySet()) {
        String thirdPartyInfo = readThirdPartyHtmlTemplate();
        final Artifact artifact = entry.getKey();
        final Model artifactPom = entry.getValue();
        thirdPartyInfo = StringUtils.replaceEach(thirdPartyInfo, new String[] { // @formatter:off
                "@DEPENDENCY_HEADLINE@", "@DEPENDENCY_BY@", "@DEPENDENCY_NAME@", "@DEPENDENCY_LICENSING@",
                "@DEPENDENCY_ORIGIN@" },
                new String[] { escapeHtml4(artifactPom.getName()), getDevelopedByInfo(artifact, artifactPom),
                        escapeHtml4(artifactPom.getName()),
                        getLicenseInfo(artifact, artifactPom, outputDirectory),
                        getOriginInfo(artifact, artifactPom) });
        // @formatter:on

        thirdPartyInfoText.append(thirdPartyInfo);
    }//from w ww.  j  ava  2 s .c  om

    return thirdPartyInfoText.toString();
}

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 ww  .j a v  a 2s  .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.apache.james.mailbox.maildir.mail.MaildirMessageMapper.java

private List<MailboxMessage> findMessagesInMailbox(Mailbox mailbox, FilenameFilter filter, int limit)
        throws MailboxException {
    MaildirFolder folder = maildirStore.createMaildirFolder(mailbox);
    try {//from w w w . jav  a  2s .c  om
        SortedMap<Long, MaildirMessageName> uidMap = folder.getUidMap(mailboxSession, filter, limit);

        ArrayList<MailboxMessage> filtered = new ArrayList<MailboxMessage>(uidMap.size());
        for (Entry<Long, MaildirMessageName> entry : uidMap.entrySet())
            filtered.add(new MaildirMailboxMessage(mailbox, entry.getKey(), entry.getValue()));
        return filtered;
    } catch (IOException e) {
        throw new MailboxException("Failure while search for Messages in Mailbox " + mailbox, e);
    }

}

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  .  ja  v  a 2  s .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:edu.utah.further.i2b2.hook.further.service.FurtherServicesImpl.java

/**
 * Adapt a query context to an i2b2 TO graph.
 * //  w  w  w.  java2  s .c o m
 * @param queryContext
 *            FQC
 * @return i2b2 TO graph ready to be marshaled and inserted into an I2b2
 *         query response message
 */
@SuppressWarnings("boxing")
public I2b2FurtherQueryResultTo toI2b2FurtherQueryResultTo(final QueryContextTo queryContext) {
    boolean isMasked = false;
    long maskedRecords = 0;
    if (log.isDebugEnabled()) {
        log.debug("Converting query ID " + queryContext.getId() + " to an i2b2 TO");
    }
    final I2b2FurtherQueryResultTo queryResult = new I2b2FurtherQueryResultTo();

    // Copy DQC list to data source result list
    final List<I2b2FurtherDataSourceResult> dataSourceResults = queryResult.getDataSources();
    final int numDataSources = queryContext.getNumChildren();
    if (log.isDebugEnabled()) {
        log.debug("# data sources = " + numDataSources);
    }
    for (final QueryContext childQc : queryContext.getChildren()) {
        if (childQc.getNumRecords() > 0 && childQc.getNumRecords() <= resultMaskBoundary) {
            isMasked = true;
            maskedRecords += childQc.getNumRecords();

        }
        dataSourceResults.add(new I2b2FurtherDataSourceResult(childQc.getDataSourceId(),
                (childQc.getNumRecords() > 0 && childQc.getNumRecords() <= resultMaskBoundary
                        ? I2b2FurtherQueryResultTo.COUNT_SCRUBBED
                        : childQc.getNumRecords())));
        if (log.isDebugEnabled()) {
            log.debug("Added data source result " + childQc);
        }
    }

    // Copy result context list to join result list. Not needed if there's
    // only one
    // data source.
    if (numDataSources > 1) {
        final List<I2b2FurtherJoinResult> joinResults = queryResult.getJoins();
        final SortedMap<ResultType, ResultContext> resultViews = CollectionUtil.newSortedMap();
        resultViews.putAll(queryContext.getResultViews());
        for (final Map.Entry<ResultType, ResultContext> entry : resultViews.entrySet()) {
            final ResultContext resultContext = entry.getValue();
            joinResults.add(new I2b2FurtherJoinResult(WordUtils.capitalize(entry.getKey().name().toLowerCase()),
                    isMasked ? (entry.getKey().equals(ResultType.SUM)
                            ? resultContext.getNumRecords() - maskedRecords
                            : I2b2FurtherQueryResultTo.COUNT_SCRUBBED) : resultContext.getNumRecords()));
            if (log.isDebugEnabled()) {
                log.debug("Added join result " + resultContext);
            }
        }
    }

    if (log.isDebugEnabled()) {
        log.debug("I2b2 TO = " + queryResult);
    }
    return queryResult;
}

From source file:com.linkedin.pinot.core.segment.store.SingleFileIndexDirectory.java

private void mapBufferEntries() throws IOException {
    SortedMap<Long, IndexEntry> indexStartMap = new TreeMap<>();

    for (Map.Entry<IndexKey, IndexEntry> columnEntry : columnEntries.entrySet()) {
        long startOffset = columnEntry.getValue().startOffset;
        indexStartMap.put(startOffset, columnEntry.getValue());
    }//from  www.j  a  va 2s  .  co  m

    long runningSize = 0;
    List<Long> offsetAccum = new ArrayList<>();
    for (Map.Entry<Long, IndexEntry> offsetEntry : indexStartMap.entrySet()) {
        IndexEntry entry = offsetEntry.getValue();
        runningSize += entry.size;

        if (runningSize >= MAX_ALLOCATION_SIZE) {
            mapAndSliceFile(indexStartMap, offsetAccum, offsetEntry.getKey());
            runningSize = entry.size;
            offsetAccum.clear();
        }
        offsetAccum.add(offsetEntry.getKey());
    }

    if (offsetAccum.size() > 0) {
        mapAndSliceFile(indexStartMap, offsetAccum, offsetAccum.get(0) + runningSize);
    }
}

From source file:com.aurel.track.item.history.HistoryLoaderBL.java

/**
 * Gets the list of comments as history values for each item
 * @param workItemIDs/*from   w w w  .  j  a  v  a2  s .co  m*/
 * @param personID
 * @param locale
 * @return
 */
public static Map<Integer, List<HistoryValues>> getComments(int[] workItemIDs, Integer personID,
        Locale locale) {
    Map<Integer, List<HistoryValues>> commentMap = new HashMap<Integer, List<HistoryValues>>();
    Map<Integer, SortedMap<Integer, Map<Integer, HistoryValues>>> historyMap = getWorkItemsHistory(workItemIDs,
            new Integer[] { SystemFields.INTEGER_COMMENT }, true, null, null, null, locale, false,
            LONG_TEXT_TYPE.ISFULLHTML, true, personID);
    if (historyMap != null) {
        for (Map.Entry<Integer, SortedMap<Integer, Map<Integer, HistoryValues>>> itemEntry : historyMap
                .entrySet()) {
            Integer itemID = itemEntry.getKey();
            SortedMap<Integer, Map<Integer, HistoryValues>> commentTransaction = itemEntry.getValue();
            if (commentTransaction != null) {
                for (Map.Entry<Integer, Map<Integer, HistoryValues>> transactionEntry : commentTransaction
                        .entrySet()) {
                    Map<Integer, HistoryValues> commentFieldEntry = transactionEntry.getValue();
                    if (commentFieldEntry != null) {
                        for (Map.Entry<Integer, HistoryValues> commentEntry : commentFieldEntry.entrySet()) {
                            HistoryValues historyValues = commentEntry.getValue();
                            if (historyValues != null) {
                                List<HistoryValues> commentsForItem = commentMap.get(itemID);
                                if (commentsForItem == null) {
                                    commentsForItem = new LinkedList<HistoryValues>();
                                    commentMap.put(itemID, commentsForItem);
                                }
                                commentsForItem.add(historyValues);
                            }
                        }
                    }
                }
            }
        }
    }
    return commentMap;
}