Example usage for java.util TreeMap get

List of usage examples for java.util TreeMap get

Introduction

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

Prototype

public V get(Object key) 

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:com.core.util.wx.PayUtils.java

/**
 * ?????//w  w  w . j a  v a 2  s.com
 */
public static String formatBizQueryParaMap(Map<String, String> paraMap, boolean urlencode) {
    StringBuilder sb = new StringBuilder();
    TreeMap<String, String> sortMap = new TreeMap<String, String>(paraMap);
    if (urlencode) {
        try {
            for (String key : sortMap.keySet()) {
                sb.append(key).append("=").append(URLEncoder.encode(sortMap.get(key), "UTF-8")).append("&");
            }
        } catch (UnsupportedEncodingException e) {
            LOG.error(e.getMessage(), e);
        }
    } else {
        for (String key : sortMap.keySet()) {
            sb.append(key).append("=").append(sortMap.get(key)).append("&");
        }
    }

    if (sb.length() > 0) {
        sb.deleteCharAt(sb.length() - 1);
    }
    return sb.toString();
}

From source file:dk.statsbiblioteket.doms.licensemodule.validation.LicenseValidator.java

public static ArrayList<UserGroupDTO> filterGroupsWithPresentationtype(ArrayList<License> licenses) {
    TreeMap<String, UserGroupDTO> groups = new TreeMap<String, UserGroupDTO>();
    for (License currentLicense : licenses) {
        for (LicenseContent currentGroup : currentLicense.getLicenseContents()) {
            String name = currentGroup.getName();
            UserGroupDTO group = groups.get(name);
            if (group == null) {
                group = new UserGroupDTO();
                group.setPresentationTypes(new ArrayList<String>());
                group.setGroupName(name);
                groups.put(name, group);
            }//ww  w .  j a va2s .  c om
            for (Presentation currentPresentation : currentGroup.getPresentations()) {
                String presentation_key = currentPresentation.getKey();
                if (group.getPresentationTypes().contains(presentation_key)) {
                    //Already added
                } else {
                    group.getPresentationTypes().add(presentation_key);
                }
            }
        }
    }
    return new ArrayList<UserGroupDTO>(groups.values());
}

From source file:spec.reporter.Utils.java

public static void generateMainChart(double compositeScore, TreeMap<String, Double> scores) {

    // Valid benchmarks + room for all possible extra - compiler, crypto, scimark, scimark.small, scimark.large, startup, xml, composite score
    Color[] colors = new Color[scores.size() + 8];

    // create the dataset...
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    int count = 0;

    Iterator<String> iteratorBenchmarks = scores.keySet().iterator();
    while (iteratorBenchmarks.hasNext()) {
        String key = iteratorBenchmarks.next();
        Double score = scores.get(key);
        if (Utils.isValidScore(score)) {
            dataset.addValue(score, key, key);
            colors[count++] = (Color) colorMap.get(key);
        }/*www  .  ja  v a  2  s  .  co  m*/
    }

    if (Utils.isValidScore(compositeScore)) {
        dataset.addValue(compositeScore, Utils.CSCORE_NAME, Utils.CSCORE_NAME);
        colors[count++] = (Color) colorMap.get(Utils.CSCORE_NAME);
    }

    JFreeChart chart = ChartFactory.createStackedBarChart("Scores", // chart title
            "", // domain axis label
            "", dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            false, // include legend
            false, // tooltips?
            false // URLs?
    );

    CategoryItemRenderer renderer = chart.getCategoryPlot().getRendererForDataset(dataset);
    for (int i = 0; i < count; i++) {
        Color paint = (Color) colors[i];
        if (paint != null) {
            renderer.setSeriesPaint(i, paint);
        }
    }

    try {
        ChartUtilities.saveChartAsJPEG(new File(getFullImageName("all")), chart, 600,
                50 + (dataset.getRowCount()) * 20);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.apache.hadoop.hive.ql.exec.ToolBox.java

@Deprecated
static ArrayList<TreeMap<String, String>> aggregateKey_string(TreeMap<String, String> para, String delimiter,
        int idx) {
    ArrayList<TreeMap<String, String>> a = new ArrayList<TreeMap<String, String>>();
    String prekey = null;/*  ww  w .  ja v  a  2s. c  o  m*/
    TreeMap<String, String> h = null;
    for (String s : para.keySet()) {
        if (prekey == null) {
            prekey = retrieveComponent(s, delimiter, idx);
            h = new TreeMap<String, String>();
            h.put(s, para.get(s));
        } else if (prekey.equals(s)) {
            h.put(s, para.get(s));
        } else {
            prekey = retrieveComponent(s, delimiter, idx);
            ;
            a.add(h);
            h = new TreeMap<String, String>();
            h.put(s, para.get(s));
        }

    }
    a.add(h);
    return a;
}

From source file:org.apache.hadoop.hive.ql.exec.ToolBox.java

@Deprecated
static ArrayList<TreeMap<String, Integer>> aggregateKey_Integer(TreeMap<String, Integer> para, String delimiter,
        int idx) {
    ArrayList<TreeMap<String, Integer>> a = new ArrayList<TreeMap<String, Integer>>();
    String prekey = null;//from ww  w  . ja  v  a 2  s.  c  o  m
    TreeMap<String, Integer> h = null;
    for (String s : para.keySet()) {
        if (prekey == null) {
            prekey = retrieveComponent(s, delimiter, idx);
            h = new TreeMap<String, Integer>();
            h.put(s, para.get(s));
        } else if (prekey.equals(s)) {
            h.put(s, para.get(s));
        } else {
            prekey = retrieveComponent(s, delimiter, idx);
            ;
            a.add(h);
            h = new TreeMap<String, Integer>();
            h.put(s, para.get(s));
        }

    }
    a.add(h);
    return a;
}

From source file:module.entities.NameFinder.DB.java

public static void insertJsonResponse(int curConsId, TreeMap<Integer, String> input) throws SQLException {
    try {//from   w  w w .  j  av  a 2  s.c  o m
        String insertSQL = "INSERT INTO enhancedentities " + "(consultation_id,article_id,json_text) VALUES"
                + "(?,?,?);";
        PreparedStatement prepStatement = connection.prepareStatement(insertSQL);
        //            connection.setAutoCommit(false);
        for (int curArticle : input.keySet()) {
            String json_text = input.get(curArticle);
            prepStatement.setInt(1, curConsId);
            prepStatement.setInt(2, curArticle);
            prepStatement.setString(3, json_text);
            //                prepStatement.executeUpdate();
            prepStatement.addBatch();
        }
        prepStatement.executeBatch();
        //            connection.commit();
        prepStatement.close();

        //            for (int i = 0; i<x.length; i++){
        //                System.out.println(x[i]);
        //            }
    } catch (BatchUpdateException ex) {
        ex.printStackTrace();
        //            System.out.println(ex.getNextException());
    }
}

From source file:de.thingweb.desc.ThingDescriptionParser.java

@Deprecated
private static Thing parseOld(JsonNode td) throws IOException {
    try {//from  w w w .  j a  v  a2  s. co m
        Thing thing = new Thing(td.get("metadata").get("name").asText());

        Iterator<String> tdIterator = td.fieldNames();
        while (tdIterator.hasNext()) {
            switch (tdIterator.next()) {
            case "metadata":
                Iterator<String> metaIterator = td.get("metadata").fieldNames();
                while (metaIterator.hasNext()) {
                    switch (metaIterator.next()) {
                    case "encodings":
                        for (JsonNode encoding : td.get("metadata").get("encodings")) {
                            thing.getMetadata().add("encodings", encoding);
                        }
                        break;

                    case "protocols":
                        TreeMap<Long, String> orderedURIs = new TreeMap<>();
                        for (JsonNode protocol : td.get("metadata").get("protocols")) {
                            orderedURIs.put(protocol.get("priority").asLong(), protocol.get("uri").asText());
                        }
                        if (orderedURIs.size() == 1) {
                            thing.getMetadata().add("uris", factory.textNode(orderedURIs.get(0)));
                        } else {
                            ArrayNode an = factory.arrayNode();
                            for (String uri : orderedURIs.values()) {
                                // values returned in ascending order
                                an.add(uri);
                            }
                            thing.getMetadata().add("uris", an);
                        }

                        break;
                    }
                }
                break;

            case "interactions":
                for (JsonNode inter : td.get("interactions")) {
                    if (inter.get("@type").asText().equals("Property")) {
                        Property.Builder builder = Property.getBuilder(inter.get("name").asText());
                        Iterator<String> propIterator = inter.fieldNames();
                        while (propIterator.hasNext()) {
                            switch (propIterator.next()) {
                            case "outputData":
                                builder.setValueType(inter.get("outputData"));
                                break;
                            case "writable":
                                builder.setWriteable(inter.get("writable").asBoolean());
                                break;
                            }
                        }
                        thing.addProperty(builder.build());
                    } else if (inter.get("@type").asText().equals("Action")) {
                        Action.Builder builder = Action.getBuilder(inter.get("name").asText());
                        Iterator<String> actionIterator = inter.fieldNames();
                        while (actionIterator.hasNext()) {
                            switch (actionIterator.next()) {
                            case "inputData":
                                builder.setInputType(inter.get("inputData").asText());
                                break;
                            case "outputData":
                                builder.setOutputType(inter.get("outputData").asText());
                                break;
                            }
                        }
                        thing.addAction(builder.build());
                    } else if (inter.get("@type").asText().equals("Event")) {
                        Event.Builder builder = Event.getBuilder(inter.get("name").asText());
                        Iterator<String> actionIterator = inter.fieldNames();
                        while (actionIterator.hasNext()) {
                            switch (actionIterator.next()) {
                            case "outputData":
                                builder.setValueType(inter.get("outputData"));
                                break;
                            }
                        }
                        thing.addEvent(builder.build());
                    }
                }
                break;
            }
        }

        return thing;
    } catch (Exception e) { // anything could happen here
        throw new IOException("unable to parse Thing Description");
    }
}

From source file:com.zoterodroid.client.ZoteroApi.java

private static String ZoteroApiCall(String url, TreeMap<String, String> params, Account account,
        Context context) throws IOException, AuthenticationException {

    String username = account.name;
    String authtoken = null;//from ww  w. jav a  2s  .  co m
    String scheme = null;

    AuthToken at = new AuthToken(context, account);
    authtoken = at.getAuthToken();

    scheme = SCHEME;

    HttpResponse resp = null;
    HttpGet post = null;

    Uri.Builder builder = new Uri.Builder();
    builder.scheme(scheme);
    builder.authority(ZOTERO_AUTHORITY);
    builder.appendEncodedPath(url);
    for (String key : params.keySet()) {
        builder.appendQueryParameter(key, params.get(key));
    }

    Log.d("apiCallUrl", builder.build().toString());
    post = new HttpGet(builder.build().toString());

    maybeCreateHttpClient();
    post.setHeader("User-Agent", "ZoteroDroid");

    CredentialsProvider provider = mHttpClient.getCredentialsProvider();
    Credentials credentials = new UsernamePasswordCredentials(username, authtoken);
    provider.setCredentials(SCOPE, credentials);

    resp = mHttpClient.execute(post);

    if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
        return EntityUtils.toString(resp.getEntity());
    } else if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
        throw new AuthenticationException();
    } else {
        throw new IOException();
    }
}

From source file:com.linkedin.helix.TestHelper.java

public static void printCache(Map<String, ZNode> cache) {
    System.out.println("START:Print cache");
    TreeMap<String, ZNode> map = new TreeMap<String, ZNode>();
    map.putAll(cache);//w w w.j  a v  a  2s. com

    for (String key : map.keySet()) {
        ZNode node = map.get(key);
        TreeSet<String> childSet = new TreeSet<String>();
        childSet.addAll(node.getChildSet());
        System.out.print(key + "=" + node.getData() + ", " + childSet + ", "
                + (node.getStat() == null ? "null\n" : node.getStat()));
    }
    System.out.println("END:Print cache");
}

From source file:gsn.storage.SQLUtils.java

/**
 * Table renaming, note that the renameMapping should be a tree map. This
 * method gets a sql query and changes the table names using the mappings
 * provided in the second argument.<br>
 * //  w ww  .j a  v  a 2s.  c  o m
 * @param query
 * @param renameMapping
 * @return
 */
public static StringBuilder newRewrite(CharSequence query, TreeMap<CharSequence, CharSequence> renameMapping) {
    // Selecting strings between pair of "" : (\"[^\"]*\")
    // Selecting tableID.tableName or tableID.* : (\\w+(\\.(\w+)|\\*))
    // The combined pattern is : (\"[^\"]*\")|(\\w+\\.((\\w+)|\\*))
    Pattern pattern = Pattern.compile("(\"[^\"]*\")|((\\w+)(\\.((\\w+)|\\*)))", Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(query);
    StringBuffer result = new StringBuffer();
    if (!(renameMapping.comparator() instanceof CaseInsensitiveComparator))
        throw new RuntimeException("Query rename needs case insensitive treemap.");
    while (matcher.find()) {
        if (matcher.group(2) == null)
            continue;
        String tableName = matcher.group(3);
        CharSequence replacement = renameMapping.get(tableName);
        // $4 means that the 4th group of the match should be appended to the
        // string (the forth group contains the field name).
        if (replacement != null)
            matcher.appendReplacement(result, new StringBuilder(replacement).append("$4").toString());
    }
    String toReturn = matcher.appendTail(result).toString().toLowerCase();

    //TODO " from " has to use regular expressions because now from is separated through space which is not always the case, for instance if the user uses \t(tab) for separating "from" from the rest of the query, then we get exception. The same issue with other sql keywords in this method.

    int indexOfFrom = toReturn.indexOf(" from ") >= 0 ? toReturn.indexOf(" from ") + " from ".length() : 0;
    int indexOfWhere = (toReturn.lastIndexOf(" where ") > 0 ? (toReturn.lastIndexOf(" where "))
            : toReturn.length());
    String selection = toReturn.substring(indexOfFrom, indexOfWhere);
    Pattern fromClausePattern = Pattern.compile("\\s*(\\w+)\\s*", Pattern.CASE_INSENSITIVE);
    Matcher fromClauseMather = fromClausePattern.matcher(selection);
    result = new StringBuffer();
    while (fromClauseMather.find()) {
        if (fromClauseMather.group(1) == null)
            continue;
        String tableName = fromClauseMather.group(1);
        CharSequence replacement = renameMapping.get(tableName);
        if (replacement != null)
            fromClauseMather.appendReplacement(result, replacement.toString() + " ");
    }
    String cleanFromClause = fromClauseMather.appendTail(result).toString();
    String finalResult = StringUtils.replace(toReturn, selection, cleanFromClause);
    return new StringBuilder(finalResult);
}