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

@SuppressWarnings("unused")
private static void loadOrganizationsAndProjects() {
    TreeMap<String, ArrayList<String>> organizations = new TreeMap<String, ArrayList<String>>();

    ArrayList<String> projects = new ArrayList<String>();
    projects.add("Project 1");
    projects.add("Project 2");
    projects.add("Project 3");
    organizations.put("Organization 1", projects);

    projects = new ArrayList<String>();
    projects.add("Project A");
    projects.add("Project B");
    projects.add("Project C");
    organizations.put("Organization A", projects);

    projects = new ArrayList<String>();
    projects.add("Project X");
    projects.add("Project Y");
    projects.add("Project Z");
    organizations.put("Organization K", projects);

    for (String key : organizations.keySet()) {
        OrganizationDTO org = new OrganizationDTO();
        org.setName(key);/*from  ww  w  .  ja  v a2  s  .  c om*/
        org = (OrganizationDTO) GenericDAO.getInstance().insert(org);
        logger.info("OrganizationDTO inserted: " + key);

        ArrayList<String> subdomains = organizations.get(key);
        for (String s : subdomains) {
            ProjectDTO proj = new ProjectDTO();
            proj.setName(s);
            proj.setOrganizationDTO(org);
            GenericDAO.getInstance().insert(proj);
            logger.info("ProjectDTO inserted: " + s);
        }
    }
}

From source file:net.imglib2.script.analysis.Histogram.java

@SuppressWarnings("boxing")
static private final <R extends RealType<R>> double process(final TreeMap<Double, Long> map, final Img<R> img,
        final int nBins, final double min, final double max) throws Exception {
    final double range = max - min;
    final double increment = range / nBins;
    final long[] bins = new long[nBins];
    ///* w w  w.j  a  v  a2  s . co  m*/
    if (0.0 == range) {
        bins[0] = img.size();
    } else {
        final Cursor<R> c = img.cursor();
        // zero-based:
        final int N = nBins - 1;
        // Analyze the image
        while (c.hasNext()) {
            c.fwd();
            int v = (int) (((c.get().getRealDouble() - min) / range) * N);
            if (v < 0)
                v = 0;
            else if (v > N)
                v = N;
            bins[v] += 1;
        }
    }
    // Put the contents of the bins into the map
    for (int i = 0; i < bins.length; i++) {
        map.put(min + i * increment, bins[i]);
    }

    return increment;
}

From source file:module.entities.NameFinder.DB.java

public static TreeMap<Integer, String> getDemocracitJSON(int consultation_id) throws SQLException {
    TreeMap<Integer, String> all = new TreeMap<Integer, String>();
    String selectSQL1 = "SELECT distinct consultation_id FROM enhancedentities;";
    ResultSet rs1 = connection.createStatement().executeQuery(selectSQL1);
    while (rs1.next()) {
        System.out.println(rs1.getString(1));
    }/*from  ww  w.j a v a  2s  .c om*/
    String selectSQL = "SELECT article_id,json_text FROM enhancedentities where consultation_id="
            + consultation_id + ";";
    ResultSet rs = connection.createStatement().executeQuery(selectSQL);
    while (rs.next()) {
        int tid = rs.getInt(1);
        String s = rs.getString(2);
        all.put(tid, s);
    }
    return all;
}

From source file:dk.statsbiblioteket.doms.licensemodule.validation.LicenseValidator.java

public static ArrayList<UserGroupDTO> filterGroupsWithPresentationtype(ArrayList<License> licenses) {
    TreeMap<String, UserGroupDTO> groups = new TreeMap<String, UserGroupDTO>();
    for (License currentLicense : licenses) {
        for (LicenseContent currentGroup : currentLicense.getLicenseContents()) {
            String name = currentGroup.getName();
            UserGroupDTO group = groups.get(name);
            if (group == null) {
                group = new UserGroupDTO();
                group.setPresentationTypes(new ArrayList<String>());
                group.setGroupName(name);
                groups.put(name, group);
            }/*  w  w w . j a  v  a  2s.co  m*/
            for (Presentation currentPresentation : currentGroup.getPresentations()) {
                String presentation_key = currentPresentation.getKey();
                if (group.getPresentationTypes().contains(presentation_key)) {
                    //Already added
                } else {
                    group.getPresentationTypes().add(presentation_key);
                }
            }
        }
    }
    return new ArrayList<UserGroupDTO>(groups.values());
}

From source file:BitLottoVerify.java

public static Map<String, String> getDrawTxSet(String addr, String mixer_hash) throws Exception {
    Map<String, Long> tx_map = getPaymentsBlockChainInfo(addr);

    int transactions = 0;
    int tickets = 0;
    long total_value = 0;

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

    for (Map.Entry<String, Long> me : tx_map.entrySet()) {
        String txid = me.getKey();
        long amt = me.getValue();

        transactions++;/*from  ww  w.  j av  a  2s . co  m*/
        total_value += amt;
        int ticket_num = 0;

        while (amt >= TICKET_COST) {
            StringBuilder explain = new StringBuilder();
            explain.append("Transaction: " + txid + " ");
            String ticket_str = txid;
            if (ticket_num >= 1) {
                explain.append("multi:" + ticket_num + " sha256(sha256(tx+" + ticket_num + ")+mixer_hash)");
                String hash_str = txid + ticket_num;
                ticket_str = sha256(hash_str);
            } else {
                explain.append("sha256(tx+mixer_hash)");
            }
            String res = sha256(ticket_str + mixer_hash);

            final_map.put(res, explain.toString());

            amt -= TICKET_COST;
            ticket_num++;
            tickets++;

        }

    }

    double btc = total_value / 1e8;
    System.out.println("Transactions: " + transactions + " BTC: " + btc + " tickets: " + tickets);
    return final_map;

}

From source file:com.sshtools.common.vomanagementtool.common.VOHelper.java

public static boolean addVOToFavourites(String voName, String fromGroup) {
    boolean isAdded = false;
    //First check if VO is already in Favourites
    TreeMap allFavVOs = getVOGroup(FAVOURITES);
    if (allFavVOs.containsKey(voName)) {
        JOptionPane.showMessageDialog(null, "VO '" + voName + "' is already in " + FAVOURITES + ".",
                "Error: Add VO to " + FAVOURITES, JOptionPane.ERROR_MESSAGE);
    } else {/* w  ww. j  a va 2 s . c  o m*/
        TreeMap groupVOs = getVOGroup(fromGroup);
        if (groupVOs.containsKey(voName)) {
            List voDetails = (List) groupVOs.get(voName);
            allFavVOs.put(voName, voDetails);
            String newContent = createStringFromTreeMap(allFavVOs);
            try {
                writeToFile(favouritesFile, newContent);
                isAdded = true;
            } catch (IOException e) {
                JOptionPane.showMessageDialog(
                        null, "Cannot add VO '" + voName + "' to " + FAVOURITES + ". Write to file '"
                                + favouritesFile + "' failed",
                        "Error: Add VO to " + FAVOURITES, JOptionPane.ERROR_MESSAGE);
            }

        }
    }
    return isAdded;
}

From source file:SerialVersionUID.java

/**
 * Build a TreeMap of the class name to ClassVersionInfo
 * // w  ww  . j av a 2 s.c o m
 * @param jar
 * @param classVersionMap
 *          TreeMap<String, ClassVersionInfo> for serializable classes
 * @param cl -
 *          the class loader to use
 * @throws IOException
 *           thrown if the jar cannot be opened
 */
static void generateJarSerialVersionUIDs(URL jar, TreeMap classVersionMap, ClassLoader cl, String pkgPrefix)
        throws IOException {
    String jarName = jar.getFile();
    JarFile jf = new JarFile(jarName);
    Enumeration entries = jf.entries();
    while (entries.hasMoreElements()) {
        JarEntry entry = (JarEntry) entries.nextElement();
        String name = entry.getName();
        if (name.endsWith(".class") && name.startsWith(pkgPrefix)) {
            name = name.substring(0, name.length() - 6);
            String classname = name.replace('/', '.');
            try {
                log.fine("Creating ClassVersionInfo for: " + classname);
                ClassVersionInfo cvi = new ClassVersionInfo(classname, cl);
                log.fine(cvi.toString());
                if (cvi.getSerialVersion() != 0) {
                    ClassVersionInfo prevCVI = (ClassVersionInfo) classVersionMap.put(classname, cvi);
                    if (prevCVI != null) {
                        if (prevCVI.getSerialVersion() != cvi.getSerialVersion()) {
                            log.severe("Found inconsistent classes, " + prevCVI + " != " + cvi + ", jar: "
                                    + jarName);
                        }
                    }
                    if (cvi.getHasExplicitSerialVersionUID() == false) {
                        log.warning("No explicit serialVersionUID: " + cvi);
                    }
                }
            } catch (OutOfMemoryError e) {
                log.log(Level.SEVERE, "Check the MaxPermSize", e);
            } catch (Throwable e) {
                log.log(Level.FINE, "While loading: " + name, e);
            }
        }
    }
    jf.close();
}

From source file:nl.surfnet.coin.api.controller.AccessConfirmationController.java

@RequestMapping("/oauth2/confirm_access")
public ModelAndView getAccessConfirmation(HttpServletRequest request,
        @ModelAttribute AuthorizationRequest clientAuth) throws Exception {
    ClientDetails client = clientDetailsService.loadClientByClientId(clientAuth.getClientId());
    TreeMap<String, Object> model = new TreeMap<String, Object>();
    model.put("auth_request", clientAuth);
    model.put("client", client);
    model.put("locale", RequestContextUtils.getLocale(request).toString());
    model.put("staticContentBasePath", staticContentBasePath);
    Map<String, String> languageLinks = new HashMap<String, String>();
    languageLinks.put("en", getUrlWithLanguageParam(request, "en"));
    languageLinks.put("nl", getUrlWithLanguageParam(request, "nl"));
    model.put("languageLinks", languageLinks);
    return new ModelAndView("access_confirmation", model);
}

From source file:it.imtech.bookimporter.BookUtilityTest.java

/**
 * Test of getOrderedLanguages method, of class BookUtility.
 */// ww w.j a  v  a  2s . c  o  m
public void testGetOrderedLanguages() {
    System.out.println("Test Ordering configuration languages: method -> getOrderedLanguages");
    TreeMap<String, String> en = new TreeMap<String, String>();
    en.put("English", "en");
    en.put("German", "de");
    en.put("Italian", "it");

    TreeMap<String, String> it = new TreeMap<String, String>();
    it.put("Inglese", "en");
    it.put("Italiano", "it");
    it.put("Tedesco", "de");

    TreeMap<String, String> de = new TreeMap<String, String>();
    de.put("Deutsch", "de");
    de.put("English", "en");
    de.put("Italienisch", "it");

    try {
        CustomClassLoader loader = new CustomClassLoader();

        Locale locale = new Locale("en");
        ResourceBundle bundle = ResourceBundle.getBundle(RESOURCES, locale, loader);
        XMLConfiguration config = new XMLConfiguration(new File(DEBUG_XML));
        TreeMap<String, String> result = BookUtility.getOrderedLanguages(config, bundle);
        assertEquals(en, result);

        locale = new Locale("it");
        bundle = ResourceBundle.getBundle(RESOURCES, locale, loader);
        config = new XMLConfiguration(new File(DEBUG_XML));
        result = BookUtility.getOrderedLanguages(config, bundle);
        assertEquals(it, result);

        locale = new Locale("de");
        bundle = ResourceBundle.getBundle(RESOURCES, locale, loader);
        config = new XMLConfiguration(new File(DEBUG_XML));
        result = BookUtility.getOrderedLanguages(config, bundle);
        assertEquals(de, result);
    } catch (ConfigurationException e) {
        fail("Ordering Language Test failed: ConfigurationException:- " + e.getMessage());
    }
}

From source file:edu.illinois.cs.cogcomp.transliteration.WikiTransliteration.java

/**
 * Helper function.//  w  w w  .ja v  a2 s .c  o  m
 * @param word1
 * @param maxSubstringLength
 * @param probMap
 * @param probs
 * @param memoizationTable
 * @param pruneToSize
 * @return
 */
public static HashMap<String, Double> Predict2(String word1, int maxSubstringLength,
        Map<String, HashSet<String>> probMap, HashMap<Production, Double> probs,
        HashMap<String, HashMap<String, Double>> memoizationTable, int pruneToSize) {
    HashMap<String, Double> result;
    if (word1.length() == 0) {
        result = new HashMap<>(1);
        result.put("", 1.0);
        return result;
    }

    if (memoizationTable.containsKey(word1)) {
        return memoizationTable.get(word1);
    }

    result = new HashMap<>();

    int maxSubstringLength1 = Math.min(word1.length(), maxSubstringLength);

    for (int i = 1; i <= maxSubstringLength1; i++) {
        String substring1 = word1.substring(0, i);

        if (probMap.containsKey(substring1)) {

            // recursion right here.
            HashMap<String, Double> appends = Predict2(word1.substring(i), maxSubstringLength, probMap, probs,
                    memoizationTable, pruneToSize);

            //int segmentations = Segmentations( word1.Length - i );

            for (String tgt : probMap.get(substring1)) {
                Production alignment = new Production(substring1, tgt);

                double alignmentProb = probs.get(alignment);

                for (String key : appends.keySet()) {
                    Double value = appends.get(key);
                    String word = alignment.getSecond() + key;
                    //double combinedProb = (pair.Value/segmentations) * alignmentProb;
                    double combinedProb = (value) * alignmentProb;

                    // I hope this is an accurate translation...
                    Dictionaries.IncrementOrSet(result, word, combinedProb, combinedProb);
                }
            }

        }
    }

    if (result.size() > pruneToSize) {
        Double[] valuesArray = result.values().toArray(new Double[result.values().size()]);
        String[] data = result.keySet().toArray(new String[result.size()]);

        //Array.Sort<Double, String> (valuesArray, data);

        TreeMap<Double, String> sorted = new TreeMap<>();
        for (int i = 0; i < valuesArray.length; i++) {
            sorted.put(valuesArray[i], data[i]);
        }

        // FIXME: is this sorted in the correct order???

        //double sum = 0;
        //for (int i = data.Length - pruneToSize; i < data.Length; i++)
        //    sum += valuesArray[i];

        result = new HashMap<>(pruneToSize);
        //            for (int i = data.length - pruneToSize; i < data.length; i++)
        //                result.put(data[i], valuesArray[i]);

        int i = 0;
        for (Double d : sorted.descendingKeySet()) {
            result.put(sorted.get(d), d);
            if (i++ > pruneToSize) {
                break;
            }
        }
    }

    memoizationTable.put(word1, result);
    return result;
}