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:org.sakuli.services.forwarder.gearman.model.builder.NagiosCheckResultBuilder.java

@Override
public NagiosCheckResult build() {
    extractData(testSuite, gearmanProperties);
    NagiosCheckResult result = new NagiosCheckResult(queueName, uuid);
    SortedMap<PayLoadFields, String> payload = new TreeMap<>();
    payload.put(TYPE, type);
    //host name from properties file can overrides the determined of the suite
    if (hostProperties != null) {
        payload.put(HOST, hostProperties);
    } else {// w ww  . j a  va2  s .  com
        payload.put(HOST, hostSuite);
    }
    payload.put(START_TIME, startTime);
    payload.put(FINISH_TIME, finishTime);
    payload.put(RETURN_CODE, returnCode);
    payload.put(SERVICE_DESC, serviceDesc);
    payload.put(OUTPUT, output.getOutputString());
    result.setPayload(payload);
    return result;
}

From source file:jhttpp2.Jhttpp2Launcher.java

public Jhttpp2Launcher() {
    server = new Jhttpp2Server(true);
    server.setServerProperties(loadServerProperties());
    restoreSettings();//from  w w w .ja va2  s . com
    server.setSettingsSaver(this);
    SortedMap<String, URL> hostRedirects = new TreeMap<String, URL>();
    try {
        hostRedirects.put("redirect.me.com", new URL("http://localhost:80/"));
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    server.setHostRedirects(hostRedirects);
    server.init();
    if (Jhttpp2Server.error) {
        System.out.println("Error: " + Jhttpp2Server.error_msg);
    } else {
        new Thread(server).start();
        log.info("Running on port " + server.port);
    }
}

From source file:org.esupportail.papercut.domain.PayBoxForm.java

public SortedMap<String, String> getOrderedParams() {
    SortedMap<String, String> params = new TreeMap<String, String>();
    params.put("PBX_SITE", site);
    params.put("PBX_RANG", rang);
    params.put("PBX_IDENTIFIANT", identifiant);
    params.put("PBX_TOTAL", total);
    params.put("PBX_DEVISE", devise);
    params.put("PBX_CMD", commande);
    params.put("PBX_PORTEUR", clientEmail);
    params.put("PBX_RETOUR", retourVariables);
    params.put("PBX_HASH", hash);
    params.put("PBX_TIME", time);
    params.put("PBX_REPONDRE_A", callbackUrl);
    params.put("PBX_EFFECTUE", forwardEffectueUrl);
    params.put("PBX_REFUSE", forwardRefuseUrl);
    params.put("PBX_ANNULE", forwardAnnuleUrl);

    // params.put("PBX_HMAC", hmac);

    return params;
}

From source file:com.jts.rest.profileservice.utils.RestServiceHelper.java

/**
 * Uses MemberChallenge service to get all the associated challenge information for a user
 * Sorts the challenge information with end date
 * Returns all the active challenges and 3 most recent past challenge 
 * @param sessionId//from   w  w  w.  j a va2s  .co m
 * @param username
 * @return
 * @throws MalformedURLException
 * @throws IOException
 */
@SuppressWarnings("unchecked")
public static JSONObject getProcessedChallengesM1(String sessionId, String username)
        throws MalformedURLException, IOException {
    //get all challenges
    JSONArray challenges = getChallenges(sessionId, username);

    JSONArray activeChallenges = new JSONArray();
    JSONArray pastChallenges = new JSONArray();
    SortedMap<Long, JSONObject> pastChallengesByDate = new TreeMap<Long, JSONObject>();
    Iterator<JSONObject> iterator = challenges.iterator();

    DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-ddhh:mm:ss");

    while (iterator.hasNext()) {
        JSONObject challenge = iterator.next();
        //identify active challenge with status
        if (challenge.get("Status__c").equals(PSContants.STATUS_CREATED)) {
            activeChallenges.add(challenge);
        } else {
            String endDateStr = ((String) challenge.get("End_Date__c")).replace("T", "");
            Date date = new Date();
            try {
                date = dateFormat.parse(endDateStr);
            } catch (ParseException pe) {
                logger.log(Level.SEVERE, "Error occurent while parsing date " + endDateStr);
            }
            pastChallengesByDate.put(date.getTime(), challenge);
        }
    }

    //from the sorted map extract the recent challenge
    int pastChallengeSize = pastChallengesByDate.size();
    if (pastChallengeSize > 0) {
        Object[] challengeArr = (Object[]) pastChallengesByDate.values().toArray();
        int startIndex = pastChallengeSize > 3 ? pastChallengeSize - 3 : 0;
        for (int i = startIndex; i < pastChallengeSize; i++) {
            pastChallenges.add(challengeArr[i]);
        }
    }
    JSONObject resultChallenges = new JSONObject();
    resultChallenges.put("activeChallenges", activeChallenges);
    resultChallenges.put("pastChallenges", pastChallenges);
    resultChallenges.put("totalChallenges", challenges.size());
    return resultChallenges;
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.Step6GraphTransitivityCleaner.java

/**
 * Find all elementary cycles in graph (with hard limit 10k cycles to prevent overflow)
 *
 * @param graph graph// w  w w. j a  v  a  2  s . co m
 * @return list of paths (path = list of node ID) of null, if self-loop found
 */
private static List<List<Object>> findCyclesInGraph(Graph graph) {
    // convert into adjacency matrix representation
    SortedMap<String, Integer> nodeToIndexMap = new TreeMap<>();

    ArrayList<Node> origNodes = new ArrayList<>(graph.getNodeSet());
    for (int i = 0; i < origNodes.size(); i++) {
        nodeToIndexMap.put(origNodes.get(i).getId(), i);
    }

    // convert to different format for the algorithm
    String[] nodeIds = new String[origNodes.size()];
    boolean adjMatrix[][] = new boolean[origNodes.size()][origNodes.size()];

    // fill node IDs to array
    for (Map.Entry<String, Integer> entry : nodeToIndexMap.entrySet()) {
        nodeIds[entry.getValue()] = entry.getKey();
    }

    // fill adjacency matrix
    for (Edge edge : graph.getEdgeSet()) {
        String sourceId = edge.getSourceNode().getId();
        String targetId = edge.getTargetNode().getId();

        int sourceIndex = nodeToIndexMap.get(sourceId);
        int targetIndex = nodeToIndexMap.get(targetId);

        adjMatrix[sourceIndex][targetIndex] = true;
    }

    // let's do the magic :)
    ElementaryCyclesSearch ecs = new ElementaryCyclesSearch(adjMatrix, nodeIds);

    List<List<Object>> cycles = ecs.getElementaryCycles();

    // since the algorithm doesn't reveal self-loops, find them by ourselves
    for (Edge edge : graph.getEdgeSet()) {
        if (edge.getTargetNode().getId().equals(edge.getSourceNode().getId())) {
            //                cycles.add(Arrays.asList((Object) edge.getSourceNode().getId(),
            //                        edge.getTargetNode().getId()));
            cycles.add(Collections.<Object>singletonList(edge.getSourceNode().getId()));
        }
    }

    //        System.out.println(cycles);

    return cycles;
}

From source file:com.jivesoftware.sdk.service.instance.action.InstanceRegisterAction.java

@Nonnull
public SortedMap<String, String> toSortedMap() {
    // Encode the client-secret
    String encodedClientSecret = (clientSecret != null) ? DigestUtils.sha256Hex(clientSecret) : clientSecret;
    SortedMap<String, String> sortedMap = Maps.newTreeMap();
    sortedMap.put(CLIENT_ID, clientId);
    sortedMap.put(CLIENT_SECRET, encodedClientSecret);
    sortedMap.put(CODE, code);// w  w w . ja v  a 2 s.  c o m
    sortedMap.put(JIVE_SIGNATURE_URL, jiveSignatureURL);
    sortedMap.put(JIVE_URL, jiveUrl);
    sortedMap.put(SCOPE, scope);
    sortedMap.put(TENANT_ID, tenantId);
    sortedMap.put(TIMESTAMP, timestamp);
    return sortedMap;
}

From source file:co.rsk.peg.StateForFederatorTest.java

@Test
public void serialize() {
    Sha3Hash sha3Hash1 = new Sha3Hash(SHA3_1);
    Sha3Hash sha3Hash2 = new Sha3Hash(SHA3_2);
    Sha3Hash sha3Hash3 = new Sha3Hash(SHA3_3);
    Sha3Hash sha3Hash4 = new Sha3Hash(SHA3_4);

    BtcTransaction tx1 = new BtcTransaction(NETWORK_PARAMETERS);
    BtcTransaction tx2 = new BtcTransaction(NETWORK_PARAMETERS);
    BtcTransaction tx3 = new BtcTransaction(NETWORK_PARAMETERS);
    BtcTransaction tx4 = new BtcTransaction(NETWORK_PARAMETERS);

    SortedMap<Sha3Hash, BtcTransaction> rskTxsWaitingForSignatures = new TreeMap<>();
    rskTxsWaitingForSignatures.put(sha3Hash1, tx1);
    rskTxsWaitingForSignatures.put(sha3Hash2, tx2);

    SortedMap<Sha3Hash, Pair<BtcTransaction, Long>> rskTxsWaitingForBroadcasting = new TreeMap<>();
    rskTxsWaitingForBroadcasting.put(sha3Hash3, Pair.of(tx3, 3L));
    rskTxsWaitingForBroadcasting.put(sha3Hash4, Pair.of(tx4, 4L));

    StateForFederator stateForFederator = new StateForFederator(rskTxsWaitingForSignatures,
            rskTxsWaitingForBroadcasting);

    byte[] encoded = stateForFederator.getEncoded();

    Assert.assertTrue(encoded.length > 0);

    StateForFederator reverseResult = new StateForFederator(encoded, NETWORK_PARAMETERS);

    Assert.assertNotNull(reverseResult);
    Assert.assertEquals(2, reverseResult.getRskTxsWaitingForBroadcasting().size());
    Assert.assertEquals(2, reverseResult.getRskTxsWaitingForSignatures().size());

    Assert.assertEquals(tx1, reverseResult.getRskTxsWaitingForSignatures().get(sha3Hash1));
    Assert.assertEquals(tx2, reverseResult.getRskTxsWaitingForSignatures().get(sha3Hash2));

    Assert.assertTrue(checkKeys(reverseResult.getRskTxsWaitingForSignatures().keySet(), sha3Hash1, sha3Hash2));

    Assert.assertEquals(Pair.of(tx3, 3L), reverseResult.getRskTxsWaitingForBroadcasting().get(sha3Hash3));
    Assert.assertEquals(Pair.of(tx4, 4L), reverseResult.getRskTxsWaitingForBroadcasting().get(sha3Hash4));

    Assert.assertTrue(/* w  ww . j  a v a  2s.  com*/
            checkKeys(reverseResult.getRskTxsWaitingForBroadcasting().keySet(), sha3Hash3, sha3Hash4));
}

From source file:org.ambraproject.admin.service.impl.CacheServiceImpl.java

/**
 * get cache stats data for display by manageCaches.ftl
 *
 * @return SortedMap of strings/*  ww  w  .j  a v a 2  s .co  m*/
 */
public SortedMap<String, String[]> getCacheData() {
    SortedMap<String, String[]> cacheStats = new TreeMap<String, String[]>();
    // header row
    cacheStats.put("", new String[] { "Size #/Objects", "Hits (Memory/Disk)", "Misses", "Eternal (TTI/TTL)",
            "Disk Overflow/Persistent", });

    final String[] cacheNames = cacheManager.getCacheNames();
    for (final String displayName : cacheNames) {
        final Ehcache cache = cacheManager.getEhcache(displayName);
        final Statistics statistics = cache.getStatistics();
        cacheStats.put(displayName, new String[] {
                String.valueOf(cache.getSize()) + " / " + String.valueOf(statistics.getObjectCount()),
                String.valueOf(statistics.getCacheHits()) + " ( " + String.valueOf(statistics.getInMemoryHits())
                        + " / " + String.valueOf(statistics.getOnDiskHits()) + " )",
                String.valueOf(statistics.getCacheMisses()),
                String.valueOf(cache.getCacheConfiguration().isEternal()) + " ( "
                        + String.valueOf(cache.getCacheConfiguration().getTimeToIdleSeconds()) + " / "
                        + String.valueOf(cache.getCacheConfiguration().getTimeToLiveSeconds()) + " )",
                String.valueOf(cache.getCacheConfiguration().isOverflowToDisk()) + " / "
                        + String.valueOf(cache.getCacheConfiguration().isDiskPersistent()) });
    }

    return cacheStats;
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.sequence.evaluation.F1ScoreTableAggregator.java

public static void evaluatePredictionsFoldersDomain(File masterFolder, String folderContains) throws Exception {
    SortedMap<String, SortedMap<String, String>> featureSetsResults = new TreeMap<>();

    File[] foldersFeatureSets = masterFolder.listFiles(EvalHelper.DIRECTORY_FILTER);

    for (File folderFeatureSet : foldersFeatureSets) {
        String[] split = folderFeatureSet.getName().split("_");
        String featureSet = split[0];
        String paramE = split[1];
        String paramT = split[2];

        if ("e0".equals(paramE) && "t1".equals(paramT)) {

            Map<String, File> foldersData = EvalHelper.listSubFoldersAndRemoveUUID(folderFeatureSet);
            for (Map.Entry<String, File> folderData : foldersData.entrySet()) {

                String data = folderData.getKey();

                if (data.contains(folderContains)) {
                    File resultSummary = new File(folderData.getValue(), "resultSummary.txt");

                    List<String> values = extractValues(resultSummary);
                    String macroF1 = values.get(0);

                    if (!featureSetsResults.containsKey(featureSet)) {
                        featureSetsResults.put(featureSet, new TreeMap<String, String>());
                    }/*from w  w  w.  j a v a  2 s  .co m*/

                    String domainName = data.split("_")[2];

                    featureSetsResults.get(featureSet).put(domainName, macroF1);
                }
            }
        }
    }

    // print results
    int rows = featureSetsResults.values().iterator().next().size();
    System.out.printf("\t");

    for (String featureSet : featureSetsResults.keySet()) {
        System.out.printf("%s\t", featureSet);
    }
    System.out.println();
    for (int i = 0; i < rows; i++) {
        //            Set<String> keySet = featureSetsResults.values().iterator().next().keySet();
        SortedMap<String, String> firstColumn = featureSetsResults.values().iterator().next();
        List<String> keys = new ArrayList<>(firstColumn.keySet());
        System.out.printf("%s\t", keys.get(i));

        for (SortedMap<String, String> values : featureSetsResults.values()) {
            System.out.printf("%s\t", values.get(keys.get(i)));
        }

        System.out.println();
    }
}

From source file:net.sourceforge.subsonic.dao.PlaylistDao.java

public List<Playlist> getReadablePlaylistsForUser(String username) {

    List<Playlist> result1 = getWritablePlaylistsForUser(username);
    List<Playlist> result2 = query("select " + COLUMNS + " from playlist where is_public", rowMapper);
    List<Playlist> result3 = query("select " + prefix(COLUMNS, "playlist")
            + " from playlist, playlist_user where " + "playlist.id = playlist_user.playlist_id and "
            + "playlist.username != ? and " + "playlist_user.username = ?", rowMapper, username, username);

    // Put in sorted map to avoid duplicates.
    SortedMap<Integer, Playlist> map = new TreeMap<Integer, Playlist>();
    for (Playlist playlist : result1) {
        map.put(playlist.getId(), playlist);
    }//www. j av a 2  s .  c  o  m
    for (Playlist playlist : result2) {
        map.put(playlist.getId(), playlist);
    }
    for (Playlist playlist : result3) {
        map.put(playlist.getId(), playlist);
    }
    return new ArrayList<Playlist>(map.values());
}