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:org.aliuge.crawler.extractor.selector.IFConditions.java

/**
 * ???//from   w  ww .  j  ava  2  s  .co  m
 * 
 * @param depend
 * @return
 */
public boolean test(Map<String, Object> selectContent) throws ExtractException {
    TreeMap<Integer, String> conIndex = Maps.newTreeMap();
    Queue<SimpleExpression> expressionQueue = Queues.newArrayDeque();
    Queue<String> logicQueue = Queues.newArrayDeque();
    // a=b and c=d or c=e or x=y
    int index = 0;
    for (String co : cond) {
        index = 0;
        while ((index = conditions.indexOf(co, index + 1)) > -1) {
            int i = index;
            conIndex.put(i, co);
        }
    }
    index = 0;
    for (Entry<Integer, String> entry : conIndex.entrySet()) {
        String subExp = conditions.substring(index, entry.getKey());
        for (String op : operations) {
            int i = subExp.indexOf(op);
            if (i > -1) {
                String[] ss = subExp.split(op);
                if (null == selectContent.get(ss[0].trim())) {
                    throw new ExtractException("?????["
                            + this.conditions + "] " + ss[0]);
                }
                expressionQueue
                        .add(new SimpleExpression(StringUtils.trim((String) selectContent.get(ss[0].trim())),
                                StringUtils.trim(ss[1]), op));
                logicQueue.add(StringUtils.trim(entry.getValue()));
            }
        }
        index = entry.getKey() + entry.getValue().length();
    }
    // ??
    String subExp = conditions.substring(index);
    for (String op : operations) {
        int i = subExp.indexOf(op);
        if (i > -1) {
            String[] ss = subExp.split(op);
            if (null == selectContent.get(ss[0].trim())) {
                throw new ExtractException("?????[" + this.conditions
                        + "] " + ss[0]);
            }
            expressionQueue.add(new SimpleExpression(StringUtils.trim((String) selectContent.get(ss[0].trim())),
                    StringUtils.trim(ss[1]), op));
        }
    }
    boolean b;
    try {
        b = expressionQueue.poll().test();
        while (!expressionQueue.isEmpty()) {
            b = cacl(b, logicQueue.poll(), expressionQueue.poll());
        }
        return b;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return false;
}

From source file:com.heliosapm.tsdblite.metric.Metric.java

public ObjectName toHostObjectName() {
    final StringBuilder b = new StringBuilder("metrics.");
    TreeMap<String, String> tgs = new TreeMap<String, String>(tags);
    String h = tgs.remove("host");
    String a = tgs.remove("app");
    final String host = h == null ? "unknownhost" : h;
    final int segIndex = metricName.indexOf('.');
    final String seg = segIndex == -1 ? metricName : metricName.substring(0, segIndex);
    b.append(host).append(".").append(seg).append(":");
    if (segIndex != -1) {
        tgs.put("app", metricName.substring(segIndex + 1));
    }//from www . j  av a2s . co  m
    for (Map.Entry<String, String> entry : tgs.entrySet()) {
        b.append(entry.getKey()).append("=").append(entry.getValue()).append(",");
    }
    b.deleteCharAt(b.length() - 1);
    return JMXHelper.objectName(b);
}

From source file:net.tsquery.DataEndpoint.java

@SuppressWarnings("unchecked")
private JSONObject PlotToDygraphJSON(Plot plot, long tsFrom, long tsTo, int topN) {
    final JSONObject plotObject = new JSONObject();
    final JSONArray nameArray = new JSONArray();
    final JSONArray dataArray = new JSONArray();
    final int dpCount = plot.getDataPointsSize();

    final TreeMap<Long, double[]> tsMap = new TreeMap<>();
    final double[] weight = new double[dpCount];

    int dpIndex = 0;
    for (DataPoints dataPoints : plot.getDataPoints()) {

        for (DataPoint point : dataPoints) {
            long timestamp = point.timestamp();
            if (timestamp < tsFrom || timestamp > tsTo)
                continue;

            long tsMSec = timestamp * 1000;
            if (!tsMap.containsKey(tsMSec)) {
                double[] values = new double[dpCount];
                values[dpIndex] = getValue(point);
                tsMap.put(tsMSec, values);

                weight[dpIndex] += ((values[dpIndex]) / 1000000.0);
            } else {
                //noinspection MismatchedReadAndWriteOfArray
                double[] values = tsMap.get(tsMSec);
                values[dpIndex] = getValue(point);
                weight[dpIndex] += ((values[dpIndex]) / 1000000.0);
            }// ww w . j  a  v a 2s. c om
        }

        dpIndex++;
    }

    HashMap<Integer, Boolean> includeMap = null;
    // are we performing a topN lookup?
    if (topN > 0) {
        includeMap = new HashMap<>(topN);
        TreeMap<Double, Integer> weightMap = new TreeMap<>(Collections.reverseOrder());
        for (int i = 0; i < dpCount; i++) {
            while (weightMap.containsKey(weight[i]))
                weight[i] -= 0.00000001;

            weightMap.put(weight[i], i);
        }

        int series = 0;
        for (Map.Entry<Double, Integer> entry : weightMap.entrySet()) {
            includeMap.put(entry.getValue(), true);

            ++series;
            if (series >= topN)
                break;
        }
    }

    for (Map.Entry<Long, double[]> entry : tsMap.entrySet()) {
        JSONArray entryArray = new JSONArray();
        entryArray.add(entry.getKey());
        final double[] points = entry.getValue();

        for (dpIndex = 0; dpIndex < dpCount; dpIndex++) {
            if ((topN <= 0) || (topN > 0 && includeMap.containsKey(dpIndex))) {
                entryArray.add(points[dpIndex]);
            }
        }

        dataArray.add(entryArray);
    }

    // First column is always the Date
    nameArray.add("Date");

    int index = -1;
    for (DataPoints dataPoints : plot.getDataPoints()) {
        index++;

        // if we are in a topN query and the current index is not included, skip this iteration
        if (topN > 0 && !includeMap.containsKey(index))
            continue;

        StringBuilder nameBuilder = new StringBuilder();

        nameBuilder.append(dataPoints.metricName()).append(":");

        Map<String, String> tags = dataPoints.getTags();
        for (String s : tags.keySet()) {
            nameBuilder.append(String.format(" %s=%s", s, tags.get(s)));
        }

        nameArray.add(nameBuilder.toString());
    }
    plotObject.put("labels", nameArray);
    plotObject.put("values", dataArray);

    return plotObject;
}

From source file:no.met.jtimeseries.netcdf.NetcdfChartProvider.java

public void getCsv(PrintStream out, Iterable<String> variables) throws ParseException, IOException {

    Vector<NumberPhenomenon> data = getWantedPhenomena(variables);

    // header/*from  ww w .  j  a v  a2s  .  co m*/
    out.print("# Time");
    for (NumberPhenomenon p : data)
        out.print(",\t" + p.getPhenomenonName() + " (" + p.getPhenomenonUnit() + ")");
    out.println();

    TreeMap<Date, Double[]> displayData = new TreeMap<Date, Double[]>();
    for (int i = 0; i < data.size(); i++) {
        for (NumberValueItem atom : data.get(i)) {
            Double[] d = displayData.get(atom.getTimeFrom());
            if (d == null) {
                d = new Double[data.size()];
                displayData.put(atom.getTimeFrom(), d);
            }
            d[i] = atom.getValue();
        }
    }

    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    for (Entry<Date, Double[]> element : displayData.entrySet()) {
        out.print(format.format(element.getKey()));
        Double[] d = element.getValue();
        for (int i = 0; i < d.length; i++)
            out.print(",\t" + d[i]);
        out.println();
    }
}

From source file:org.lockss.servlet.AddContent.java

private void deletePublisher(String publisher) throws IOException {
    TreeMap<String, TreeMap<String, TreeSet<ArchivalUnit>>> auMap = DisplayContentTab.getAusByPublisherName();
    ArrayList<String> auIds = new ArrayList<String>();
    if (auMap.containsKey(publisher)) {
        for (Map.Entry<String, TreeMap<String, TreeSet<ArchivalUnit>>> entry : auMap.entrySet()) {
            String publisherString = entry.getKey();
            log.error("Publisher: " + publisher);
            log.error("Publisher string: " + publisherString);
            if (publisher.equals(publisherString)) {
                TreeMap<String, TreeSet<ArchivalUnit>> titleMap = entry.getValue();
                for (Map.Entry<String, TreeSet<ArchivalUnit>> stringTreeSetEntry : titleMap.entrySet()) {
                    TreeSet<ArchivalUnit> auSet = stringTreeSetEntry.getValue();
                    for (ArchivalUnit au : auSet) {
                        auIds.add(au.getAuId());
                    }/*from  w  w  w.  j a va  2s  .c  o m*/
                }
            }
        }
        doRemoveAus(auIds);
        session.setAttribute("actionMessage",
                "All AUs associated with publisher " + publisher + " were deleted");
    } else {
        log.error("Could not find publisher");
    }
}

From source file:net.anthonypoon.ngram.rollingregression.RollingRegressionReducer.java

@Override
protected void reduce(Text key, Iterable<Text> values, Context context)
        throws IOException, InterruptedException {
    TreeMap<String, Double> currElement = new TreeMap();
    boolean pastThreshold = false;
    for (Text val : values) {
        String[] strArray = val.toString().split("\t");
        if (Double.valueOf(strArray[1]) > threshold) {
            pastThreshold = true;//from   ww w .  j ava  2  s  .c o  m
        }
        currElement.put(strArray[0], Math.log(Double.valueOf(strArray[1])));
    }
    if (pastThreshold) {
        for (Integer i = 0; i <= upbound - lowbound; i++) {
            if (!currElement.containsKey(String.valueOf(lowbound + i))) {
                if (i != 0) {
                    currElement.put(String.valueOf(lowbound + i),
                            currElement.get(String.valueOf(lowbound + i - 1)));
                } else {
                    currElement.put(String.valueOf(lowbound + i), 0.0);
                }
            }

        }
        TreeMap<String, Double> result = new TreeMap();
        for (Integer i = 0 + range; i <= upbound - lowbound - range; i++) {
            SimpleRegression regression = new SimpleRegression();
            for (Integer l = -range; l <= range; l++) {
                regression.addData(l.doubleValue(), currElement.get(String.valueOf(i + lowbound + l)));
            }
            if (!Double.isNaN(regression.getSlope())) {
                if (!positiveOnly || regression.getSlope() > 0) {
                    result.put(String.valueOf(lowbound + i), regression.getSlope());
                }
            }
        }
        for (Map.Entry<String, Double> pair : result.entrySet()) {
            context.write(key, new Text(pair.getKey() + "\t" + String.format("%.5f", pair.getValue())));
        }
    }
}

From source file:GitBackend.GitAPI.java

private void printCommitMap(TreeMap<DateTime, RevCommit> commitMap) {
    Iterator it = commitMap.entrySet().iterator();

    System.out.println("Number of commits here: " + commitMap.size());
    while (it.hasNext()) {
        Map.Entry pair = (Map.Entry) it.next();
        RevCommit commit = (RevCommit) pair.getValue();
        System.out.println(pair.getKey() + " --- " + commit.getName());

    }//from   w w  w.  ja v  a 2  s . co  m
}

From source file:org.opencms.workplace.tools.database.CmsHtmlImportDialog.java

/**
 * Returns a list with all available templates.<p>
 * //  ww  w.  j  a v a2  s  .c o  m
 * @return a list with all available templates
 */
private List getTemplates() {

    ArrayList ret = new ArrayList();
    TreeMap templates = null;

    try {
        templates = CmsNewResourceXmlPage.getTemplates(getJsp().getCmsObject(), null);

        // loop through all templates and build the entries
        Iterator i = templates.entrySet().iterator();
        while (i.hasNext()) {
            Map.Entry entry = (Map.Entry) i.next();
            String title = (String) entry.getKey();
            String path = (String) entry.getValue();

            ret.add(new CmsSelectWidgetOption(path, false, title));
        }
    } catch (CmsException e) {
        // not necessary
    }

    return ret;
}

From source file:org.openanzo.test.QueryTestSuiteBase.java

@SuppressWarnings("all")
protected QueryType getQueryType(String query) {
    String lc = query.toLowerCase();
    TreeMap<Integer, QueryType> m = new TreeMap<Integer, QueryType>();
    m.put(Integer.valueOf(lc.indexOf("select")), QueryType.SELECT);
    m.put(Integer.valueOf(lc.indexOf("construct")), QueryType.CONSTRUCT);
    m.put(Integer.valueOf(lc.indexOf("ask")), QueryType.ASK);
    m.put(Integer.valueOf(lc.indexOf("describe")), QueryType.DESCRIBE);
    for (Entry<Integer, QueryType> e : m.entrySet()) {
        int index = e.getKey();
        if (index > -1) {
            // determine if this index is inside a BASE or PREFIX clause. We do this by determining if
            // a colon immediately follows it or it is inside angle brackets
            int x;
            for (x = index + 3; Character.isJavaIdentifierPart(lc.charAt(x)); x++)
                ; //earliest the colon could be, if we're in ask
            if (lc.charAt(x) != ':') {
                int lt = lc.lastIndexOf('<', index);
                int gt = lc.lastIndexOf('>', index);
                if (lt == -1 || gt > lt) {
                    // no < before us, or else there's a > after the last <
                    return e.getValue();
                }/*w ww. j  a  va2  s .  c  om*/
            }
        }
    }
    fail("Unknown query type for query: " + query);
    return null;
}

From source file:streaming.core.WindowOperation.java

@Override
public Object[][] process(Object[] event) {
    long day = (Long) event[0];
    String word = (String) event[1];
    long freqs = (Long) event[2];

    TreeMap<Long, Long> sortedFreq = map.get(word);
    if (sortedFreq == null) {
        sortedFreq = new TreeMap<Long, Long>();
        map.put(word, sortedFreq);//from w w w. ja v a2  s  .  c om
    }

    Long t = sortedFreq.get(day);
    if (t != null) {
        freqs = freqs + t;
    }
    sortedFreq.put(day, freqs);

    Iterator<Entry<Long, Long>> iterator = sortedFreq.headMap(1 + day - numberOfDays).entrySet().iterator();
    while (iterator.hasNext()) {
        iterator.next();
        iterator.remove();
    }

    DescriptiveStatistics stats = new DescriptiveStatistics();
    long dayIndex = 1 + day - numberOfDays;
    for (Entry<Long, Long> e : sortedFreq.entrySet()) {
        while (e.getKey() > dayIndex) {
            dayIndex++;
            stats.addValue(0);
        }
        stats.addValue(e.getValue());
    }

    if (sortedFreq.size() > numberOfDays) {
        System.out.println(day + " size=" + sortedFreq.size() + " " + sortedFreq);
    }

    double mean = stats.getMean();
    double meadian = stats.getPercentile(50);
    mean = (mean == 0) ? 1 : mean;
    meadian = (meadian == 0) ? 1 : meadian;
    double stddev = stats.getStandardDeviation();
    stddev = (stddev == 0) ? 1 : stddev;
    double cov = stddev / mean;

    //double swna = Math.log(freqs)*freqs/stats.getMean();
    double swna1 = Math.log(meadian) * Math.abs(freqs - meadian) / stddev;
    if (Double.isNaN(swna1)) {
        System.out.println();
    }
    double swna2 = Math.abs(freqs - meadian) / stddev;
    double swna3 = freqs / (meadian * cov);

    Gaussian gaussian = new Gaussian(100, 50);

    double swna4 = (0.1 + 100 * gaussian.value(meadian)) * freqs / (meadian * cov);

    int percentageAvialableValues = Math.round(100 * sortedFreq.size() / numberOfDays);
    //System.out.println("#"+ word + " " + freqs + " "+ stats.getMean() + Arrays.toString(stats.getValues()));
    return new Object[][] { { day, word, swna1, freqs, stats.getMean(), meadian, stddev, swna2, swna3, swna4,
            cov, percentageAvialableValues } };

    //      if(freqs > 3 && swna> 5){
    //         return new Object[][]{{day, word, swna}};   
    //      }else{
    //         return null;
    //      }

}