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.hichinaschool.flashcards.libanki.Decks.java

public void select(long did) {
    try {//from  w  w w  . jav a  2s  .  c  o  m
        String name = mDecks.get(did).getString("name");
        // current deck
        mCol.getConf().put("curDeck", Long.toString(did));
        // and active decks (current + all children)
        TreeMap<String, Long> actv = children(did);
        actv.put(name, did);
        JSONArray ja = new JSONArray();
        for (Long n : actv.values()) {
            ja.put(n);
        }
        mCol.getConf().put("activeDecks", ja);
        mChanged = true;
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.impetus.ankush2.framework.monitor.AbstractMonitor.java

/**
 * Method to convert null value maps to list object.
 * /* ww  w.  java2 s .c om*/
 * @param treeMap
 *            the tree map
 * @return the object
 */
private static Object convertToList(TreeMap treeMap) {
    // if treemap is null or empty return null.
    if (treeMap == null || treeMap.isEmpty())
        return null;
    boolean isList = false;
    // item set
    List itemSet = new ArrayList();
    // iterating over the treemap.
    for (Object m : treeMap.keySet()) {
        // item key.
        String itemKey = m.toString();
        // if value is null.
        if (treeMap.get(itemKey) == null) {
            isList = true;
            // adding item to item set.
            itemSet.add(itemKey);
        } else {
            // getting the object.
            Object obj = convertToList((TreeMap) (treeMap.get(itemKey)));
            // empty map.
            TreeMap map = new TreeMap();
            // putting object in map.
            map.put(itemKey, obj);
            // putting object in tree map.
            treeMap.put(itemKey, obj);
            // adding the item in set.
            itemSet.add(map);
        }
    }

    // if it is list then return list else return map.
    if (isList) {
        return itemSet;
    } else {
        return treeMap;
    }
}

From source file:au.edu.ausstage.networks.LookupManager.java

/**
 * A method to lookup the key collaborators for a contributor
 *
 * @param id         the unique id of the contributor
 * @param formatType the required format of the data
 * @param sortType   the required way in which the data is to be sorted
 *
 * @return           the results of the lookup
 *//*from w  w  w . ja va2 s .  c o  m*/
public String getKeyCollaborators(String id, String formatType, String sortType) {

    // check on the parameters
    if (InputUtils.isValidInt(id) == false || InputUtils.isValid(formatType) == false
            || InputUtils.isValid(sortType) == false) {
        throw new IllegalArgumentException("All parameters to this method are required");
    }

    // define a Tree Set to store the results
    java.util.LinkedList<Collaborator> collaborators = new java.util.LinkedList<Collaborator>();

    // define other helper variables
    QuerySolution row = null;
    Collaborator collaborator = null;

    // define the base sparql query
    String sparqlQuery = "PREFIX foaf:       <" + FOAF.NS + ">" + "PREFIX ausestage:  <" + AuseStage.NS + "> "
            + "SELECT ?collaborator ?collabGivenName ?collabFamilyName ?function ?firstDate ?lastDate ?collabCount "
            + "WHERE {  " + "       @ a foaf:Person ; "
            + "                      ausestage:hasCollaboration ?collaboration. "
            + "       ?collaboration ausestage:collaborator ?collaborator; "
            + "                      ausestage:collaborationFirstDate ?firstDate; "
            + "                      ausestage:collaborationLastDate ?lastDate; "
            + "                      ausestage:collaborationCount ?collabCount. "
            + "       ?collaborator  foaf:givenName ?collabGivenName; "
            + "                      foaf:familyName ?collabFamilyName; "
            + "                      ausestage:function ?function. " + "       FILTER (?collaborator != @) "
            + "}";

    // do we need to sort by name?
    if (sortType.equals("count") == true) {
        sparqlQuery += " ORDER BY DESC(?collabCount)";
    } else if (sortType.equals("name") == true) {
        sparqlQuery += " ORDER BY ?collabFamilyName ?collabGivenName";
    }

    // build a URI from the id
    id = AusStageURI.getContributorURI(id);

    // add the contributor URI to the query
    sparqlQuery = sparqlQuery.replaceAll("@", "<" + id + ">");

    // execute the query
    ResultSet results = rdf.executeSparqlQuery(sparqlQuery);

    // build the dataset
    // use a numeric sort order
    while (results.hasNext()) {
        // loop though the resulset
        // get a new row of data
        row = results.nextSolution();

        // instantiate a collaborator object
        collaborator = new Collaborator(AusStageURI.getId(row.get("collaborator").toString()));

        // check to see if the list contains this collaborator
        if (collaborators.indexOf(collaborator) != -1) {
            // collaborator is already in the list
            collaborator = collaborators.get(collaborators.indexOf(collaborator));

            // update the function
            collaborator.setFunction(row.get("function").toString());

        } else {
            // collaborator is not on the list

            // get the name
            collaborator.setGivenName(row.get("collabGivenName").toString());
            collaborator.setFamilyName(row.get("collabFamilyName").toString(), true);

            // get the dates
            collaborator.setFirstDate(row.get("firstDate").toString());
            collaborator.setLastDate(row.get("lastDate").toString());

            // get the collaboration count
            collaborator.setCollaborations(Integer.toString(row.get("collabCount").asLiteral().getInt()));

            // add the url
            collaborator.setUrl(AusStageURI.getURL(row.get("collaborator").toString()));

            // add the function
            collaborator.setFunction(row.get("function").toString());

            collaborators.add(collaborator);
        }
    }

    // play nice and tidy up
    rdf.tidyUp();

    // sort by the id
    if (sortType.equals("id") == true) {
        TreeMap<Integer, Collaborator> collaboratorsToSort = new TreeMap<Integer, Collaborator>();

        for (int i = 0; i < collaborators.size(); i++) {
            collaborator = collaborator = collaborators.get(i);

            collaboratorsToSort.put(Integer.parseInt(collaborator.getId()), collaborator);
        }

        // empty the list
        collaborators.clear();

        // add the collaborators back to the list
        Collection values = collaboratorsToSort.values();
        Iterator iterator = values.iterator();

        while (iterator.hasNext()) {
            // get the collaborator
            collaborator = (Collaborator) iterator.next();

            collaborators.add(collaborator);
        }

        collaboratorsToSort = null;
    }

    // define a variable to store the data
    String dataString = null;

    if (formatType.equals("html") == true) {
        dataString = createHTMLOutput(collaborators);
    } else if (formatType.equals("xml") == true) {
        dataString = createXMLOutput(collaborators);
    } else if (formatType.equals("json") == true) {
        dataString = createJSONOutput(collaborators);
    }

    // return the data
    return dataString;
}

From source file:com.fdu.jira.plugin.report.timesheet.TimeSheet.java

private Map<String, List<Worklog>> getWorklogMapByUser(List<Worklog> worklogObjects) {
    TreeMap<String, List<Worklog>> presult = new TreeMap<String, List<Worklog>>();
    for (Worklog w : worklogObjects) {
        List<Worklog> worklogs = presult.get(w.getAuthor());
        if (worklogs == null) {
            worklogs = new ArrayList<Worklog>();
            presult.put(w.getAuthor(), worklogs);
        }//from ww w.  ja va2  s . c  o  m
        worklogs.add(w);
    }
    LinkedHashMap<String, List<Worklog>> result = new LinkedHashMap<String, List<Worklog>>();
    List<Map.Entry<String, List<Worklog>>> keyList = new ArrayList<Map.Entry<String, List<Worklog>>>(
            presult.entrySet());
    final UserManager userManager = ComponentAccessor.getUserManager();
    if (userManager != null)
        Collections.sort(keyList, new Comparator<Map.Entry<String, List<Worklog>>>() {
            public int compare(Map.Entry<String, List<Worklog>> e1, Map.Entry<String, List<Worklog>> e2) {
                User user1 = userManager.getUser(e1.getKey());
                User user2 = userManager.getUser(e2.getKey());
                String userFullName1 = (user1 != null) ? user1.getDisplayName() : e1.getKey();
                String userFullName2 = (user1 != null) ? user2.getDisplayName() : e2.getKey();
                return userFullName1.compareTo(userFullName2);
            }
        });
    for (Map.Entry<String, List<Worklog>> e : keyList) {
        result.put(e.getKey(), e.getValue());
    }
    return result;
}

From source file:com.nubits.nubot.trading.wrappers.AllCoinWrapper.java

public ApiResponse getLastTradesImpl(CurrencyPair pair, long startTime) {
    ApiResponse apiResponse = new ApiResponse();
    String url = API_AUTH_URL;
    String method = API_TRADES;//from w  ww . j  a v  a 2s  .  c  o  m
    boolean isGet = false;
    ArrayList<Trade> tradeList = new ArrayList<Trade>();
    TreeMap<String, String> query_args = new TreeMap<>();
    query_args.put("page", "1");
    query_args.put("page_size", "20");

    ApiResponse response = getQuery(url, method, query_args, true, isGet);
    if (response.isPositive()) {
        JSONObject httpAnswerJson = (JSONObject) response.getResponseObject();
        JSONArray trades = (JSONArray) httpAnswerJson.get("data");
        if (trades != null) {
            //LOG.info(trades.toJSONString());
            for (Iterator<JSONObject> trade = trades.iterator(); trade.hasNext();) {
                Trade thisTrade = parseTrade(trade.next());
                if (!thisTrade.getPair().equals(pair)) {
                    continue;
                }
                if (thisTrade.getDate().getTime() < startTime) {
                    continue;
                }
                tradeList.add(thisTrade);
            }
        }
        apiResponse.setResponseObject(tradeList);
    } else {
        apiResponse = response;
    }

    return apiResponse;
}

From source file:com.nubits.nubot.trading.wrappers.AllCoinWrapper.java

private ApiResponse enterOrder(String type, CurrencyPair pair, double amount, double price) {
    ApiResponse apiResponse = new ApiResponse();
    String order_id;/*ww w  .  ja v  a2s .co m*/
    boolean isGet = false;
    TreeMap<String, String> query_args = new TreeMap<>();

    query_args.put("num", String.valueOf(amount));
    query_args.put("price", String.valueOf(price));
    query_args.put("exchange", pair.getPaymentCurrency().getCode().toUpperCase());
    query_args.put("type", pair.getOrderCurrency().getCode().toUpperCase());

    String url = API_AUTH_URL;
    String method;

    if (type == Constant.BUY) {
        method = API_BUY_COIN;
    } else {
        method = API_SELL_COIN;
    }

    ApiResponse response = getQuery(url, method, query_args, true, isGet);
    if (response.isPositive()) {
        JSONObject httpAnswerJson = (JSONObject) response.getResponseObject();
        JSONObject dataJson = (JSONObject) httpAnswerJson.get(TOKEN_DATA);
        if (dataJson.containsKey(TOKEN_ORDER_ID)) {
            order_id = dataJson.get(TOKEN_ORDER_ID).toString();
            apiResponse.setResponseObject(order_id);
        } else {
            apiResponse.setError(errors.genericError);
        }
    } else {
        apiResponse = response;
    }

    return apiResponse;
}

From source file:com.alkacon.opencms.counter.CmsCounterManager.java

/** 
 * This functions returns all counter entries from the database.<p>
 * //from   www.j  a va  2s.com
 * @return a Map of all counter entries with id as key and {@link Integer} as value
 */
public TreeMap getCounters() {

    TreeMap result = new TreeMap();
    PreparedStatement statement = null;
    Connection con = null;
    ResultSet res = null;
    try {

        // get connection and set the statements
        con = CmsDbUtil.getInstance().getConnection(m_connectionPool);
        statement = con.prepareStatement(C_GET_COUNTERS);
        res = statement.executeQuery();

        // the query result is parsing into key and value
        String key;
        int value;
        while (res.next()) {
            key = res.getString(1);
            value = res.getInt(2);
            result.put(key, new Integer(value));
        }

    } catch (Exception ex) {
        if (LOG.isErrorEnabled()) {
            LOG.error(Messages.get().getBundle().key(Messages.LOG_ERROR_ACCESSING_DB_1, C_COUNTER_TABLE), ex);
        }
    } finally {
        CmsDbUtil.getInstance().closeConnection(res, statement, con);
    }
    return result;
}

From source file:com.hichinaschool.flashcards.anki.Preferences.java

private void initializeLanguageDialog() {
    TreeMap<String, String> items = new TreeMap<String, String>();
    for (String localeCode : mAppLanguages) {
        Locale loc;//from  w w  w.j  av  a  2 s.c om
        if (localeCode.length() > 2) {
            loc = new Locale(localeCode.substring(0, 2), localeCode.substring(3, 5));
        } else {
            loc = new Locale(localeCode);
        }
        items.put(loc.getDisplayName(), loc.toString());
    }
    mLanguageDialogLabels = new CharSequence[items.size() + 1];
    mLanguageDialogValues = new CharSequence[items.size() + 1];
    mLanguageDialogLabels[0] = getResources().getString(R.string.language_system);
    mLanguageDialogValues[0] = "";
    int i = 1;
    for (Map.Entry<String, String> e : items.entrySet()) {
        mLanguageDialogLabels[i] = e.getKey();
        mLanguageDialogValues[i] = e.getValue();
        i++;
    }
    mLanguageSelection = (ListPreference) getPreferenceScreen().findPreference("language");
    mLanguageSelection.setEntries(mLanguageDialogLabels);
    mLanguageSelection.setEntryValues(mLanguageDialogValues);
}

From source file:com.clustercontrol.collect.util.CollectGraphUtil.java

/**
 * ????????????monitorId?managerName??facilityId-collectID?Map????
 * @param itemCode/*from   w  w w . ja  v  a2s  .c  o m*/
 * @return
 */
private static Map<String, Integer> getFacilityCollectMap(String itemDisplayNameMonitorId, String managerName) {
    List<Integer> collectIdList = getInstance().m_managerMonitorCollectIdMap.get(managerName)
            .get(itemDisplayNameMonitorId);
    Map<String, List<Integer>> facilityCollectMap = getInstance().m_targetManagerFacilityCollectMap
            .get(managerName);
    TreeMap<String, Integer> retMap = new TreeMap<String, Integer>();
    if (facilityCollectMap != null && !facilityCollectMap.isEmpty()) {
        for (Map.Entry<String, List<Integer>> entry : facilityCollectMap.entrySet()) {
            String facilityId = entry.getKey();
            List<Integer> collectIdList1 = entry.getValue();
            boolean search = false;
            if (collectIdList != null && !collectIdList.isEmpty()) {
                for (Integer collectId : collectIdList) {
                    if (collectIdList1.contains(collectId)) {
                        retMap.put(facilityId, collectId);
                        search = true;
                        break;
                    }
                }
            }
            // ??itemDisplayNameMonitorId???collectID??????null?
            // ????
            if (!search) {
                retMap.put(facilityId, null);
            }
        }
    }
    return retMap;
}

From source file:com.nubits.nubot.trading.wrappers.PeatioWrapper.java

public ApiResponse getLastTradesImpl(CurrencyPair pair, long startTime) {
    ApiResponse apiResponse = new ApiResponse();
    String url = apiBaseUrl;/*from  w  ww  .jav a  2 s. c  o m*/
    String method = API_GET_TRADES;
    boolean isGet = true;
    TreeMap<String, String> query_args = new TreeMap<>();
    ArrayList<Trade> tradeList = new ArrayList<Trade>();

    query_args.put("canonical_verb", "GET");
    query_args.put("canonical_uri", method);
    query_args.put("market", pair.toString());
    query_args.put("limit", "1000");

    ApiResponse response = getQuery(url, method, query_args, true, isGet);
    if (response.isPositive()) {
        LOG.info("A maximum of 1000 trades can be returned from the Peatio API");
        JSONArray httpAnswerJson = (JSONArray) response.getResponseObject();
        for (Iterator<JSONObject> trade = httpAnswerJson.iterator(); trade.hasNext();) {
            Trade thisTrade = parseTrade(trade.next());
            if (thisTrade.getDate().getTime() < startTime) {
                continue;
            }
            tradeList.add(thisTrade);
        }
        apiResponse.setResponseObject(tradeList);
    } else {
        apiResponse = response;
    }
    return apiResponse;
}