Example usage for java.util TreeMap put

List of usage examples for java.util TreeMap put

Introduction

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

Prototype

public V put(K key, V value) 

Source Link

Document

Associates the specified value with the specified key in this map.

Usage

From source file:com.boyuanitsm.pay.unionpay.util.SDKUtil.java

/**
 * Map???Keyascii???key1=value1&key2=value2? ????signature
 * //w  w  w . ja  v a  2s . c  o  m
 * @param data
 *            Map?
 * @return ?
 */
public static String coverMap2String(Map<String, String> data) {
    TreeMap<String, String> tree = new TreeMap<String, String>();
    Iterator<Entry<String, String>> it = data.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, String> en = it.next();
        if (SDKConstants.param_signature.equals(en.getKey().trim())) {
            continue;
        }
        tree.put(en.getKey(), en.getValue());
    }
    it = tree.entrySet().iterator();
    StringBuffer sf = new StringBuffer();
    while (it.hasNext()) {
        Entry<String, String> en = it.next();
        sf.append(en.getKey() + SDKConstants.EQUAL + en.getValue() + SDKConstants.AMPERSAND);
    }
    if (sf.length() == 0) {
        return "";
    }
    return sf.substring(0, sf.length() - 1);
}

From source file:com.liangc.hq.base.utils.MonitorUtils.java

public static List findServerTypes(List servers) {
    TreeMap serverTypeSet = new TreeMap();
    for (Iterator i = servers.iterator(); i.hasNext();) {
        ServerValue thisAppSvc = (ServerValue) i.next();
        if (thisAppSvc != null && thisAppSvc.getServerType() != null) {
            ServerTypeValue svcType = thisAppSvc.getServerType();
            serverTypeSet.put(svcType.getName(), svcType);
        }/*w w  w.j a v  a 2  s  . c o  m*/
    }
    return new ArrayList(serverTypeSet.values());
}

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

/**
 * Fetches users bookmarks/*w w w  .  j  av  a  2  s . c  o m*/
 * 
 * @param account The account being synced.
 * @param authtoken The authtoken stored in the AccountManager for the
 *        account
 * @return list The list of bookmarks received from the server.
 * @throws AuthenticationException 
 */
public static ArrayList<Citation> getBookmark(ArrayList<String> hashes, Account account, Context context)
        throws IOException, AuthenticationException {

    ArrayList<Citation> bookmarkList = new ArrayList<Citation>();
    TreeMap<String, String> params = new TreeMap<String, String>();
    String hashString = "";
    String response = null;
    String url = FETCH_BOOKMARK_URI;

    for (String h : hashes) {
        if (hashes.get(0) != h) {
            hashString += "+";
        }
        hashString += h;
    }
    params.put("meta", "yes");
    params.put("hashes", hashString);

    response = ZoteroApiCall(url, params, account, context);

    if (response.contains("<?xml")) {
        bookmarkList = Citation.valueOf(response);
    } else {
        Log.e(TAG, "Server error in fetching bookmark list");
        throw new IOException();
    }
    return bookmarkList;
}

From source file:com.act.lcms.db.model.StandardIonResult.java

private static LinkedHashMap<String, XZ> deserializeStandardIonAnalysisResult(String jsonEntry)
        throws IOException {
    // We have to re-sorted the deserialized results so that we meet the contract expected by the caller.
    Map<String, XZ> deserializedResult = OBJECT_MAPPER.readValue(jsonEntry, typeRefForStandardIonAnalysis);
    TreeMap<Double, String> sortedIntensityToIon = new TreeMap<>(Collections.reverseOrder());

    for (Map.Entry<String, XZ> val : deserializedResult.entrySet()) {
        sortedIntensityToIon.put(val.getValue().getIntensity(), val.getKey());
    }//from   www. ja  v a  2 s. c om

    LinkedHashMap<String, XZ> sortedResult = new LinkedHashMap<>();
    for (Map.Entry<Double, String> val : sortedIntensityToIon.entrySet()) {
        String ion = val.getValue();
        sortedResult.put(ion, deserializedResult.get(ion));
    }

    return sortedResult;
}

From source file:com.deliciousdroid.client.DeliciousApi.java

/**
 * Retrieves a list of suggested tags for a URL.
 * /*from  w ww . java2 s .  com*/
 * @param suggestUrl The URL to get suggested tags for.
 * @param account The account being synced.
 * @param context The current application context.
 * @return A list of tags suggested for the provided url.
 * @throws IOException If a server error was encountered.
 * @throws AuthenticationException If an authentication error was encountered.
 */
public static ArrayList<Tag> getSuggestedTags(String suggestUrl, Account account, Context context)
        throws IOException, AuthenticationException, TooManyRequestsException {

    ArrayList<Tag> tagList = new ArrayList<Tag>();

    if (!suggestUrl.startsWith("http")) {
        suggestUrl = "http://" + suggestUrl;
    }

    InputStream responseStream = null;
    TreeMap<String, String> params = new TreeMap<String, String>();
    params.put("url", suggestUrl);

    String url = FETCH_SUGGESTED_TAGS_URI;

    responseStream = DeliciousApiCall(url, params, account, context);
    SaxTagParser parser = new SaxTagParser(responseStream);

    try {
        tagList = parser.parseSuggested();
    } catch (ParseException e) {
        Log.e(TAG, "Server error in fetching bookmark list");
        throw new IOException();
    }

    responseStream.close();
    return tagList;
}

From source file:com.deliciousdroid.client.DeliciousApi.java

/**
 * Sends a request to Delicious's Add Bookmark api.
 * //from   w w w  .j a  v  a2 s.  c  om
 * @param bookmark The bookmark to be added.
 * @param account The account being synced.
 * @param context The current application context.
 * @return A boolean indicating whether or not the api call was successful.
 * @throws IOException If a server error was encountered.
 * @throws AuthenticationException If an authentication error was encountered.
 * @throws TokenRejectedException If the oauth token is reported to be expired.
 * @throws Exception If an unknown error is encountered.
 */
public static Boolean addBookmark(Bookmark bookmark, Account account, Context context)
        throws IOException, AuthenticationException, TooManyRequestsException {

    String url = bookmark.getUrl();
    if (url.endsWith("/")) {
        url = url.substring(0, url.lastIndexOf('/'));
    }

    TreeMap<String, String> params = new TreeMap<String, String>();

    params.put("description", bookmark.getDescription());
    params.put("extended", bookmark.getNotes());

    // until delicious fixes their api we need to use commas to delimit tags
    // tags with spaces, although supported by the web interface, will not work with deliciousdroid
    params.put("tags", bookmark.getTagString().replace(' ', ','));
    params.put("url", bookmark.getUrl());
    params.put("replace", "yes");

    if (bookmark.getShared()) {
        params.put("shared", "yes");
    } else
        params.put("shared", "no");

    String uri = ADD_BOOKMARKS_URI;
    String response = null;
    InputStream responseStream = null;

    responseStream = DeliciousApiCall(uri, params, account, context);
    response = convertStreamToString(responseStream);
    responseStream.close();

    if (response.contains("<result code=\"done\"/>")) {
        return true;
    } else {
        Log.e(TAG, "Server error in adding bookmark");
        throw new IOException();
    }
}

From source file:com.deliciousdroid.client.DeliciousApi.java

/**
 * Retrieves a list of all bookmarks, with only their URL hash and a change (meta) hash,
 * to determine what bookmarks have changed since the last update.
 * //from w w w .j  a  v a2s .co  m
 * @param account The account being synced.
 * @param context The current application context.
 * @return A list of bookmarks received from the server with only the URL hash and meta hash.
 * @throws IOException If a server error was encountered.
 * @throws AuthenticationException If an authentication error was encountered.
 */
public static ArrayList<Bookmark> getChangedBookmarks(Account account, Context context)
        throws IOException, AuthenticationException {

    ArrayList<Bookmark> bookmarkList = new ArrayList<Bookmark>();
    InputStream responseStream = null;
    TreeMap<String, String> params = new TreeMap<String, String>();
    String url = FETCH_CHANGED_BOOKMARKS_URI;

    params.put("hashes", "yes");

    responseStream = DeliciousApiCall(url, params, account, context);
    SaxBookmarkParser parser = new SaxBookmarkParser(responseStream);

    try {
        bookmarkList = parser.parse();
    } catch (ParseException e) {
        Log.e(TAG, "Server error in fetching bookmark list");
        throw new IOException();
    }

    responseStream.close();
    return bookmarkList;
}

From source file:com.jrummyapps.busybox.signing.ZipSigner.java

/** Add the SHA1 of every file to the manifest, creating it if necessary. */
private static Manifest addDigestsToManifest(final JarFile jar) throws IOException, GeneralSecurityException {
    final Manifest input = jar.getManifest();
    final Manifest output = new Manifest();

    final Attributes main = output.getMainAttributes();
    main.putValue("Manifest-Version", MANIFEST_VERSION);
    main.putValue("Created-By", CREATED_BY);

    // We sort the input entries by name, and add them to the output manifest in sorted order.
    // We expect that the output map will be deterministic.
    final TreeMap<String, JarEntry> byName = new TreeMap<>();
    for (Enumeration<JarEntry> e = jar.entries(); e.hasMoreElements();) {
        JarEntry entry = e.nextElement();
        byName.put(entry.getName(), entry);
    }/*  w  w  w .ja v  a  2 s.c o  m*/

    final MessageDigest md = MessageDigest.getInstance("SHA1");
    final byte[] buffer = new byte[4096];
    int num;

    for (JarEntry entry : byName.values()) {
        final String name = entry.getName();
        if (!entry.isDirectory() && !name.equals(JarFile.MANIFEST_NAME) && !name.equals(CERT_SF_NAME)
                && !name.equals(CERT_RSA_NAME)) {
            InputStream data = jar.getInputStream(entry);
            while ((num = data.read(buffer)) > 0) {
                md.update(buffer, 0, num);
            }

            Attributes attr = null;
            if (input != null) {
                attr = input.getAttributes(name);
            }
            attr = attr != null ? new Attributes(attr) : new Attributes();
            attr.putValue("SHA1-Digest", base64encode(md.digest()));
            output.getEntries().put(name, attr);
        }
    }

    return output;
}

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

@Deprecated
private static Thing parseOld(JsonNode td) throws IOException {
    try {/*  w ww. j  a  v  a 2  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.pindroid.client.PinboardApi.java

/**
 * Retrieves a list of suggested tags for a URL.
 * /*from w w w. j a  va  2s.c  om*/
 * @param suggestUrl The URL to get suggested tags for.
 * @param account The account being synced.
 * @param context The current application context.
 * @return A list of tags suggested for the provided url.
 * @throws IOException If a server error was encountered.
 * @throws AuthenticationException If an authentication error was encountered.
 * @throws TooManyRequestsException 
 * @throws PinboardException 
 */
public static ArrayList<Tag> getSuggestedTags(String suggestUrl, Account account, Context context)
        throws IOException, AuthenticationException, TooManyRequestsException, PinboardException {

    ArrayList<Tag> tagList = new ArrayList<Tag>();

    if (!suggestUrl.startsWith("http")) {
        suggestUrl = "http://" + suggestUrl;
    }

    InputStream responseStream = null;
    TreeMap<String, String> params = new TreeMap<String, String>();
    params.put("url", suggestUrl);

    String url = FETCH_SUGGESTED_TAGS_URI;

    responseStream = PinboardApiCall(url, params, account, context);
    SaxTagParser parser = new SaxTagParser(responseStream);

    try {
        tagList = parser.parseSuggested();
    } catch (ParseException e) {
        Log.e(TAG, "Server error in fetching bookmark list");
        throw new IOException();
    }

    responseStream.close();
    return tagList;
}