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.trnltk.apps.experiments.AmbiguityMatrixApp.java

private int[][] getMatrixData(ImmutableMultiset<String> wordCountSet,
        List<String> distinctWordsWithEnoughOccurrences, Map<String, List<String>> resultMap,
        SortedMap<String, Integer> sortedTotalAmbiguityMap) {
    int data[][] = new int[distinctWordsWithEnoughOccurrences.size()][Feature.values().length + 1]; // +1 for Y = totalAmbiguity
    int i = 0;/*from w  w w. j av  a  2s  .  co m*/
    for (Map.Entry<String, Integer> ambiguityEntry : sortedTotalAmbiguityMap.entrySet()) {
        final int[] dataRow = data[i];
        dataRow[Feature.values().length] = ambiguityEntry.getValue(); // last column is the Y
        for (int j = 0; j < Feature.values().length; j++) {
            Feature feature = Feature.values()[j];
            final String surface = ambiguityEntry.getKey();
            dataRow[j] = feature.compute(surface, resultMap.get(surface), wordCountSet);
        }
        i++;
    }
    return data;
}

From source file:com.espertech.esper.filter.FilterParamIndexStringRange.java

public final void matchEvent(EventBean theEvent, Collection<FilterHandle> matches) {
    Object objAttributeValue = lookupable.getGetter().get(theEvent);

    if (objAttributeValue == null) {
        return;//w w  w.  j a va2 s . c om
    }

    String attributeValue = (String) objAttributeValue;

    StringRange rangeStart = new StringRange(null, attributeValue);
    StringRange rangeEnd = new StringRange(attributeValue, null);
    SortedMap<StringRange, EventEvaluator> subMap = ranges.subMap(rangeStart, true, rangeEnd, true);

    // 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<StringRange, EventEvaluator> entry : subMap.entrySet()) {
            if (entry.getKey().getMin().compareTo(attributeValue) < 0
                    && entry.getKey().getMax().compareTo(attributeValue) > 0) {
                entry.getValue().matchEvent(theEvent, matches);
            }
        }
    } else if (this.getFilterOperator() == FilterOperator.RANGE_CLOSED) // include all endpoints
    {
        for (Map.Entry<StringRange, EventEvaluator> entry : subMap.entrySet()) {
            if (entry.getKey().getMin().compareTo(attributeValue) <= 0
                    && entry.getKey().getMax().compareTo(attributeValue) >= 0) {
                entry.getValue().matchEvent(theEvent, matches);
            }
        }
    } else if (this.getFilterOperator() == FilterOperator.RANGE_HALF_CLOSED) // include high endpoint not low endpoint
    {
        for (Map.Entry<StringRange, EventEvaluator> entry : subMap.entrySet()) {
            if (entry.getKey().getMin().compareTo(attributeValue) < 0
                    && entry.getKey().getMax().compareTo(attributeValue) >= 0) {
                entry.getValue().matchEvent(theEvent, matches);
            }
        }
    } else if (this.getFilterOperator() == FilterOperator.RANGE_HALF_OPEN) // include low endpoint not high endpoint
    {
        for (Map.Entry<StringRange, EventEvaluator> entry : subMap.entrySet()) {
            if (entry.getKey().getMin().compareTo(attributeValue) <= 0
                    && entry.getKey().getMax().compareTo(attributeValue) > 0) {
                entry.getValue().matchEvent(theEvent, matches);
            }
        }
    } else {
        throw new IllegalStateException("Invalid filter operator " + this.getFilterOperator());
    }
}

From source file:org.aika.network.neuron.lattice.AndNode.java

public AndNode(int level, SortedMap<InputNode, Node> parents) {
    super(level);
    this.parents = parents;
    for (Map.Entry<InputNode, Node> me : parents.entrySet()) {
        me.getValue().andChildren.put(me.getKey(), this);
        me.getValue().andChildrenWithinDocument.put(me.getKey(), this);
    }/*  w w w  .  j  a v  a 2 s .c  o m*/
}

From source file:test.RowsWithoutColumnIteratorTest.java

@Test
public void simpleMacTest3() throws Exception {
    ZooKeeperInstance instance = new ZooKeeperInstance(mac.getInstanceName(), mac.getZooKeepers());
    Connector conn = instance.getConnector("root", new PasswordToken(password));

    final String table = "simpleMacTest3";
    TableOperations tops = conn.tableOperations();
    if (tops.exists(table)) {
        tops.delete(table);/* w w w .ja  v a2  s  .  co  m*/
    }

    tops.create(table);

    BatchWriter bw = conn.createBatchWriter(table, new BatchWriterConfig());

    Mutation m = new Mutation("1");
    m.put("A", "", "");
    bw.addMutation(m);

    m = new Mutation("2");
    m.put("A", "", "");
    m.put("B", "", "");
    bw.addMutation(m);

    m = new Mutation("2.5");
    m.put("A", "", "");
    m.put("C", "", "");
    m.put("E", "", "");
    bw.addMutation(m);

    m = new Mutation("3");
    m.put("A", "", "");
    m.put("B", "", "");
    m.put("C", "", "");
    m.put("D", "", "");
    bw.addMutation(m);

    m = new Mutation("3.5");
    m.put("A", "", "");
    m.put("C", "", "");
    m.put("D", "", "");
    bw.addMutation(m);

    m = new Mutation("4");
    m.put("C", "", "");
    bw.addMutation(m);

    bw.close();

    Scanner s = conn.createScanner(table, new Authorizations());
    Map<String, String> options = ImmutableMap.of(RowsWithoutColumnIterator.COLUMNS_TO_IGNORE, "B,D");
    IteratorSetting cfg = new IteratorSetting(50, RowsWithoutColumnIterator.class, options);
    s.addScanIterator(cfg);
    s.setRange(new Range());

    Iterator<Entry<Key, Value>> iter = s.iterator();

    // Row 1
    Assert.assertTrue(iter.hasNext());
    Entry<Key, Value> next = iter.next();

    Assert.assertEquals("1", next.getKey().getRow().toString());
    SortedMap<Key, Value> values = WholeRowIterator.decodeRow(next.getKey(), next.getValue());
    Assert.assertEquals(1, values.size());
    Iterator<Entry<Key, Value>> rowValues = values.entrySet().iterator();

    Entry<Key, Value> row = rowValues.next();
    Assert.assertEquals(0, new Key("1", "A", "").compareTo(row.getKey(), PartialKey.ROW_COLFAM_COLQUAL_COLVIS));
    Assert.assertEquals(new Value(new byte[0]), row.getValue());

    // Row 2.5
    Assert.assertTrue(iter.hasNext());
    next = iter.next();

    Assert.assertEquals("2.5", next.getKey().getRow().toString());
    values = WholeRowIterator.decodeRow(next.getKey(), next.getValue());
    Assert.assertEquals(3, values.size());
    rowValues = values.entrySet().iterator();

    row = rowValues.next();
    Assert.assertEquals(0,
            new Key("2.5", "A", "").compareTo(row.getKey(), PartialKey.ROW_COLFAM_COLQUAL_COLVIS));
    Assert.assertEquals(new Value(new byte[0]), row.getValue());
    row = rowValues.next();

    Assert.assertEquals(0,
            new Key("2.5", "C", "").compareTo(row.getKey(), PartialKey.ROW_COLFAM_COLQUAL_COLVIS));
    Assert.assertEquals(new Value(new byte[0]), row.getValue());
    row = rowValues.next();

    Assert.assertEquals(0,
            new Key("2.5", "E", "").compareTo(row.getKey(), PartialKey.ROW_COLFAM_COLQUAL_COLVIS));
    Assert.assertEquals(new Value(new byte[0]), row.getValue());

    // Row 4
    Assert.assertTrue(iter.hasNext());
    next = iter.next();

    Assert.assertEquals("4", next.getKey().getRow().toString());
    values = WholeRowIterator.decodeRow(next.getKey(), next.getValue());
    Assert.assertEquals(1, values.size());
    rowValues = values.entrySet().iterator();

    row = rowValues.next();
    Assert.assertEquals(0, new Key("4", "C", "").compareTo(row.getKey(), PartialKey.ROW_COLFAM_COLQUAL_COLVIS));
    Assert.assertEquals(new Value(new byte[0]), row.getValue());

    Assert.assertFalse(iter.hasNext());
}

From source file:com.tripit.auth.OAuthCredential.java

public String getSessionParameters(String redirectUrl, String action)
        throws UnsupportedEncodingException, InvalidKeyException, NoSuchAlgorithmException {
    SortedMap<String, String> params = new TreeMap<String, String>();
    params.put("redirect_url", redirectUrl);
    params = generateOAuthParameters(action, params);
    params.put("redirect_url", redirectUrl);
    params.put("action", action);

    StringBuilder sb = new StringBuilder();
    sb.append('{');
    boolean isFirst = true;
    for (Map.Entry<String, String> param : params.entrySet()) {
        if (isFirst) {
            isFirst = false;//from   w w  w .j ava  2 s.  co  m
        } else {
            sb.append(",");
        }

        jsonEncodeString(param.getKey(), sb);
        sb.append(": ");
        jsonEncodeString(param.getValue(), sb);
    }
    sb.append('}');

    return sb.toString();
}

From source file:com.erinors.hpb.server.handler.SortedMapHandler.java

@Override
public Object clone(CloningContext context, Object object) {
    if (!(object instanceof SortedMap)) {
        return null;
    }// w w  w  .j av a 2  s . c o m

    SortedMap<Object, Object> source = (SortedMap<Object, Object>) object;
    SortedMap<Object, Object> result;

    if (source instanceof PersistentSortedMap && !((PersistentSortedMap) source).wasInitialized()) {
        result = new UninitializedPersistentSortedMap<Object, Object>(source.comparator());
        context.addProcessedObject(object, result);
    } else {
        SortedMap<Object, Object> map = new TreeMap<Object, Object>(source.comparator());
        context.addProcessedObject(object, map);

        for (Map.Entry<?, ?> entry : source.entrySet()) {
            map.put(context.clone(entry.getKey()), context.clone(entry.getValue()));
        }

        result = map;
    }

    return result;
}

From source file:core.com.qiniu.auth.AWS3Signer.java

protected String getCanonicalizedHeadersForStringToSign(Request<?> request) {
    List<String> headersToSign = getHeadersForStringToSign(request);

    for (int i = 0; i < headersToSign.size(); i++) {
        headersToSign.set(i, StringUtils.lowerCase(headersToSign.get(i)));
    }//from   ww  w  .  j  a  v a  2  s  .  c  o  m

    SortedMap<String, String> sortedHeaderMap = new TreeMap<String, String>();
    for (Map.Entry<String, String> entry : request.getHeaders().entrySet()) {
        if (headersToSign.contains(StringUtils.lowerCase(entry.getKey()))) {
            sortedHeaderMap.put(StringUtils.lowerCase(entry.getKey()), entry.getValue());
        }
    }

    StringBuilder builder = new StringBuilder();
    for (Map.Entry<String, String> entry : sortedHeaderMap.entrySet()) {
        builder.append(StringUtils.lowerCase(entry.getKey())).append(":").append(entry.getValue()).append("\n");
    }

    return builder.toString();
}

From source file:com.kolich.aws.services.s3.impl.KolichS3Signer.java

/**
  * Calculate the canonical string for a REST/HTTP request to S3.
  *///www .ja va 2  s .c o  m
private static final String getS3CanonicalString(final AwsHttpRequest request) {
    // A few standard headers we extract for conveinence.
    final String contentType = CONTENT_TYPE.toLowerCase(), contentMd5 = CONTENT_MD5.toLowerCase(),
            date = DATE.toLowerCase();
    // Start with the empty string ("").
    final StringBuilder buf = new StringBuilder();
    // Next is the HTTP verb and a newline.
    buf.append(request.getMethod() + LINE_SEPARATOR_UNIX);
    // Add all interesting headers to a list, then sort them.
    // "Interesting" is defined as Content-MD5, Content-Type, Date,
    // and x-amz-... headers.
    final Map<String, String> headersMap = getHeadersAsMap(request);
    final SortedMap<String, String> interesting = Maps.newTreeMap();
    if (!headersMap.isEmpty()) {
        Iterator<Map.Entry<String, String>> it = headersMap.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<String, String> entry = it.next();
            final String key = entry.getKey(), value = entry.getValue();
            if (key == null) {
                continue;
            }
            final String lk = key.toLowerCase(Locale.getDefault());
            // Ignore any headers that are not interesting.
            if (lk.equals(contentType) || lk.equals(contentMd5) || lk.equals(date)
                    || lk.startsWith(AMAZON_PREFIX)) {
                interesting.put(lk, value);
            }
        }
    }
    // Remove default date timestamp if "x-amz-date" is set.
    if (interesting.containsKey(S3_ALTERNATE_DATE)) {
        interesting.put(date, "");
    }
    // These headers require that we still put a new line in after them,
    // even if they don't exist.
    if (!interesting.containsKey(contentType)) {
        interesting.put(contentType, "");
    }
    if (!interesting.containsKey(contentMd5)) {
        interesting.put(contentMd5, "");
    }
    // Add all the interesting headers
    for (Iterator<Map.Entry<String, String>> i = interesting.entrySet().iterator(); i.hasNext();) {
        final Map.Entry<String, String> entry = i.next();
        final String key = entry.getKey();
        final Object value = entry.getValue();
        if (key.startsWith(AMAZON_PREFIX)) {
            buf.append(key).append(':').append(value);
        } else {
            buf.append(value);
        }
        buf.append(LINE_SEPARATOR_UNIX);
    }
    // The CanonicalizedResource this request is working with.
    // If the request specifies a bucket using the HTTP Host header
    // (virtual hosted-style), append the bucket name preceded by a
    // "/" (e.g., "/bucketname"). For path-style requests and requests
    // that don't address a bucket, do nothing.
    if (request.getResource() != null) {
        buf.append("/" + request.getResource() + request.getURI().getRawPath());
    } else {
        buf.append(request.getURI().getRawPath());
    }
    // Amazon requires us to sort the query string parameters.
    final List<SortableBasicNameValuePair> params = sortParams(URLEncodedUtils.parse(request.getURI(), UTF_8));
    String separator = "?";
    for (final NameValuePair pair : params) {
        final String name = pair.getName(), value = pair.getValue();
        // Skip any parameters that aren't part of the
        // canonical signed string.
        if (!INTERESTING_PARAMETERS.contains(name)) {
            continue;
        }
        buf.append(separator).append(name);
        if (value != null) {
            buf.append("=").append(value);
        }
        separator = "&";
    }
    return buf.toString();
}

From source file:at.christophwurst.orm.service.BurnDownServiceImpl.java

@Override
public Map<Date, Float> getBurnDownData(Long sprintId) {
    Map<Date, Float> result = new HashMap<>();
    Sprint sprint = sprintRepository.getSprintAndWorklogs(sprintId);

    int totalTime = sprint.getRequirements().stream().mapToInt((s) -> {
        return s.getTasks().stream().mapToInt(Task::getEstimatedTime).sum();
    }).sum();//from  www . j  av  a  2s .  c  o m

    SortedMap<Date, List<LogbookEntry>> workLogs = new TreeMap<>();
    sprint.getRequirements().forEach((r) -> {
        r.getTasks().forEach((t) -> {
            t.getLogbookEntries().forEach((e) -> {
                Date day = stripDate(e.getStartTime());
                if (!workLogs.containsKey(day)) {
                    workLogs.put(day, new ArrayList<>());
                }
                workLogs.get(day).add(e);
            });
        });
    });

    int left = totalTime;
    for (Map.Entry<Date, List<LogbookEntry>> entry : workLogs.entrySet()) {
        long Ldone = entry.getValue().stream().mapToLong(LogbookEntry::getTotalTime).sum();
        int done = (int) (Ldone / (1000 * 3600));
        left -= done;
        result.put(entry.getKey(), (float) left / totalTime);
    }
    return result;
}

From source file:com.haulmont.cuba.web.sys.WebJarResourceResolver.java

protected String getFullPath(SortedMap<String, String> pathIndex, String partialPath) {
    if (partialPath.charAt(0) == '/') {
        partialPath = partialPath.substring(1);
    }//from   w  w  w.j a  va2s .  c  o m

    String reversePartialPath = reversePath(partialPath);

    SortedMap<String, String> fullPathTail = pathIndex.tailMap(reversePartialPath);

    if (fullPathTail.size() == 0) {
        if (log.isTraceEnabled()) {
            printNotFoundTraceInfo(pathIndex, partialPath);
        }
        throwNotFoundException(partialPath);
    }

    Iterator<Map.Entry<String, String>> fullPathTailIterator = fullPathTail.entrySet().iterator();
    Map.Entry<String, String> fullPathEntry = fullPathTailIterator.next();
    if (!fullPathEntry.getKey().startsWith(reversePartialPath)) {
        if (log.isTraceEnabled()) {
            printNotFoundTraceInfo(pathIndex, partialPath);
        }
        throwNotFoundException(partialPath);
    }
    String fullPath = fullPathEntry.getValue();

    if (fullPathTailIterator.hasNext()) {
        List<String> matches = null;

        while (fullPathTailIterator.hasNext()) {
            Map.Entry<String, String> next = fullPathTailIterator.next();
            if (next.getKey().startsWith(reversePartialPath)) {
                if (matches == null) {
                    matches = new ArrayList<>();
                }
                matches.add(next.getValue());
            } else {
                break;
            }
        }

        if (matches != null) {
            matches.add(fullPath);
            throw new MultipleMatchesException("Multiple matches found for " + partialPath
                    + ". Please provide a more specific path, for example by including a version number.",
                    matches);
        }
    }

    return fullPath;
}