Example usage for java.util SortedMap put

List of usage examples for java.util SortedMap put

Introduction

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

Prototype

V put(K key, V value);

Source Link

Document

Associates the specified value with the specified key in this map (optional operation).

Usage

From source file:core.com.qiniu.auth.AWS3Signer.java

protected String getCanonicalizedHeadersForStringToSign(Request<?> request) {
    List<String> headersToSign = getHeadersForStringToSign(request);

    for (int i = 0; i < headersToSign.size(); i++) {
        headersToSign.set(i, StringUtils.lowerCase(headersToSign.get(i)));
    }//from   w  w  w .j  a  va2s .c om

    SortedMap<String, String> sortedHeaderMap = new TreeMap<String, String>();
    for (Map.Entry<String, String> entry : request.getHeaders().entrySet()) {
        if (headersToSign.contains(StringUtils.lowerCase(entry.getKey()))) {
            sortedHeaderMap.put(StringUtils.lowerCase(entry.getKey()), entry.getValue());
        }
    }

    StringBuilder builder = new StringBuilder();
    for (Map.Entry<String, String> entry : sortedHeaderMap.entrySet()) {
        builder.append(StringUtils.lowerCase(entry.getKey())).append(":").append(entry.getValue()).append("\n");
    }

    return builder.toString();
}

From source file:net.proest.librepilot.web.handler.DefinitionHandler.java

public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    response.setCharacterEncoding("utf-8");
    response.setStatus(HttpServletResponse.SC_OK);

    PrintWriter out = response.getWriter();

    List<String> targetObjects = Arrays.asList(target.split("/"));

    SortedMap<String, UAVTalkXMLObject> objects = new TreeMap<>();

    for (UAVTalkXMLObject xmlObj : mFcDevice.getObjectTree().getXmlObjects().values()) {
        if (targetObjects.size() == 0 || targetObjects.contains(xmlObj.getName())) {
            if (mShowSettings && xmlObj.isSettings() || mShowState && !xmlObj.isSettings()) {
                objects.put(xmlObj.getName(), xmlObj);
            }//  w ww .j a  v  a  2  s.  c  o  m
        }
    }

    String callback = request.getParameter("callback");

    if (callback != null) {
        response.setContentType("application/javascript");
        out.println(callback + "(");
    } else {
        response.setContentType("application/json");
    }

    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(SerializationFeature.INDENT_OUTPUT);

    out.println(mapper.writeValueAsString(objects));

    if (callback != null) {
        out.print(")");
    }

    baseRequest.setHandled(true);
}

From source file:com.aurel.track.item.link.ItemLinkBL.java

/**
 * Gets the links from predecessors to itemID as successor
 * @param itemID//from  ww  w  .java 2  s .com
 * @return
 */
static SortedMap<Integer, TWorkItemLinkBean> getPredecessorsForMeAsSuccessorMap(Integer itemID) {
    SortedMap<Integer, TWorkItemLinkBean> itemLinkMap = new TreeMap<Integer, TWorkItemLinkBean>();
    List<TWorkItemLinkBean> linksFromPredecessors = workItemLinkDAO.loadByWorkItemSucc(itemID);
    if (linksFromPredecessors != null) {
        for (TWorkItemLinkBean workItemLinkBean : linksFromPredecessors) {
            itemLinkMap.put(workItemLinkBean.getObjectID(), workItemLinkBean);
        }
    }
    return itemLinkMap;
}

From source file:net.ripe.rpki.commons.crypto.rfc3779.ResourceExtensionParser.java

/**
 * Parses the IP address blocks extension and merges all address families
 * into a single {@link IpResourceSet} containing both IPv4 and IPv6
 * addresses. Maps an {@link AddressFamily} to <code>null</code> when the
 * resource of this type are inherited. If no resources are specified it is
 * mapped to an empty resource set.// w  w  w  . j  a va2  s . c  o  m
 */
public SortedMap<AddressFamily, IpResourceSet> parseIpAddressBlocks(byte[] extension) {
    ASN1Primitive octetString = decode(extension);
    expect(octetString, ASN1OctetString.class);
    ASN1OctetString o = (ASN1OctetString) octetString;
    SortedMap<AddressFamily, IpResourceSet> map = derToIpAddressBlocks(decode(o.getOctets()));

    for (AddressFamily family : SUPPORTED_ADDRESS_FAMILIES) {
        if (!map.containsKey(family)) {
            map.put(family, new IpResourceSet());
        }
    }

    for (AddressFamily addressFamily : map.keySet()) {
        Validate.isTrue(!addressFamily.hasSubsequentAddressFamilyIdentifier(), "SAFI not supported");
    }

    return map;
}

From source file:hudson.maven.ModuleDependency.java

/**
 * Given a list of ModuleDependencies (of the same groupId and artifactId),
 * picks the {@link ModuleDependency} that satisfies the constraint and has the highest version.
 *
 * @param candidates/*from  w w w. j a v  a  2s  .c om*/
 *      List that represents specific (non-range) versions.
 * @return The highest satisfying ModuleDependency or null if none can be found.
 */
public ModuleDependency findHighestFrom(Collection<ModuleDependency> candidates) {
    //Create a sorted map of the ModuleDependnecies sorted on version (descending order).
    SortedMap<ArtifactVersion, ModuleDependency> sorted = new TreeMap<ArtifactVersion, ModuleDependency>(
            new ReverseComparator());
    for (ModuleDependency candidate : candidates) {
        sorted.put(candidate.parseVersion(), candidate);
    }

    //Now find the highest version that satisfies this dependency.
    for (ModuleDependency e : sorted.values()) {
        if (contains(e))
            return e;
    }

    // non found
    return null;
}

From source file:com.octo.mbo.domain.ApproachingMatcher.java

/**
 * Sort the list of keys according to their distance with the reference key
 * @param keysOfSlides List of keys/*from w  w  w .jav a2 s .  c o  m*/
 * @param key A reference key that will be compared to each String
 * @return A map whose index are the distances and values a list of keys for the corresponding distance.
 */
public SortedMap<Integer, Set<String>> sortByDistanceWithKey(Collection<String> keysOfSlides, String key) {
    assert keysOfSlides != null;
    assert key != null;

    SortedMap<Integer, Set<String>> keysSortedByDistance = new TreeMap<>();

    for (String slideKey : keysOfSlides) {
        int distK2k = levenshteinDistance.apply(normalize(key), normalize(slideKey));
        if (keysSortedByDistance.containsKey(distK2k)) {
            keysSortedByDistance.get(distK2k).add(slideKey);
        } else {
            keysSortedByDistance.put(distK2k, new HashSet<>((Collections.singletonList(slideKey))));
        }
    }

    log.trace("Sort by least distance to '{}' after normalization : {}", key, keysSortedByDistance);

    return keysSortedByDistance;
}

From source file:info.gehrels.voting.web.VoteBuilder.java

private Vote<GenderedCandidate> createPreferenceVote(GenderedElection genderedElection) {
    SortedMap<Long, GenderedCandidate> candidatesByPreferences = new TreeMap<>();

    for (int i = 0; (i < genderedElection.getCandidates().size())
            && (i < preferencesByCandidateIdx.size()); i++) {
        PreferenceBuilder preference = preferencesByCandidateIdx.get(i);
        if (preference.getValue() != null) {
            candidatesByPreferences.put(preference.getValue(),
                    genderedElection.getCandidates().asList().get(i));
        }/*from  w ww. ja  va2 s . c  om*/
    }

    return Vote.createPreferenceVote(genderedElection, ImmutableSet.copyOf(candidatesByPreferences.values()));
}

From source file:fr.ribesg.bukkit.ncore.config.UuidDb.java

@Override
protected void handleValues(final YamlConfiguration config) throws InvalidConfigurationException {
    for (final String uuidString : config.getKeys(false)) {
        final UUID id = UUID.fromString(uuidString);
        final ConfigurationSection section = config.getConfigurationSection(uuidString);
        final String lastKnownName = section.getString("lastKnownName");
        final long firstSeen = section.getLong("firstSeen");
        final long lastSeen = section.getLong("lastSeen");
        final ConfigurationSection previousNamesSection = section.getConfigurationSection("previousNames");
        final SortedMap<Long, String> previousNames = new TreeMap<>();
        if (previousNamesSection != null) {
            for (final String previousName : previousNamesSection.getKeys(false)) {
                previousNames.put(previousNamesSection.getLong(previousName), previousName);
            }// w  w  w . j  a  va 2 s  . c  o  m
        }
        final PlayerInfo info = new PlayerInfo(id, lastKnownName, previousNames, firstSeen, lastSeen);
        this.byUuid.put(id, info);
        if (lastKnownName != null) {
            this.byName.put(lastKnownName.toLowerCase(), info);
        }
    }
}

From source file:lti.oauth.OAuthMessageSigner.java

/**
 * This method double encodes the parameter keys and values.
 * Thus, it expects the keys and values contained in the 'parameters' SortedMap
 * NOT to be encoded.//from   w w w . j ava 2s .  c  o  m
 * This method also generates oauth_body_hash parameter and adds it to 
 * 'parameters' SortedMap
 * 
 * @param secret
 * @param algorithm
 * @param method
 * @param url
 * @param parameters
 * @param requestBody
 * @return oauth signature
 * @throws Exception
 */
public String signWithBodyHash(String secret, String algorithm, String method, String url,
        SortedMap<String, String> parameters, String requestBody) throws Exception {

    byte[] bytes = requestBody.getBytes();

    MessageDigest sha = MessageDigest.getInstance("SHA-1");
    sha.reset();
    sha.update(bytes);
    byte[] encodedRequestBytes = Base64.encodeBase64(sha.digest());

    String oauthBodyHash = new String(encodedRequestBytes);

    parameters.put(OAuthUtil.OAUTH_POST_BODY_PARAMETER, oauthBodyHash);

    return sign(secret, algorithm, method, url, parameters);
}

From source file:com.haulmont.cuba.web.sys.WebJarResourceResolver.java

protected SortedMap<String, String> filterPathIndexByPrefix(SortedMap<String, String> pathIndex,
        String prefix) {/*w w  w  .j  a v  a2  s . c om*/
    SortedMap<String, String> filteredPathIndex = new TreeMap<>();
    for (String key : pathIndex.keySet()) {
        String value = pathIndex.get(key);
        if (value.startsWith(prefix)) {
            filteredPathIndex.put(key, value);
        }
    }
    return filteredPathIndex;
}