Example usage for java.util SortedMap keySet

List of usage examples for java.util SortedMap keySet

Introduction

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

Prototype

Set<K> keySet();

Source Link

Document

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

Usage

From source file:annis.WekaHelper.java

public static String exportAsArff(List<AnnotatedMatch> annotatedMatches) {
    StringBuilder sb = new StringBuilder();

    // header: relation name (unused)
    sb.append("@relation name\n");
    sb.append("\n");

    // figure out what annotations are used at each match position
    SortedMap<Integer, SortedSet<String>> columnsByNodePos = new TreeMap<Integer, SortedSet<String>>();

    for (int i = 0; i < annotatedMatches.size(); ++i) {
        AnnotatedMatch match = annotatedMatches.get(i);
        for (int j = 0; j < match.size(); ++j) {
            AnnotatedSpan span = match.get(j);
            if (columnsByNodePos.get(j) == null) {
                columnsByNodePos.put(j, new TreeSet<String>());
            }/*from   w  w w . ja v  a  2 s.c  om*/
            for (Annotation annotation : span.getAnnotations()) {
                columnsByNodePos.get(j).add("anno_" + annotation.getQualifiedName());
            }

            for (Annotation meta : span.getMetadata()) {
                columnsByNodePos.get(j).add("meta_" + meta.getQualifiedName());
            }

        }
    }

    // print column names and data types
    int count = columnsByNodePos.keySet().size();

    for (int j = 0; j < count; ++j) {
        sb.append("@attribute ").append(fullColumnName(j + 1, "id")).append(" string\n");
        sb.append("@attribute ").append(fullColumnName(j + 1, "span")).append(" string\n");
        SortedSet<String> annotationNames = columnsByNodePos.get(j);
        for (String name : annotationNames) {
            sb.append("@attribute ").append(fullColumnName(j + 1, name)).append(" string\n");
        }
    }
    sb.append("\n@data\n\n");

    // print values
    for (AnnotatedMatch match : annotatedMatches) {
        List<String> line = new ArrayList<String>();
        int k = 0;
        for (; k < match.size(); ++k) {
            AnnotatedSpan span = match.get(k);
            Map<String, String> valueByName = new HashMap<String, String>();

            if (span != null) {
                if (span.getAnnotations() != null) {
                    for (Annotation annotation : span.getAnnotations()) {
                        valueByName.put("anno_" + annotation.getQualifiedName(), annotation.getValue());
                    }
                }
                if (span.getMetadata() != null) {
                    for (Annotation meta : span.getMetadata()) {
                        valueByName.put("meta_" + meta.getQualifiedName(), meta.getValue());
                    }
                }

                line.add("'" + span.getId() + "'");
                line.add("'" + span.getCoveredText().replace("'", "\\'") + "'");
            }

            for (String name : columnsByNodePos.get(k)) {
                if (valueByName.containsKey(name)) {
                    line.add("'" + valueByName.get(name).replace("'", "\\'") + "'");
                } else {
                    line.add("'NULL'");
                }
            }
        }
        for (int l = k; l < count; ++l) {
            line.add("'NULL'");
            for (int m = 0; m <= columnsByNodePos.get(l).size(); ++m) {
                line.add("'NULL'");
            }
        }
        sb.append(StringUtils.join(line, ","));
        sb.append("\n");
    }

    return sb.toString();
}

From source file:org.esupportail.papercut.domain.PayBoxForm.java

public String getParamsAsString() {
    String paramsAsString = "";
    SortedMap<String, String> params = getOrderedParams();
    for (String key : params.keySet()) {
        paramsAsString = paramsAsString + key + "=" + params.get(key) + "&";
    }/*from   ww  w .  j  a  va 2  s . c o  m*/
    paramsAsString = paramsAsString.subSequence(0, paramsAsString.length() - 1).toString();
    try {
        // paramsAsString = URLEncoder.encode(paramsAsString, "utf8");
        System.out.println(paramsAsString);
        return paramsAsString;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.vrem.wifianalyzer.vendor.VendorAdapter.java

VendorAdapter(@NonNull Context context, @NonNull SortedMap<String, List<String>> vendors) {
    super(context, R.layout.vendor_details, new ArrayList<>(vendors.keySet()));
    this.vendors = vendors;
}

From source file:org.apache.hadoop.hbase.regionserver.ccindex.IndexedRegion.java

public static void putIndexMultTable(IndexedRegion r, IndexSpecification indexSpec, byte[] row,
        SortedMap<byte[], byte[]> columnValues, Integer lockId, Result oldResult) throws IOException {
    updateTimes++;/* w  w  w .  ja  v  a 2s. c  om*/
    HashSet<String> IndexColumns = new HashSet<String>();
    Put lastPut = null;

    if (r.orgTable == null) {
        HTableDescriptor td = r.getTableDesc();
        r.orgTable = new HTable(r.conf, td.getName());
        r.orgTable.setWriteBufferSize(1000 * 1000 * 20);
    }

    for (byte[] column : indexSpec.getIndexedColumns()) {
        IndexColumns.add(new String(column));
    }
    boolean hasIndex = false;

    for (byte[] column : columnValues.keySet())
        if (IndexColumns.contains(new String(column))) {
            if (oldResult != null && oldResult.raw() != null && oldResult.list() != null) {
                if (oldResult.getValue(column).equals(columnValues.get(column))) {
                    continue;
                }
                SortedMap<byte[], byte[]> oldColumnValues = r.convertToValueMap(oldResult);
                Get get = new Get(indexSpec.getKeyGenerator().createIndexKey(row, oldColumnValues));

                get.addColumn(column);
                try {
                    if (r.isClosed()) {
                        oldResult = r.orgTable.get(get);
                    } else
                        oldResult = r.superGet(get, lockId);
                    if (oldResult != null && oldResult.raw() != null && oldResult.list() != null) {
                        Delete delete = new Delete(get.getRow());
                        r.getIndexTable(indexSpec).delete(delete);
                        r.getCCTTable(indexSpec).delete(delete);
                    }

                    deletTimes++;
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }

            }
        }

    for (byte[] column : columnValues.keySet())
        if (IndexColumns.contains(new String(column))) {

            hasIndex = true;
            Get oldGet = new Get(row);

            HColumnDescriptor dess[] = r.getTableDesc().getColumnFamilies();
            for (HColumnDescriptor des : dess) {
                if (columnValues.get(des.getName()) == null) {
                    oldGet.addColumn(des.getName());
                }
            }
            // oldGet.addColumn(column);
            oldResult = null;
            if (r.isClosed()) {
                oldResult = r.orgTable.get(oldGet);
            } else
                oldResult = r.superGet(oldGet, lockId);
            if (oldResult != null && oldResult.raw() != null && oldResult.list() != null) {
                for (KeyValue kv : oldResult.list()) {
                    if (columnValues.get(kv.getColumn()) == null)
                        columnValues.put(kv.getColumn(), kv.getValue());
                }
            }
        }
    if (!hasIndex) {
        Get oldGet = new Get(row);
        oldGet.addColumn(indexSpec.getIndexedColumns()[0]);
        oldResult = null;
        if (r.isClosed()) {
            oldResult = r.orgTable.get(oldGet);
        } else
            oldResult = r.superGet(oldGet, lockId);
        if (!(oldResult != null && oldResult.raw() != null && oldResult.list() != null)) {
            return;
        } else {
            SortedMap<byte[], byte[]> oldColumnValues = r.convertToValueMap(oldResult);
            for (KeyValue kv : oldResult.list()) {
                columnValues.put(kv.getColumn(), kv.getValue());
            }
        }

    }
    lastPut = IndexMaintenanceUtils.createIndexUpdate(indexSpec, row, columnValues);

    r.getIndexTable(indexSpec).put(lastPut);
    HTable cct = r.getCCTTable(indexSpec);
    cct.put(IndexMaintenanceUtils.createCCTUpdate(indexSpec, row, columnValues, r.indexTableDescriptor));

}

From source file:com.vrem.wifianalyzer.vendor.VendorAdapter.java

void setVendors(@NonNull SortedMap<String, List<String>> vendors) {
    this.vendors = vendors;
    clear();/*ww w  . j a va  2  s.  c  o m*/
    addAll(new ArrayList<>(vendors.keySet()));
}

From source file:org.motrice.jmx.BasicAppManagement.java

/**
 * Get the names and log levels of all loggers.
 *///from  w w  w . j  a  v a2 s .c  om
@ManagedAttribute(description = "Application loggers and log levels", currencyTimeLimit = 10)
public List<String> getLoggers() {
    List<String> nameList = new ArrayList<String>();
    SortedMap<String, Logger> map = doGetLoggers();
    for (String key : map.keySet()) {
        Logger log = map.get(key);
        if (log != null && log.getLevel() != null) {
            nameList.add(key + " = " + log.getLevel());
        }
    }

    return nameList;
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.Step6GraphTransitivityCleaner.java

@SuppressWarnings("unchecked")
public static void printResultStatistics(File xmlFile) throws IllegalAccessException {
    Map<String, Map<String, GraphCleaningResults>> results = (Map<String, Map<String, GraphCleaningResults>>) XStreamTools
            .getXStream().fromXML(xmlFile);

    //        System.out.println(results);

    SortedMap<String, List<GraphCleaningResults>> resultsGroupedByMethod = new TreeMap<>();

    for (Map.Entry<String, Map<String, GraphCleaningResults>> entry : results.entrySet()) {
        //            System.out.println(entry.getKey());

        for (Map.Entry<String, GraphCleaningResults> e : entry.getValue().entrySet()) {
            //                System.out.println(e.getKey());
            //                System.out.println(e.getValue());

            if (!resultsGroupedByMethod.containsKey(e.getKey())) {
                resultsGroupedByMethod.put(e.getKey(), new ArrayList<GraphCleaningResults>());
            }//from  www . ja  v  a 2 s . c o  m

            resultsGroupedByMethod.get(e.getKey()).add(e.getValue());
        }
    }

    String header = null;

    // collect statistics
    for (Map.Entry<String, List<GraphCleaningResults>> entry : resultsGroupedByMethod.entrySet()) {
        List<GraphCleaningResults> value = entry.getValue();
        SortedMap<String, DescriptiveStatistics> stringDescriptiveStatisticsMap = collectStatisticsOverGraphCleaningResults(
                value);

        if (header == null) {
            header = StringUtils.join(stringDescriptiveStatisticsMap.keySet(), "\t");
            System.out.println("\t\t" + header);
        }

        List<Double> means = new ArrayList<>();
        List<Double> stdDevs = new ArrayList<>();
        for (DescriptiveStatistics statistics : stringDescriptiveStatisticsMap.values()) {
            means.add(statistics.getMean());
            stdDevs.add(statistics.getStandardDeviation());
        }

        List<String> meansString = new ArrayList<>();
        for (Double mean : means) {
            meansString.add(String.format(Locale.ENGLISH, "%.2f", mean));
        }

        List<String> stdDevString = new ArrayList<>();
        for (Double stdDev : stdDevs) {
            stdDevString.add(String.format(Locale.ENGLISH, "%.2f", stdDev));
        }

        System.out.println(entry.getKey() + "\tmean\t" + StringUtils.join(meansString, "\t"));
        //            System.out.println(entry.getKey() + "\tstdDev\t" + StringUtils.join(stdDevString, "\t"));
    }
}

From source file:com.adyen.Util.HMACValidator.java

public String getDataToSign(SortedMap<String, String> postParameters) {
    List<String> parts = new ArrayList<>();

    for (String key : postParameters.keySet()) {
        parts.add(escapeVal(key));// w  ww  . j a  v a 2s . c  om
    }

    for (String value : postParameters.values()) {
        parts.add(escapeVal(value));
    }

    return Util.implode(DATA_SEPARATOR, parts);
}

From source file:org.libreplan.web.common.components.finders.CriterionMultipleFiltersFinder.java

@Override
public List<FilterPair> getFirstTenFilters() {
    getListMatching().clear();//  ww  w  .  j  a  v a 2  s .co  m
    SortedMap<CriterionType, List<Criterion>> criterionsMap = getCriterionsMap();
    Iterator<CriterionType> iteratorCriterionType = criterionsMap.keySet().iterator();
    while (iteratorCriterionType.hasNext() && getListMatching().size() < 10) {
        CriterionType type = iteratorCriterionType.next();
        for (int i = 0; getListMatching().size() < 10 && i < criterionsMap.get(type).size(); i++) {
            Criterion criterion = criterionsMap.get(type).get(i);
            addCriterion(type, criterion);
        }
    }
    return getListMatching();
}

From source file:com.github.lukaszbudnik.dqueue.QueueClientPerformanceTest.java

@After
public void after() throws Exception {
    session.execute("drop keyspace " + cassandraKeyspace);

    SortedMap<String, Timer> timers = metricRegistry.getTimers();

    timers.keySet().stream().forEach(k -> {
        Timer t = timers.get(k);/*from  ww w.j  a  va 2s .  c o m*/
        System.out.println(k);
        System.out.println("\ttimes called ==> " + t.getCount());
        System.out.println("\tmedian ==> " + t.getSnapshot().getMedian() / 1000 / 1000);
        System.out.println("\t75th percentile ==> " + t.getSnapshot().get75thPercentile() / 1000 / 1000);
        System.out.println("\t99th percentile ==> " + t.getSnapshot().get99thPercentile() / 1000 / 1000);
    });

    queueClient.close();
}