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.sfs.whichdoctor.dao.GroupDAOImpl.java

/**
 * Load group./*  www  . j  a  v a2s  .c om*/
 *
 * @param rs the rs
 * @param loadDetails the load details
 *
 * @return the group bean
 *
 * @throws SQLException the SQL exception
 */
private GroupBean loadGroup(final ResultSet rs, final BuilderBean loadDetails) throws SQLException {

    GroupBean group = new GroupBean();

    group.setId(rs.getInt("GroupId"));
    group.setGUID(rs.getInt("GUID"));
    group.setObjectType(rs.getString("ObjectType"));
    group.setType(rs.getString("Type"));
    group.setYear(rs.getInt("Year"));
    group.setColour(rs.getString("Colour"));
    group.setWeighting(rs.getInt("Weighting"));
    group.setPermission(rs.getString("Permission"));
    group.setName(rs.getString("Name"));
    group.setDescription(rs.getString("Description"));
    group.setGroupDN(rs.getString("GroupDN"));
    group.setItemCount(rs.getInt("ItemCount"));

    if (loadDetails.getBoolean("TAGS")) {
        try {
            group.setTags(this.getTagDAO().load(group.getGUID(), loadDetails.getString("USERDN"), true));
        } catch (Exception e) {
            dataLogger.error("Error loading tags for group: " + e.getMessage());
        }
    }

    group.setActive(rs.getBoolean("Active"));
    if (loadDetails.getBoolean("HISTORY")) {
        try {
            group.setCreatedDate(rs.getTimestamp("CreatedDate"));
        } catch (SQLException sqe) {
            dataLogger.debug("Error loading CreatedDate: " + sqe.getMessage());
        }
        group.setCreatedBy(rs.getString("CreatedBy"));
        try {
            group.setModifiedDate(rs.getTimestamp("ModifiedDate"));
        } catch (SQLException sqe) {
            dataLogger.debug("Error loading ModifiedDate: " + sqe.getMessage());
        }
        group.setModifiedBy(rs.getString("ModifiedBy"));
    }

    if (loadDetails.getBoolean("ITEMS")) {
        int referenceId = 0;
        try {
            referenceId = Integer.parseInt(loadDetails.getString("REFERENCEID"));
        } catch (Exception e) {
            dataLogger.debug("Error parsing ReferenceId: " + e.getMessage());
        }
        try {
            group.setItems(
                    this.getItemDAO().load(group.getGUID(), true, "Group", group.getObjectType(), referenceId,
                            loadDetails.getString("ITEMS_STARTDATE"), loadDetails.getString("ITEMS_ENDDATE")));
        } catch (Exception e) {
            dataLogger.error("Error loading items: " + e.getMessage());
        }
    }

    if (StringUtils.equalsIgnoreCase(group.getType(), "Election") && loadDetails.getBoolean("VOTES")) {
        /* Load the votes for this election group */
        try {
            TreeMap<Integer, VoteBean> votesCast = this.voteDAO.load(group.getGUID());
            group.setVotesCast(votesCast);
            group.setCastVoteCount(votesCast.keySet().size());
        } catch (Exception e) {
            dataLogger.error("Error loading votes cast: " + e.getMessage());
        }
        try {
            TreeMap<Integer, Integer> eligibleVotes = this.voteDAO.loadEligible(group.getGUID());
            group.setEligibleVoteCount(eligibleVotes.keySet().size());
        } catch (Exception e) {
            dataLogger.error("Error loading eligible vote count: " + e.getMessage());
        }
    }
    if (StringUtils.equalsIgnoreCase(group.getType(), "Election") && loadDetails.getBoolean("CANDIDATES")) {
        // * Load the candidates for this election group */
        try {
            Collection<CandidateBean> candidates = this.candidateDAO.load(group.getGUID(), loadDetails);
            group.setCandidates(candidates);
        } catch (Exception e) {
            dataLogger.error("Error loading votes cast: " + e.getMessage());
        }
    }

    if (loadDetails.getBoolean("IDENTITIES")) {

        boolean loadIdentities = false;
        if (StringUtils.equalsIgnoreCase(group.getObjectType(), "Organisations")
                || StringUtils.equalsIgnoreCase(group.getObjectType(), "Members")) {
            loadIdentities = true;
        }
        if (loadIdentities && group.getItems() != null) {
            group.setItems(loadIdentities(group.getItems()));
        }
    }

    if (loadDetails.getBoolean("MEMO")) {
        try {
            group.setMemo(this.getMemoDAO().load(group.getGUID(), loadDetails.getBoolean("MEMO_FULL")));
        } catch (Exception e) {
            dataLogger.error("Error loading memos: " + e.getMessage());
        }
    }

    if (loadDetails.getBoolean("CREATED")) {
        UserBean user = new UserBean();
        user.setDN(rs.getString("CreatedBy"));
        user.setPreferredName(rs.getString("CreatedFirstName"));
        user.setLastName(rs.getString("CreatedLastName"));
        group.setCreatedUser(user);
    }
    if (loadDetails.getBoolean("MODIFIED")) {
        UserBean user = new UserBean();
        user.setDN(rs.getString("ModifiedBy"));
        user.setPreferredName(rs.getString("ModifiedFirstName"));
        user.setLastName(rs.getString("ModifiedLastName"));
        group.setModifiedUser(user);
    }
    return group;
}

From source file:com.sfs.whichdoctor.analysis.GroupAnalysisDAOImpl.java

/**
 * Load reference objects./*from   w w w. ja  v a2  s.  c o  m*/
 *
 * @param referenceGUIDs the reference gui ds
 * @param loadDetails the load details
 * @param user the user
 * @param groupClass the group class
 *
 * @return the tree map< integer, object>
 *
 * @throws WhichDoctorSearchDaoException the which doctor search dao
 * exception
 */
private TreeMap<Integer, Object> loadReferenceObjects(final TreeMap<Integer, ArrayList<Integer>> referenceGUIDs,
        final BuilderBean loadDetails, final UserBean user, final String groupClass)
        throws WhichDoctorSearchDaoException {

    TreeMap<Integer, Object> referenceObjects = new TreeMap<Integer, Object>();

    Collection<Object> searchGUIDs = new ArrayList<Object>();

    for (Integer referenceGUID : referenceGUIDs.keySet()) {
        searchGUIDs.add(String.valueOf(referenceGUID));
    }

    dataLogger
            .info("Loading reference objects for: " + groupClass + ",  with a size of: " + searchGUIDs.size());

    if (StringUtils.equalsIgnoreCase(groupClass, "people")
            || StringUtils.equalsIgnoreCase(groupClass, "members")) {
        referenceObjects = loadPeople(searchGUIDs, loadDetails, user);
    }

    if (StringUtils.equalsIgnoreCase(groupClass, "organisations")) {
        referenceObjects = loadOrganisations(searchGUIDs, loadDetails, user);
    }

    if (StringUtils.equalsIgnoreCase(groupClass, "debits")) {
        referenceObjects = loadDebits(searchGUIDs, loadDetails, user);
    }

    if (StringUtils.equalsIgnoreCase(groupClass, "credits")) {
        referenceObjects = loadCredits(searchGUIDs, loadDetails, user);
    }

    if (StringUtils.equalsIgnoreCase(groupClass, "receipts")) {
        referenceObjects = loadReceipts(searchGUIDs, loadDetails, user);
    }

    if (StringUtils.equalsIgnoreCase(groupClass, "reimbursements")) {
        referenceObjects = loadReimbursements(searchGUIDs, loadDetails, user);
    }

    if (StringUtils.equalsIgnoreCase(groupClass, "rotations")) {
        referenceObjects = loadRotations(searchGUIDs, loadDetails, user);
    }

    return referenceObjects;
}

From source file:com.sfs.dao.GadgetPreferencesDAOImpl.java

/**
 * Converts the key/value TreeMap into a string for persisting to the
 * data-store./*from  w w  w.  jav  a  2 s  . co  m*/
 *
 * @param keyValues the key values
 *
 * @return the string
 */
private String writeGadgetPreferences(final TreeMap<String, String> keyValues) {
    StringBuffer userPrefs = new StringBuffer();

    if (keyValues != null) {
        for (String key : keyValues.keySet()) {
            String value = keyValues.get(key);
            // Add key and value to StringBuffer
            userPrefs.append(key);
            userPrefs.append("=");
            userPrefs.append(value);
            userPrefs.append("\n");
        }
    }
    return userPrefs.toString();
}

From source file:org.opentaps.gwt.messages.GwtLabelsGeneratorContainer.java

/**
 * Writes gwt locale properties, generate locale properties files base default GWT label properties
 * @param defaultGwtLabelDefinitionsMaps a <code>Map</code> of gwt label definitions
 * @param locale a <code>String</code> value of Locale
 * @param gwtPropertiesDir a <code>String</code> value
 * @param gwtLabelFileName a <code>String</code> value
 *//*  w w  w. j  a  v a2  s. c om*/
private void writeGwtLocaleProperties(TreeMap<String, GwtLabelDefinition> defaultGwtLabelDefinitionsMaps,
        String locale, String gwtPropertiesDir, String gwtLabelFileName) throws IOException {
    // write the localized properties files
    StringBuffer stringBuffer = new StringBuffer();
    for (String key : defaultGwtLabelDefinitionsMaps.keySet()) {
        // check the label has the same signature as the default label
        GwtLabelDefinition defaultLabel = defaultGwtLabelDefinitionsMaps.get(key);
        String localizedString = UtilProperties.getMessage(
                getResourceNameFromPath(defaultLabel.getPropertiesFile()), defaultLabel.getOriginKey(),
                new Locale(locale));
        if (UtilValidate.isNotEmpty(localizedString)) {
            if (!key.startsWith("_")) {
                // save the list of parameters that were parsed from the label text
                // and that will be used as the message interface method parameters
                List<String> parameters = new ArrayList<String>();
                localizedString = formatGwtLabel(localizedString, parameters);
                // replace extra quote character which add by UtilProperties
                localizedString = localizedString.replace("''{", "'{");
                localizedString = localizedString.replace("}''", "}'");
                localizedString = localizedString.replace("'''{", "''{");
                localizedString = localizedString.replace("}'''", "}''");
            }
            stringBuffer.append(key).append(" = ").append(localizedString).append("\n");
        }
    }
    String outGwtLabelPropertiesFile = gwtPropertiesDir + gwtLabelFileName + ".properties";
    if (!locale.equals(DEFAULT_LOCALE)) {
        outGwtLabelPropertiesFile = gwtPropertiesDir + gwtLabelFileName + "_" + locale + ".properties";
    }
    File propertiesFile = new File(outGwtLabelPropertiesFile);
    FileUtils.writeStringToFile(propertiesFile, stringBuffer.toString(), "UTF-8");
}

From source file:nl.uva.sne.disambiguators.BabelNet.java

private Set<Term> babelNetDisambiguation(String language, String lemma, Set<String> ngarms) {
    if (ngarms.isEmpty()) {
        return null;
    }//w  w w.  ja  v  a 2 s.  c  o  m
    if (ngarms.size() == 1 && ngarms.iterator().next().length() <= 1) {
        return null;
    }

    HashMap<String, Double> idsMap = new HashMap<>();
    Map<String, Term> termMap = new HashMap<>();
    Set<Term> terms = new HashSet<>();
    int count = 0;
    int breaklimit = 1000;
    int oneElementlimit = 65;
    int difflimit = 60;
    Double persent;
    for (String n : ngarms) {
        if (n.length() <= 1) {
            continue;
        }
        count++;
        if (idsMap.size() == 1 && count > oneElementlimit) {
            //                Double score = idsMap.values().iterator().next();
            //                if (score >= 10) {
            break;
            //                }
        }

        if ((count % 2) == 0 && idsMap.size() >= 2 && count > difflimit) {
            ValueComparator bvc = new ValueComparator(idsMap);
            TreeMap<String, Double> sorted_map = new TreeMap(bvc);
            sorted_map.putAll(idsMap);
            Iterator<String> iter = sorted_map.keySet().iterator();
            Double first = idsMap.get(iter.next());
            Double second = idsMap.get(iter.next());

            persent = first / (first + second);
            if (persent > 0.65) {
                break;
            }
        }
        if (count > breaklimit) {
            break;
        }

        String clearNg = n.replaceAll("_", " ");
        if (clearNg == null) {
            continue;
        }
        if (clearNg.startsWith(" ")) {
            clearNg = clearNg.replaceFirst(" ", "");
        }
        if (clearNg.endsWith(" ")) {
            clearNg = clearNg.substring(0, clearNg.length() - 1);
        }

        Pair<Term, Double> termPair = null;
        try {
            termPair = babelNetDisambiguation(language, lemma, clearNg);
        } catch (Exception ex) {
            if (ex.getMessage() != null && ex.getMessage().contains("Your key is not valid")) {
                try {
                    termPair = babelNetDisambiguation(language, lemma, clearNg);
                } catch (Exception ex1) {
                    //                        Logger.getLogger(BabelNet.class.getName()).log(Level.WARNING, ex1, null);
                }
            } else {
                Logger.getLogger(SemanticUtils.class.getName()).log(Level.WARNING, null, ex);
            }
        }
        if (termPair != null) {
            termMap.put(termPair.first.getUID(), termPair.first);
            Double score;
            if (idsMap.containsKey(termPair.first.getUID())) {
                score = idsMap.get(termPair.first.getUID());
                //                    score++;
                score += termPair.second;
            } else {
                //                    score = 1.0;
                score = termPair.second;
            }
            idsMap.put(termPair.first.getUID(), score);
        }
    }
    if (!idsMap.isEmpty()) {
        ValueComparator bvc = new ValueComparator(idsMap);
        TreeMap<String, Double> sorted_map = new TreeMap(bvc);
        sorted_map.putAll(idsMap);
        count = 0;
        Double firstScore = idsMap.get(sorted_map.firstKey());
        terms.add(termMap.get(sorted_map.firstKey()));
        idsMap.remove(sorted_map.firstKey());
        for (String tvID : sorted_map.keySet()) {
            if (count >= 1) {
                Double secondScore = idsMap.get(tvID);
                persent = secondScore / (firstScore + secondScore);
                if (persent > 0.2) {
                    terms.add(termMap.get(tvID));
                }
                if (count >= 2) {
                    break;
                }
            }
            count++;
        }
        return terms;
    }
    return null;
}

From source file:jackpal.androidterm.TermPreferences.java

private void setAppPickerList() {
    PackageManager pm = this.getApplicationContext().getPackageManager();
    final List<ApplicationInfo> installedAppList = pm.getInstalledApplications(0);
    final TreeMap<String, String> items = new TreeMap<>();
    for (ApplicationInfo app : installedAppList) {
        Intent intent = pm.getLaunchIntentForPackage(app.packageName);
        if (intent != null)
            items.put(app.loadLabel(pm).toString(), app.packageName);
    }/*from  w  w  w  .ja  va 2 s.  c  om*/
    List<String> list = new ArrayList<>(items.keySet());
    final String labels[] = list.toArray(new String[list.size()]);
    list = new ArrayList<>(items.values());
    final String packageNames[] = list.toArray(new String[list.size()]);

    String id = "external_app_package_name";
    ListPreference packageName = (ListPreference) getPreferenceScreen().findPreference(id);
    packageName.setEntries(labels);
    packageName.setEntryValues(packageNames);
}

From source file:org.alfresco.web.forms.xforms.SchemaUtil.java

public static TreeMap<String, TreeSet<XSTypeDefinition>> buildTypeTree(final XSModel schema) {
    final TreeMap<String, TreeSet<XSTypeDefinition>> result = new TreeMap<String, TreeSet<XSTypeDefinition>>();
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("buildTypeTree " + schema);
    // build the type tree for complex types
    final XSNamedMap types = schema.getComponents(XSConstants.TYPE_DEFINITION);
    for (int i = 0; i < types.getLength(); i++) {
        final XSTypeDefinition t = (XSTypeDefinition) types.item(i);
        if (t.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) {
            final XSComplexTypeDefinition type = (XSComplexTypeDefinition) t;
            SchemaUtil.buildTypeTree(type, new TreeSet<XSTypeDefinition>(TYPE_EXTENSION_SORTER), result);
        }/*from   w  ww . j  a  v  a 2 s  .com*/
    }

    // build the type tree for simple types
    for (int i = 0; i < types.getLength(); i++) {
        final XSTypeDefinition t = (XSTypeDefinition) types.item(i);
        if (t.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) {
            SchemaUtil.buildTypeTree((XSSimpleTypeDefinition) t,
                    new TreeSet<XSTypeDefinition>(TYPE_EXTENSION_SORTER), result);
        }
    }

    // print out type hierarchy for debugging purposes
    if (LOGGER.isDebugEnabled()) {
        for (String typeName : result.keySet()) {
            TreeSet<XSTypeDefinition> descendents = result.get(typeName);
            LOGGER.debug(">>>> for " + typeName + " Descendants=\n ");
            Iterator<XSTypeDefinition> it = descendents.iterator();
            while (it.hasNext()) {
                XSTypeDefinition desc = it.next();
                LOGGER.debug("      " + desc.getName());
            }
        }
    }
    return result;
}

From source file:net.spfbl.core.Analise.java

protected static void dumpClusterTLD(StringBuilder builder) {
    TreeMap<String, Short[]> map = getClusterMap();
    for (String token : map.keySet()) {
        Short[] dist = map.get(token);
        int spam = dist[1];
        if (spam > 512) {
            int ham = dist[0];
            float total = ham + spam;
            float reputation = spam / total;
            if (reputation > CLUSTER_RED) {
                if (Domain.isOfficialTLD(token)) {
                    if (!Block.contains(token)) {
                        builder.append(token);
                        builder.append(' ');
                        builder.append(ham);
                        builder.append(' ');
                        builder.append(spam);
                        builder.append('\n');
                    }//from   ww  w . j a v  a 2s.c  om
                }
            }
        }
    }
}

From source file:net.spfbl.core.Analise.java

protected static void dumpClusterCPF(StringBuilder builder) {
    TreeMap<String, Short[]> map = getClusterMap();
    for (String token : map.keySet()) {
        Short[] dist = map.get(token);
        int spam = dist[1];
        if (spam > 512) {
            int ham = dist[0];
            float total = ham + spam;
            float reputation = spam / total;
            if (reputation > CLUSTER_RED) {
                if (Owner.isOwnerCPF(token)) {
                    if (!Block.contains(token)) {
                        builder.append(token);
                        builder.append(' ');
                        builder.append(ham);
                        builder.append(' ');
                        builder.append(spam);
                        builder.append('\n');
                    }/* w  ww .j av  a2s .  c  o  m*/
                }
            }
        }
    }
}

From source file:net.spfbl.core.Analise.java

protected static void dumpClusterCNPJ(StringBuilder builder) {
    TreeMap<String, Short[]> map = getClusterMap();
    for (String token : map.keySet()) {
        Short[] dist = map.get(token);
        int spam = dist[1];
        if (spam > 512) {
            int ham = dist[0];
            float total = ham + spam;
            float reputation = spam / total;
            if (reputation > CLUSTER_RED) {
                if (Owner.isOwnerCNPJ(token)) {
                    if (!Block.contains(token)) {
                        builder.append(token);
                        builder.append(' ');
                        builder.append(ham);
                        builder.append(' ');
                        builder.append(spam);
                        builder.append('\n');
                    }//  w w  w.j  a va2s  .c  om
                }
            }
        }
    }
}