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:Main.java

/**
 * Converter Map<Object, Object> instance to xml string. Note: currently, we
 * aren't consider more about some collection types, such as array,list,
 *
 * @param dataMap/*from  w ww. java 2 s. co m*/
 *            the data map
 *
 * @return the string
 */
public static String converter(SortedMap<String, String> dataMap) {
    StringBuilder strBuilder = new StringBuilder();
    strBuilder.append("<xml>\n");
    Set<String> objSet = dataMap.keySet();
    for (Object key : objSet) {
        if (key == null) {
            continue;
        }
        strBuilder.append("<").append(key.toString()).append(">");
        Object value = dataMap.get(key);
        strBuilder.append(coverter(value));
        strBuilder.append("</").append(key.toString()).append(">\n");
    }
    strBuilder.append("</xml>");
    return strBuilder.toString();
}

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

public static Put createOrgUpdate(final byte[] row, final SortedMap<byte[], byte[]> columnValues) {
    byte[] indexRow = row;
    Put update = null;//from  w ww.ja  v  a  2 s  . c  o  m
    update = new Put(indexRow);
    for (byte[] col : columnValues.keySet()) {
        try {
            byte[] val = columnValues.get(col);
            byte[][] colSeperated = HStoreKey.parseColumn(col);
            update.add(colSeperated[0], colSeperated[1], val);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            continue;
        }
    }

    return update;
}

From source file:eu.medsea.util.EncodingGuesser.java

/**
 * Utility method to get all of the current encoding names, in canonical format, supported by your JVM
 * at the time this is called./* w  w  w.  j a va2  s .  com*/
 * @return current Collection of canonical encoding names
 */
public static Collection getCanonicalEncodingNamesSupportedByJVM() {
    Collection encodings = new TreeSet();

    SortedMap charSets = Charset.availableCharsets();
    Collection charSetNames = charSets.keySet();
    for (Iterator it = charSetNames.iterator(); it.hasNext();) {
        encodings.add((String) it.next());
    }
    if (log.isDebugEnabled()) {
        log.debug("The following [" + encodings.size() + "] encodings will be used: " + encodings);
    }
    return encodings;
}

From source file:Main.java

public static String getStreamEncoding(InputStream stream) throws IOException {
    String encoding = null;/*w w  w  .j  a v  a2 s  . c  o  m*/
    boolean DEBUG = false;

    if (DEBUG) {
        SortedMap map = Charset.availableCharsets();
        Object[] keys = map.keySet().toArray();

        for (int i = 0; i < keys.length; i++) {
            System.out.println("Key = " + keys[i] + " Value = " + map.get(keys[i]));
        }
    }

    int ch = stream.read();
    if (DEBUG)
        System.out.print("[" + ch + "]");

    // UCS-4 Big Endian (1234)
    if (ch == 0x00) {
        ch = stream.read();
        if (DEBUG)
            System.out.print("[" + ch + "]");
        if (ch == 0x00) {
            ch = stream.read();
            if (DEBUG)
                System.out.print("[" + ch + "]");
            if (ch == 0xFE) {
                ch = stream.read();
                if (DEBUG)
                    System.out.print("[" + ch + "]");
                if (ch == 0xFF) {
                    encoding = UCS_4BE;
                }
            } else if (ch == 0xFF) {
                ch = stream.read();
                if (DEBUG)
                    System.out.print("[" + ch + "]");
                if (ch == 0xFE) {
                    encoding = UNKNOWN;
                }
            } else if (ch == 0x00) {
                ch = stream.read();
                if (DEBUG)
                    System.out.print("[" + ch + "]");
                if (ch == 0x3C) {
                    encoding = UCS_4BE;
                }
            } else if (ch == 0x3C) {
                ch = stream.read();
                if (DEBUG)
                    System.out.print("[" + ch + "]");
                if (ch == 0x00) {
                    encoding = UNKNOWN;
                }
            }
        } else if (ch == 0x3C) {
            ch = stream.read();
            if (DEBUG)
                System.out.print("[" + ch + "]");
            if (ch == 0x00) {
                ch = stream.read();
                if (DEBUG)
                    System.out.print("[" + ch + "]");
                if (ch == 0x00) {
                    encoding = UNKNOWN;
                } else if (ch == 0x3F) {
                    encoding = UTF_16BE;
                }
            }
        }
    } else if (ch == 0x3C) {
        ch = stream.read();
        if (DEBUG)
            System.out.print("[" + ch + "]");
        if (ch == 0x00) {
            ch = stream.read();
            if (DEBUG)
                System.out.print("[" + ch + "]");
            if (ch == 0x00) {
                ch = stream.read();
                if (DEBUG)
                    System.out.print("[" + ch + "]");
                if (ch == 0x00) {
                    encoding = UCS_4LE;
                }
            } else if (ch == 0x3F) {
                ch = stream.read();
                if (DEBUG)
                    System.out.print("[" + ch + "]");
                if (ch == 0x00) {
                    encoding = UTF_16LE;
                }
            }
        } else if (ch == 0x3F) {
            ch = stream.read();
            if (DEBUG)
                System.out.print("[" + ch + "]");
            if (ch == 0x78) {
                ch = stream.read();
                if (DEBUG)
                    System.out.print("[" + ch + "]");
                if (ch == 0x6D) {
                    encoding = UTF_8;
                }
            }
        }
    } else if (ch == 0xFF) {
        ch = stream.read();
        if (DEBUG)
            System.out.print("[" + ch + "]");
        if (ch == 0xFE) {
            ch = stream.read();
            encoding = UTF_16LE;
            if (DEBUG)
                System.out.print("[" + ch + "]");
            if (ch == 0x00) {
                ch = stream.read();
                if (DEBUG)
                    System.out.print("[" + ch + "]");
                if (ch == 0x00) {
                    encoding = UCS_4LE;
                }
            }
        }
    } else if (ch == 0xFE) {
        ch = stream.read();
        if (DEBUG)
            System.out.print("[" + ch + "]");
        if (ch == 0xFF) {
            ch = stream.read();

            encoding = UTF_16BE;
            if (DEBUG)
                System.out.print("[" + ch + "]");
            if (ch == 0x00) {
                ch = stream.read();
                if (DEBUG)
                    System.out.print("[" + ch + "]");
                if (ch == 0x00) {
                    encoding = UNKNOWN;
                }
            }
        }
    } else if (ch == 0xEF) {
        ch = stream.read();
        if (DEBUG)
            System.out.print("[" + ch + "]");
        if (ch == 0xBB) {
            ch = stream.read();
            if (DEBUG)
                System.out.print("[" + ch + "]");
            if (ch == 0xBF) {
                //               System.out.println( "Found UTF-8 byte order mark.");
                // strip utf-8 byte order mark
                stream.mark(1024);
                encoding = UTF_8;
            }
        }
    } else if (ch == 0x4C) {
        ch = stream.read();
        if (DEBUG)
            System.out.print("[" + ch + "]");
        if (ch == 0x6F) {
            ch = stream.read();
            if (DEBUG)
                System.out.print("[" + ch + "]");
            if (ch == 0xA7) {
                ch = stream.read();
                if (DEBUG)
                    System.out.print("[" + ch + "]");
                if (ch == 0x94) {
                    encoding = EBCDIC;
                }
            }
        }
    }

    if (DEBUG)
        System.out.println("getStreamEncoding() [" + encoding + "]");
    return encoding;
}

From source file:com.taobao.android.builder.tasks.manager.transform.TransformManager.java

public static List<TransformTask> findTransformTaskByTransformType(AppVariantContext appVariantContext,
        Class<?> transformClass) {
    List<TransformTask> transformTasksList = Lists.newArrayList();
    VariantConfiguration config = appVariantContext.getVariantConfiguration();
    TaskCollection<TransformTask> transformTasks = appVariantContext.getProject().getTasks()
            .withType(TransformTask.class);
    SortedMap<String, TransformTask> transformTaskSortedMap = transformTasks.getAsMap();
    String variantName = config.getFullName();
    for (String taskName : transformTaskSortedMap.keySet()) {
        TransformTask transformTask = transformTaskSortedMap.get(taskName);
        if (variantName == transformTask.getVariantName()) {
            if (transformTask.getTransform().getClass() == transformClass) {
                transformTasksList.add(transformTask);
            }/*  w  ww.  ja  v  a 2  s.c  om*/
        }
    }
    return transformTasksList;
}

From source file:de.tudarmstadt.ukp.experiments.dip.wp1.documents.Step11GoldDataStatistics.java

/**
 * Relevant sentences per document (per query)
 *//*from w w  w  .j a  v  a2  s .  co m*/
public static void statistics6(File inputDir, File outputDir) throws IOException {
    PrintWriter pw = new PrintWriter(new FileWriter(new File(outputDir, "stats6.csv")));

    SortedMap<String, DescriptiveStatistics> result = new TreeMap<>();
    result.put("relevantSentencesDocumentPercent", new DescriptiveStatistics());

    // print header
    for (String mapKey : result.keySet()) {
        pw.printf(Locale.ENGLISH, "%s\t%sStdDev\t", mapKey, mapKey);
    }
    pw.println();

    // iterate over query containers
    for (File f : FileUtils.listFiles(inputDir, new String[] { "xml" }, false)) {
        QueryResultContainer queryResultContainer = QueryResultContainer
                .fromXML(FileUtils.readFileToString(f, "utf-8"));
        System.out.println("Processing " + f);

        for (QueryResultContainer.SingleRankedResult rankedResult : queryResultContainer.rankedResults) {

            if (rankedResult.plainText != null && !rankedResult.plainText.isEmpty()) {

                int relevantSentences = 0;
                int totalSentences = 0;

                if (rankedResult.goldEstimatedLabels != null) {
                    for (QueryResultContainer.SingleSentenceRelevanceVote sentenceRelevanceVote : rankedResult.goldEstimatedLabels) {
                        totalSentences++;

                        if (Boolean.valueOf(sentenceRelevanceVote.relevant)) {
                            relevantSentences++;
                        }
                    }

                    // percent relevant

                    result.get("relevantSentencesDocumentPercent")
                            .addValue((double) relevantSentences / (double) totalSentences);
                }
            }
        }
    }

    // print results
    // print header
    for (String mapKey : result.keySet()) {
        pw.printf(Locale.ENGLISH, "%.3f\t%.3f\t", result.get(mapKey).getMean(),
                result.get(mapKey).getStandardDeviation());
    }

    pw.close();

}

From source file:org.hippoecm.frontend.usagestatistics.UsageStatisticsExternalUrl.java

public static String get() {
    final SortedMap<String, String> parameters = new TreeMap<>();

    parameters.put(RELEASE_VERSION, new SystemInfoDataProvider().getReleaseVersion());

    final Calendar now = Calendar.getInstance();
    parameters.put(YEAR, String.valueOf(now.get(Calendar.YEAR)));
    parameters.put(MONTH, String.valueOf(now.get(Calendar.MONTH) + 1));
    parameters.put(DAY, String.valueOf(now.get(Calendar.DAY_OF_MONTH)));

    final String[] search = parameters.keySet().toArray(new String[parameters.size()]);
    final String[] replacements = parameters.values().toArray(new String[parameters.size()]);

    return StringUtils.replaceEach(getServer(), search, replacements);
}

From source file:org.shept.util.FileUtils.java

/**
 * Compare the source path and the destination path for filenames with the filePattern
 * e.g. *.bak, *tmp and copy these files to the destination dir if they are not present at the
 * destination or if they have changed (by modifactionDate)
 * /*  www  .j a  v a 2 s.  c o  m*/
 * @param destPath
 * @param sourcePath
 * @param filePattern
 * @return the number of files being copied
 */
public static Integer syncAdd(String sourcePath, String destPath, String filePattern) {
    // check for new files since the last check which need to be copied
    Integer number = 0;
    SortedMap<FileNameDate, File> destMap = fileMapByNameAndDate(destPath, filePattern);
    SortedMap<FileNameDate, File> sourceMap = fileMapByNameAndDate(sourcePath, filePattern);
    // identify the list of source files different from their destinations
    for (FileNameDate fk : destMap.keySet()) {
        sourceMap.remove(fk);
    }

    // copy the list of files from source to destination
    for (File file : sourceMap.values()) {
        log.debug(file.getName() + ": " + new Date(file.lastModified()));
        File copy = new File(destPath, file.getName());
        try {
            if (!copy.exists()) {
                // copy to tmp file first to avoid clashes during lengthy copy action
                File tmp = File.createTempFile("vrs", ".tmp", copy.getParentFile());
                FileCopyUtils.copy(file, tmp);
                if (!tmp.renameTo(copy)) {
                    tmp.delete(); // cleanup if we fail
                }
                number++;
            }
        } catch (IOException ex) {
            log.error("FileCopy error for file " + file.getName(), ex);
        }
    }
    return number;
}

From source file:com.espertech.esper.core.start.EPStatementStartMethodHelperPrior.java

private static void handlePrior(ViewUpdatedCollection viewUpdatedCollection,
        SortedMap<Integer, List<ExprPriorNode>> callbacksPerIndex,
        Map<ExprPriorNode, ExprPriorEvalStrategy> strategies) {

    // Since an expression such as "prior(2, price), prior(8, price)" translates
    // into {2, 8} the relative index is {0, 1}.
    // Map the expression-supplied index to a relative viewUpdatedCollection-known index via wrapper
    int relativeIndex = 0;
    for (int reqIndex : callbacksPerIndex.keySet()) {
        List<ExprPriorNode> priorNodes = callbacksPerIndex.get(reqIndex);
        for (ExprPriorNode callback : priorNodes) {
            ExprPriorEvalStrategy strategy;
            if (viewUpdatedCollection instanceof RelativeAccessByEventNIndex) {
                RelativeAccessByEventNIndex relativeAccess = (RelativeAccessByEventNIndex) viewUpdatedCollection;
                PriorEventViewRelAccess impl = new PriorEventViewRelAccess(relativeAccess, relativeIndex);
                strategy = new ExprPriorEvalStrategyRelativeAccess(impl);
            } else {
                if (viewUpdatedCollection instanceof RandomAccessByIndex) {
                    strategy = new ExprPriorEvalStrategyRandomAccess(
                            (RandomAccessByIndex) viewUpdatedCollection);
                } else {
                    strategy = new ExprPriorEvalStrategyRelativeAccess(
                            (RelativeAccessByEventNIndex) viewUpdatedCollection);
                }//from   w  ww.ja  v  a2s  . co  m
            }

            strategies.put(callback, strategy);
        }
        relativeIndex++;
    }
}

From source file:com.pinterest.secor.parser.MessageParser.java

public static List[] listFromJsonSorted(org.json.JSONObject json) {
    if (json == null)
        return null;
    SortedMap map = new TreeMap();
    Iterator i = json.keys();/* ww  w.ja  v a2s  . c om*/
    while (i.hasNext()) {
        try {
            String key = i.next().toString();
            //System.out.println(key);
            String j = json.getString(key);
            map.put(key, j);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    LinkedList keys = new LinkedList(map.keySet());
    LinkedList values = new LinkedList(map.values());
    List[] variable = new List[2];
    variable[0] = keys;
    variable[1] = values;
    return variable;
}