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:api.wiki.WikiNameApi2.java

@Override
public void Search(PeopleNameOption option, ProgressCallback callback) {
    if (supports(option)) {
        String title = cultures.get(option.genre).replaceAll("\\s+", "_");
        TreeMap<String, String> values = getCategoryOption(title);

        if (containsGenderKey(values)) { // WE HAVE A GENDER KEY!
            for (String potentialGenderKey : values.values()) {
                if (option.gender == GenderOption.EITHER && (containeAnyKey(potentialGenderKey))) {
                    processAll(values.keySet(), option, callback);
                } else if (option.gender == GenderOption.AMBIGOUS && containsUniKey(potentialGenderKey)
                        || option.gender == GenderOption.FEMALE && containsFemaleKey(potentialGenderKey)
                        || option.gender == GenderOption.MALE && containsMaleKey(potentialGenderKey)) {
                    processSpecific(potentialGenderKey, option, callback);
                }/* ww  w  .  ja  va  2 s  .c o m*/
            }
        } else {
            System.out.println("preforming deep search");
        }
    }
}

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  www. ja v  a 2 s.co m*/
        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:org.talend.dataquality.record.linkage.ui.composite.table.MatchRuleDataTable.java

/**
 * DOC xqliu Comment method "buildGroupSizeArray".
 * /*from   w w  w .j a v  a  2  s .co  m*/
 * @param groupSize2groupFrequency
 * @param minGroupSize
 */
private void initGroupSizeArray(TreeMap<Object, Long> groupSize2groupFrequency, int minGroupSize) {
    groupSizeList.clear();
    for (Object obj : groupSize2groupFrequency.keySet()) {
        int grpSize = Integer.valueOf(obj.toString());
        if (grpSize >= minGroupSize) {
            groupSizeList.add(grpSize);
        }
    }
    Collections.sort(groupSizeList, new Comparator<Integer>() {

        @Override
        public int compare(Integer o1, Integer o2) {
            return o1 - o2;
        }

    });
}

From source file:org.apache.hadoop.hive.ql.exec.ComputationBalancerReducer.java

void flushMCVlist(FSDataOutputStream out) throws Exception {

    out.writeBytes("MCVList\n");
    for (String _iter_outside_ : mcvList.keySet()) {
        TreeMap<String, Integer> _TreeMap = mcvList.get(_iter_outside_);
        out.writeBytes(_iter_outside_ + "\n");
        ToolBox _tb = new ToolBox();

        for (String _s_ : _TreeMap.keySet()) {
            _tb.push(_s_, _TreeMap.get(_s_));
        }/*from  ww  w. j  a  va2 s .c o m*/

        if (_TreeMap.keySet().size() > 256) {

            _tb.compact(_TreeMap, ToolBox.SortMethod.DescendSort, Integer.valueOf(256));
        } else {
            _tb.descendSort();
        }

        for (int idx = 0; idx < _tb.getCapacity(); idx++) {
            double _tmp_frac_ = ((double) _tb.getIntegeAtIdx(idx) / (double) _sampledRecordNumber_);
            out.writeBytes(
                    _iter_outside_ + ToolBox.hiveDelimiter + _tb.getStringAtIdx(idx) + ToolBox.hiveDelimiter
                            + _tb.getIntegeAtIdx(idx) + ToolBox.hiveDelimiter + _tmp_frac_ + "\n");
        }
    }

}

From source file:org.apache.camel.dataformat.bindy.BindyFixedLengthFactory.java

public String unbind(Map<String, Object> model) throws Exception {

    StringBuilder buffer = new StringBuilder();
    results = new HashMap<Integer, List>();

    for (Class clazz : models) {

        if (model.containsKey(clazz.getName())) {

            Object obj = model.get(clazz.getName());

            if (LOG.isDebugEnabled()) {
                LOG.debug("Model object: " + obj + ", class: " + obj.getClass().getName());
            }//w  ww . jav a2 s.c  om

            if (obj != null) {

                // Generate Fixed Length table
                // containing the positions of the fields
                generateFixedLengthPositionMap(clazz, obj);

            }
        }
    }

    // Convert Map<Integer, List> into List<List>
    TreeMap<Integer, List> sortValues = new TreeMap<Integer, List>(results);
    for (Integer key : sortValues.keySet()) {

        // Get list of values
        List<String> val = sortValues.get(key);
        String value = val.get(0);

        buffer.append(value);
    }

    return buffer.toString();
}

From source file:com.jsonstore.database.DatabaseSchema.java

public boolean equals(TreeMap<String, String> schema_compare) {
    if (schema_compare.size() != (this.nodes.size() + this.internalNodes.size())) {
        return false;
    }/*www .j a v  a2  s  . co m*/

    for (String key : schema_compare.keySet()) {
        String safeKey = JSONStoreUtil.getDatabaseSafeSearchFieldName(key);
        SearchFieldType type = null;

        if (this.safeNodes.containsKey(safeKey)) {
            type = this.nodes.get(safeKey);
            if (null == type) {
                type = this.safeNodes.get(safeKey);
            }
        } else {
            type = this.internalNodes.get(safeKey);
        }

        if ((type == null) || !type.getMappedType().equals(schema_compare.get(key))) {
            return false;
        }
    }

    return true;
}

From source file:monasca.persister.repository.cassandra.CassandraMetricRepo.java

@Override
public void addToBatch(MetricEnvelope metricEnvelope, String id) {
    Metric metric = metricEnvelope.metric;
    Map<String, Object> metaMap = metricEnvelope.meta;

    String tenantId = getMeta(TENANT_ID, metric, metaMap, id);
    String region = getMeta(REGION, metric, metaMap, id);
    String metricName = metric.getName();
    TreeMap<String, String> dimensions = metric.getDimensions() == null ? new TreeMap<String, String>()
            : new TreeMap<>(metric.getDimensions());

    StringBuilder sb = new StringBuilder(region).append(tenantId).append(metricName);

    Iterator<String> it = dimensions.keySet().iterator();
    while (it.hasNext()) {
        String k = it.next();/*w  w  w  .j  a v a  2  s . c  om*/
        sb.append(k).append(dimensions.get(k));
    }

    byte[] defIdSha = DigestUtils.sha(sb.toString());
    Sha1HashId defIdShaHash = new Sha1HashId(defIdSha);

    if (cluster.getMetricIdCache().getIfPresent(defIdShaHash.toHexString()) == null) {
        addDefinitionToBatch(defIdShaHash, metricName, dimensions, tenantId, region, id, metric.getTimestamp());
        batches.addMeasurementQuery(buildMeasurementInsertQuery(defIdShaHash, metric.getTimestamp(),
                metric.getValue(), metric.getValueMeta(), region, tenantId, metricName, dimensions, id));
    } else {
        metricCacheHitMeter.mark();
        batches.addMetricQuery(cluster.getMetricUpdateStmt().bind(retention,
                new Timestamp(metric.getTimestamp()), region, tenantId, metricName,
                getDimensionList(dimensions), new ArrayList<>(dimensions.keySet())));
        batches.addMeasurementQuery(buildMeasurementUpdateQuery(defIdShaHash, metric.getTimestamp(),
                metric.getValue(), metric.getValueMeta(), id));
    }

    metricCount++;
}

From source file:gsn.beans.StreamElement.java

public StreamElement(TreeMap<String, Serializable> output, DataField[] fields) {
    int nbFields = output.keySet().size();
    if (output.containsKey("timed"))
        nbFields--;//from w  w w .  j a  va  2 s  . c o  m
    String fieldNames[] = new String[nbFields];
    Byte fieldTypes[] = new Byte[nbFields];
    Serializable fieldValues[] = new Serializable[nbFields];
    TreeMap<String, Integer> indexedFieldNames = new TreeMap<String, Integer>(new CaseInsensitiveComparator());
    int idx = 0;

    long timestamp = System.currentTimeMillis();
    for (String key : output.keySet()) {
        Serializable value = output.get(key);

        if (key.equalsIgnoreCase("timed")) {
            timestamp = (Long) value;
            timestampProvided = true;
        } else {
            fieldNames[idx] = key;
            fieldValues[idx] = value;
            for (int i = 0; i < fields.length; i++) {
                if (fields[i].getName().equalsIgnoreCase(key))
                    fieldTypes[idx] = fields[i].getDataTypeID();
            }
            indexedFieldNames.put(key, idx);
            idx++;
        }
    }
    this.fieldNames = fieldNames;
    this.fieldTypes = fieldTypes;
    this.fieldValues = fieldValues;
    this.indexedFieldNames = indexedFieldNames;
    this.timeStamp = timestamp;
}

From source file:org.mda.bcb.tcgagsdata.create.ProcessFile.java

protected void countBarcodesAndGenes(TreeMap<File, String> theFiles) throws FileNotFoundException, IOException {
    M_BARCODES = 0;//from   www.  java  2s .co  m
    M_GENES = 0;
    TreeSet<String> genes = new TreeSet<>();
    for (File file : theFiles.keySet()) {
        long start = System.currentTimeMillis();
        int numOfCol = 0;
        try (BufferedReader br = new BufferedReader(new FileReader(file))) {
            // header
            String line = br.readLine();
            numOfCol = line.split("\t", -1).length;
            while (null != (line = br.readLine())) {

                genes.add(line.substring(0, line.indexOf("\t")));
            }
        }
        M_BARCODES = M_BARCODES + numOfCol;
        long finish = System.currentTimeMillis();
        System.out.println("file " + ((finish - start) / 1000.0) + " seconds");
    }
    M_GENES = genes.size();
}

From source file:com.compomics.pride_asa_pipeline.core.logic.modification.PTMMapper.java

public PtmSettings removeDuplicateMasses(PtmSettings modProfile, double precursorMassAcc) {
    TreeMap<Double, String> massToModMap = new TreeMap<>();
    for (String aModName : modProfile.getAllModifications()) {
        massToModMap.put(modProfile.getPtm(aModName).getMass(), aModName);
    }//w w  w  . j av a  2 s.c o m
    double previousMass = massToModMap.firstKey() - precursorMassAcc;
    for (Double aModMass : massToModMap.keySet()) {
        if (Math.abs(aModMass - previousMass) < precursorMassAcc) {
            String originalModification = massToModMap.get(previousMass);
            String duplicateModification = massToModMap.get(aModMass);
            if (originalModification != null) {
                System.out.println("Duplicate masses found : " + originalModification + "(" + previousMass + ")"
                        + " vs " + duplicateModification + "(" + aModMass + ")");
                if (modProfile.getFixedModifications().contains(duplicateModification)) {
                    modProfile.removeFixedModification(duplicateModification);
                } else {
                    modProfile.removeVariableModification(duplicateModification);
                }
            }
        }
        previousMass = aModMass;
    }

    return modProfile;
}