Example usage for java.util TreeMap keySet

List of usage examples for java.util TreeMap keySet

Introduction

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

Prototype

public Set<K> keySet() 

Source Link

Document

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

Usage

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   www  .  j  a  v a 2s  .  c  o  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.ebay.erl.mobius.core.model.TupleColumnComparator.java

private static int compare(TreeMap<String, String> m1, TreeMap<String, String> m2) {
    int _COMPARE_RESULT = Integer.MAX_VALUE;

    int m1_size = m1.size();
    int m2_size = m2.size();

    if (m1_size == 0 || m2_size == 0) {
        if (m1_size == m2_size)
            return 0;
        else if (m1_size != 0)
            return 1;
        else/*from   w ww. j a  va  2 s .  co m*/
            return -1;
    }

    Iterator<String> k1_it = m1.keySet().iterator();
    Iterator<String> k2_it = m2.keySet().iterator();

    boolean hasDiff = false;

    while (k1_it.hasNext()) {
        String k1 = k1_it.next();

        if (k2_it.hasNext()) {
            String k2 = k2_it.next();

            _COMPARE_RESULT = String.CASE_INSENSITIVE_ORDER.compare(k1, k2);
            if (_COMPARE_RESULT == 0) {
                // same key, check their value
                String v1 = m1.get(k1);
                String v2 = m2.get(k2);

                _COMPARE_RESULT = v1.compareTo(v2);
            }
        } else {
            // m1 has more keys than m2 and m1 has the same
            // values for all the keys in m2
            _COMPARE_RESULT = 1;
        }

        if (_COMPARE_RESULT != 0 && _COMPARE_RESULT != Integer.MAX_VALUE) {
            hasDiff = true;
            break;// has result
        }
    }

    if (!hasDiff) {
        if (k2_it.hasNext()) {
            // m2 has more keys than m1, and m2 has the same
            // values for all the keys in m1
            _COMPARE_RESULT = -1;
        } else {
            // m1 and m2 are the same

        }
    }

    return _COMPARE_RESULT;
}

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 .c o m

    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:br.ufrgs.inf.dsmoura.repository.model.loadData.LoadLists.java

@SuppressWarnings("unused")
private static void loadDomainAndSubdomain() {
    //      TreeMap<String, ArrayList<String>> domains = readFileCcs98();
    //      TreeMap<String, ArrayList<String>> domains = readFileDomains();
    TreeMap<String, ArrayList<String>> domains = getAllDomainsAndSubDomains();

    for (String key : domains.keySet()) {
        ApplicationDomain ad = new ApplicationDomain();
        ad.setName(key);/*from  w  w w.j a  v  a 2s . co  m*/
        ad = (ApplicationDomain) GenericDAO.getInstance().insert(ad);
        logger.info("ApplicationDomain inserted: " + key);

        ArrayList<String> subdomains = domains.get(key);
        Collections.sort(subdomains);
        for (String s : subdomains) {
            ApplicationSubdomain as = new ApplicationSubdomain();
            as.setName(s);
            as.setApplicationDomain(ad);
            GenericDAO.getInstance().insert(as);
            logger.info("ApplicationSubdomain inserted: " + s);
        }
    }
}

From source file:net.triptech.metahive.KeyValueIdentifier.java

/**
 * Calculate the key value by concatenating the values.
 *
 * @param values the values/*from   w w w  .j  av  a 2s .c  o m*/
 * @return the object
 */
public static Object concat(final List<Object> values) {

    Object keyValue = null;

    TreeMap<String, Integer> valueSet = new TreeMap<String, Integer>();

    for (Object value : values) {
        if (value instanceof String) {
            valueSet.put((String) value, 0);
        }
    }

    if (valueSet.size() > 0) {
        StringBuilder sb = new StringBuilder();

        int count = valueSet.keySet().size();
        int counter = 1;

        for (String item : valueSet.keySet()) {
            if (sb.length() > 0) {
                if (counter == count) {
                    sb.append(" and ");
                } else {
                    sb.append(", ");
                }
            }
            sb.append(item);
            counter++;
        }
        keyValue = sb.toString();
    }

    return keyValue;
}

From source file:com.sangupta.jerry.oauth.OAuthUtils.java

/**
 * Generate a sorted parameter string for the given parameters. All
 * parameters are appended into a string form.
 * /*from  w  w  w.ja va  2  s .c  o  m*/
 * @param params
 *            the request parameters that need to be appended
 * 
 * @param encodeParamValues
 *            whether to URL encode the parameters or not
 * 
 * @return the URL query string representation of all parameters
 */
public static String generateParamString(TreeMap<String, String> params, boolean encodeParamValues) {
    if (AssertUtils.isEmpty(params)) {
        return StringUtils.EMPTY_STRING;
    }

    StringBuilder builder = new StringBuilder();
    boolean first = true;

    for (String key : params.keySet()) {
        if (first) {
            first = false;
        } else {
            builder.append('&');
        }

        builder.append(key);
        builder.append("=");
        if (encodeParamValues) {
            builder.append(UriUtils.encodeURIComponent(params.get(key), true));
        } else {
            builder.append(params.get(key));
        }
    }

    return builder.toString();
}

From source file:org.etudes.util.HtmlHelper.java

/**
 * Make the elements in alpha order, no internal spacing, all ; terminated
 * //from   ww  w.jav a2s .c o  m
 * @param value
 * @return
 */
public static String canonicalStyleAttribute(String value) {
    // break on ";"
    String[] parts = StringUtil.split(value, ";");

    // collect style and value elements for alpha rendering
    TreeMap<String, String> elements = new TreeMap<String, String>();
    for (String part : parts) {
        // break on first ":"
        String[] lr = StringUtil.split(part, ":");

        if (lr.length == 2) {
            elements.put(lr[0].trim(), lr[1].trim());
        }
    }

    // reform the value
    StringBuilder newValue = new StringBuilder();
    for (String key : elements.keySet()) {
        String setting = elements.get(key);
        newValue.append(key);
        newValue.append(":");
        newValue.append(setting);
        newValue.append(";");
    }

    return newValue.toString();
}

From source file:org.waarp.gateway.kernel.rest.RestArgument.java

/**
 * @param hmacSha256//from w  ww.  j  av  a2s .  c o  m
 *            SHA-256 key to create the signature
 * @param extraKey
 *            might be null
 * @param treeMap
 * @param argPath
 * @throws HttpInvalidAuthenticationException
 */
protected static String computeKey(HmacSha256 hmacSha256, String extraKey, TreeMap<String, String> treeMap,
        String argPath) throws HttpInvalidAuthenticationException {
    Set<String> keys = treeMap.keySet();
    StringBuilder builder = new StringBuilder(argPath);
    if (!keys.isEmpty() || extraKey != null) {
        builder.append('?');
    }
    boolean first = true;
    for (String keylower : keys) {
        if (first) {
            first = false;
        } else {
            builder.append('&');
        }
        builder.append(keylower).append('=').append(treeMap.get(keylower));
    }
    if (extraKey != null) {
        if (!keys.isEmpty()) {
            builder.append("&");
        }
        builder.append(REST_ROOT_FIELD.ARG_X_AUTH_INTERNALKEY.field).append("=").append(extraKey);
    }
    try {
        return hmacSha256.cryptToHex(builder.toString());
    } catch (Exception e) {
        throw new HttpInvalidAuthenticationException(e);
    }
}

From source file:script.candidate.CandidateIOTest.java

@org.junit.Test
public void testMapper() {
    Map<Integer, String> map = new HashMap<>();
    map.put(2, "/home/ryoji/ssm/sql-script-manager/dummy_file_system/sqlscripts/2016/Dec/01_12_2016.sql");
    map.put(1, "/home/ryoji/ssm/sql-script-manager/dummy_file_system/sqlscripts/2016/Dec/01_12_2016.sql");
    CandidateIO.saveCandidates(map);//ww w  .j a  v a  2s .  com
    TreeMap<Integer, String> candidate = CandidateIO.readCandidate();
    System.out.print(candidate.keySet());
    Assert.assertTrue(ArrayUtils.contains(candidate.keySet().toArray(), 2));
}

From source file:com.genentech.application.calcProps.SDFCalcProps.java

private static void printProperties(Set<Calculator> calculators, boolean showHidden) {
    //Print properties by alphabetical order
    TreeMap<String, String> sortedCalcs = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
    for (Calculator calc : calculators) {
        if (calc.isPublic()) {
            sortedCalcs.put(calc.getName(), calc.getHelpText());
        } else if (showHidden == true) {//print non public props as well
            sortedCalcs.put(calc.getName(), calc.getHelpText());
        }/*from  w  w  w . j ava  2  s.c om*/
    }

    for (String key : sortedCalcs.keySet()) {
        System.err.println(key + ":\t" + sortedCalcs.get(key));
    }
}