Example usage for java.util TreeMap entrySet

List of usage examples for java.util TreeMap entrySet

Introduction

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

Prototype

EntrySet entrySet

To view the source code for java.util TreeMap entrySet.

Click Source Link

Document

Fields initialized to contain an instance of the entry set view the first time this view is requested.

Usage

From source file:com.opengamma.analytics.math.interpolation.GridInterpolator2D.java

private Map<Double, Interpolator1DDataBundle> testData(final Map<DoublesPair, Double> data) {
    final Map<Double, Interpolator1DDataBundle> result = new TreeMap<Double, Interpolator1DDataBundle>();
    final TreeMap<DoublesPair, Double> sorted = new TreeMap<DoublesPair, Double>(_comparator);
    sorted.putAll(data);/*from w  w  w. j  ava 2s  .c  o  m*/
    final Iterator<Map.Entry<DoublesPair, Double>> iterator = sorted.entrySet().iterator();
    final Map.Entry<DoublesPair, Double> firstEntry = iterator.next();
    double x = firstEntry.getKey().first;
    Map<Double, Double> yzValues = new TreeMap<Double, Double>();
    yzValues.put(firstEntry.getKey().second, firstEntry.getValue());
    while (iterator.hasNext()) {
        final Map.Entry<DoublesPair, Double> nextEntry = iterator.next();
        final double newX = nextEntry.getKey().first;
        if (Double.doubleToLongBits(newX) != Double.doubleToLongBits(x)) {
            final Interpolator1DDataBundle interpolatorData = _yInterpolator.getDataBundle(yzValues);
            result.put(x, interpolatorData);
            yzValues = new TreeMap<Double, Double>();
            yzValues.put(nextEntry.getKey().second, nextEntry.getValue());
            x = newX;
        } else {
            yzValues.put(nextEntry.getKey().second, nextEntry.getValue());
        }
        if (!iterator.hasNext()) {
            yzValues.put(nextEntry.getKey().second, nextEntry.getValue());
            final Interpolator1DDataBundle interpolatorData = _yInterpolator.getDataBundle(yzValues);
            result.put(x, interpolatorData);
        }
    }
    return result;
}

From source file:org.apache.accumulo.server.init.Initialize.java

private static void createMetadataFile(VolumeManager volmanager, String fileName, Tablet... tablets)
        throws IOException {
    // sort file contents in memory, then play back to the file
    TreeMap<Key, Value> sorted = new TreeMap<>();
    for (Tablet tablet : tablets) {
        createEntriesForTablet(sorted, tablet);
    }//ww w . j  a va 2 s  .  com
    FileSystem fs = volmanager.getVolumeByPath(new Path(fileName)).getFileSystem();
    FileSKVWriter tabletWriter = FileOperations.getInstance().newWriterBuilder()
            .forFile(fileName, fs, fs.getConf())
            .withTableConfiguration(AccumuloConfiguration.getDefaultConfiguration()).build();
    tabletWriter.startDefaultLocalityGroup();

    for (Entry<Key, Value> entry : sorted.entrySet()) {
        tabletWriter.append(entry.getKey(), entry.getValue());
    }

    tabletWriter.close();
}

From source file:io.druid.query.search.SearchQueryRunner.java

private Sequence<Result<SearchResultValue>> makeReturnResult(int limit, TreeMap<SearchHit, MutableInt> retVal) {
    Iterable<SearchHit> source = Iterables.transform(retVal.entrySet(),
            new Function<Map.Entry<SearchHit, MutableInt>, SearchHit>() {
                @Override/*from   www  . j a v  a2  s .  c o  m*/
                public SearchHit apply(Map.Entry<SearchHit, MutableInt> input) {
                    SearchHit hit = input.getKey();
                    return new SearchHit(hit.getDimension(), hit.getValue(), input.getValue().intValue());
                }
            });
    return Sequences.simple(ImmutableList
            .of(new Result<SearchResultValue>(segment.getDataInterval().getStart(), new SearchResultValue(
                    Lists.newArrayList(new FunctionalIterable<SearchHit>(source).limit(limit))))));
}

From source file:net.oremland.rss.reader.fragments.BaseListFragment.java

private List<TModel> getModelList(TreeMap<String, TModel> items) {
    List<TModel> models = new ArrayList<TModel>();
    for (Map.Entry<String, TModel> item : items.entrySet()) {
        models.add(item.getValue());// ww  w  . j a  v  a  2 s  .co  m
    }
    return models;
}

From source file:uk.ac.kcl.itemProcessors.DbLineFixerItemProcessor.java

@Override
public Document process(final Document doc) throws Exception {
    LOG.debug("starting " + this.getClass().getSimpleName() + " on doc " + doc.getDocName());
    String sql = MessageFormat.format(
            "SELECT {0}, {1}, {2} FROM {3} WHERE {0} = ''{4}'' " + " ORDER BY {5} DESC ", documentKeyName,
            lineKeyName, lineContents, srcTableName, doc.getPrimaryKeyFieldValue(), lineKeyName);

    List<MultilineDocument> docs = template.query(sql, simpleMapper);

    TreeMap<Integer, String> map = new TreeMap<>();
    for (MultilineDocument mldoc : docs) {
        map.put(Integer.valueOf(mldoc.getLineKey()), mldoc.getLineContents());
    }//from w  w w.  j a  v  a2  s  .  c  o m
    StringBuilder sb2 = new StringBuilder();
    for (Map.Entry<Integer, String> entry : map.entrySet()) {
        sb2.append(entry.getValue());
    }

    addField(doc, sb2.toString());
    LOG.debug("finished " + this.getClass().getSimpleName() + " on doc " + doc.getDocName());
    return doc;
}

From source file:org.apache.hadoop.hive.metastore.MetastoreDirectSqlUtils.java

/**
 * Merges applies the result of a PM SQL query into a tree of object.
 * Essentially it's an object join. DN could do this for us, but it issues queries
 * separately for every object, which is suboptimal.
 * @param pm//from   w ww. ja v  a  2  s .  c o  m
 * @param tree The object tree, by ID.
 * @param queryText The query text.
 * @param keyIndex Index of the Long column corresponding to the map ID in query result rows.
 * @param func The function that is called on each (object,row) pair with the same id.
 * @return the count of results returned from the query.
 */
static <T> int loopJoinOrderedResult(PersistenceManager pm, TreeMap<Long, T> tree, String queryText,
        Object[] parameters, int keyIndex, ApplyFunc<T> func) throws MetaException {
    boolean doTrace = LOG.isDebugEnabled();
    long start = doTrace ? System.nanoTime() : 0;
    Query query = pm.newQuery("javax.jdo.query.SQL", queryText);
    Object result = null;
    if (parameters == null || parameters.length == 0) {
        result = query.execute();
    } else {
        result = query.executeWithArray(parameters);
    }
    long queryTime = doTrace ? System.nanoTime() : 0;
    if (result == null) {
        query.closeAll();
        return 0;
    }
    List<Object[]> list = ensureList(result);
    Iterator<Object[]> iter = list.iterator();
    Object[] fields = null;
    for (Map.Entry<Long, T> entry : tree.entrySet()) {
        if (fields == null && !iter.hasNext())
            break;
        long id = entry.getKey();
        while (fields != null || iter.hasNext()) {
            if (fields == null) {
                fields = iter.next();
            }
            long nestedId = extractSqlLong(fields[keyIndex]);
            if (nestedId < id)
                throw new MetaException("Found entries for unknown ID " + nestedId);
            if (nestedId > id)
                break; // fields belong to one of the next entries
            func.apply(entry.getValue(), fields);
            fields = null;
        }
        Deadline.checkTimeout();
    }
    int rv = list.size();
    query.closeAll();
    timingTrace(doTrace, queryText, start, queryTime);
    return rv;
}

From source file:org.mule.transport.email.MailMuleMessageFactory.java

@Override
protected void addAttachments(DefaultMuleMessage muleMessage, Object transportMessage) throws Exception {
    super.addAttachments(muleMessage, transportMessage);

    Object content = ((Message) transportMessage).getContent();
    if (content instanceof Multipart) {
        Multipart multipart = (Multipart) content;

        TreeMap<String, Part> attachments = new TreeMap<String, Part>();
        MailUtils.getAttachments(multipart, attachments);

        log.debug("Received Multipart message. Adding attachments");
        for (Map.Entry<String, Part> entry : attachments.entrySet()) {
            Part part = entry.getValue();
            String name = entry.getKey();

            muleMessage.addInboundAttachment(name, part.getDataHandler());
            addAttachmentHeaders(name, part, muleMessage);
        }//from www.j  a  v a2s .c o  m
    }
}

From source file:org.opennms.netmgt.vmmgr.Starter.java

private void loadGlobalProperties() {
    // Log system properties, sorted by property name
    TreeMap<Object, Object> sortedProps = new TreeMap<Object, Object>(System.getProperties());
    for (Entry<Object, Object> entry : sortedProps.entrySet()) {
        LOG.debug("System property '{}' already set to value '{}'.", entry.getKey(), entry.getValue());
    }// w  ww  . ja v a  2  s .  c o m

    File propertiesFile = getPropertiesFile();
    if (!propertiesFile.exists()) {
        // don't require the file
        return;
    }

    Properties props = new Properties();
    InputStream in = null;
    try {
        in = new FileInputStream(propertiesFile);
        props.load(in);
    } catch (IOException e) {
        die("Error trying to read properties file '" + propertiesFile + "': " + e, e);
    } finally {
        IOUtils.closeQuietly(in);
    }

    for (Entry<Object, Object> entry : props.entrySet()) {
        String systemValue = System.getProperty(entry.getKey().toString());
        if (systemValue != null) {
            LOG.debug(
                    "Property '{}' from {} already exists as a system property (with value '{}').  Not overridding existing system property.",
                    entry.getKey(), propertiesFile, systemValue);
        } else {
            LOG.debug("Setting system property '{}' to '{}' from {}.", entry.getKey(), entry.getValue(),
                    propertiesFile);
            System.setProperty(entry.getKey().toString(), entry.getValue().toString());
        }
    }

    if (props.containsKey("networkaddress.cache.ttl")) {
        java.security.Security.setProperty("networkaddress.cache.ttl",
                props.getProperty("networkaddress.cache.ttl"));
    } else {
        java.security.Security.setProperty("networkaddress.cache.ttl", "120");
    }
}

From source file:org.j2free.util.ServletUtils.java

/**
 * Returns true if the parameter string prior to the "sig" parameter match the "sig"
 * parameter when combined with the key and hashed.  For post requests, the parameter
 * order is not guaranteed and so is assumed to be sorted alphabetically by key.
 *
 * @param req/*from   w  w w. j  a va 2s.c om*/
 * @param secret
 * @return
 */
public static boolean isAuthenticatedRequest(HttpServletRequest req, String secret) {
    String query, sig = getStringParameter(req, "sig"), method = req.getMethod();
    if (method.equalsIgnoreCase("GET")) {
        query = req.getQueryString();

        if (StringUtils.isBlank(query) || StringUtils.isBlank(sig))
            return false;

        query = query.replace("&sig=" + sig, EMPTY);
    } else if (method.equalsIgnoreCase("POST")) {
        TreeMap<String, String[]> params = new TreeMap(req.getParameterMap());
        params.remove("sig"); // remove the signature

        StringBuilder buf = new StringBuilder();
        for (Map.Entry<String, String[]> entry : params.entrySet()) {
            if (buf.length() > 0)
                buf.append("&");

            buf.append(entry.getKey());
            buf.append('=');
            buf.append(entry.getValue()[0]);
        }
        query = buf.toString();
    } else // We're not supporting auth on non GET or POST requests
        return false;

    return signQueryString(query, secret).equals(sig);
}

From source file:com.itude.mobile.mobbl.server.http.HttpDelegate.java

private synchronized Header[] transformToHeader(TreeMap<String, String[]> headers) {
    if (headers == null)
        return null;

    Header[] result = new Header[headers.size()];
    Iterator<Entry<String, String[]>> iterator = headers.entrySet().iterator();

    int i = 0;//from   w  w  w  .j  av a 2 s.  com
    while (iterator.hasNext()) {
        Entry<String, String[]> entry = iterator.next();
        for (String s : entry.getValue())
            result[i] = new Header(entry.getKey(), s);
        i++;
    }

    return result;
}