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.norconex.importer.handler.tagger.impl.TitleGeneratorTagger.java

private String getCarrotTitle(String text) throws IOException {
    // Use Carrot2 to try get an OK title.
    int maxSectionSize = Math.max(MIN_SECTION_MAX_BREAK_SIZE, text.length() / NUM_SECTIONS);

    if (LOG.isDebugEnabled()) {
        LOG.debug("Content-length: " + text.length() + "; maxSectionSize: " + maxSectionSize);
    }//w w w . j av a 2 s  .  c o m

    List<Document> sections = new ArrayList<Document>();
    try (TextReader reader = new TextReader(new StringReader(text), maxSectionSize)) {
        String section = null;
        while ((section = reader.readText()) != null) {
            sections.add(new Document(section));
        }
    }

    final ProcessingResult byDomainClusters = controller.process(sections, null, STCClusteringAlgorithm.class);
    final List<Cluster> clusters = byDomainClusters.getClusters();

    if (LOG.isDebugEnabled()) {
        LOG.debug("Title generator clusters= " + clusters);
    }
    TreeMap<Double, String> titles = new TreeMap<>();
    for (Cluster cluster : clusters) {
        titles.put(cluster.getScore(), cluster.getLabel());
        if (LOG.isDebugEnabled()) {
            LOG.info(cluster.getScore() + "=" + cluster.getLabel());
        }
    }
    Entry<Double, String> titleEntry = titles.lastEntry();
    if (titleEntry == null || titleEntry.getKey() < MIN_ACCEPTABLE_SCORE) {
        return null;
    }
    return titleEntry.getValue();
}

From source file:hydrograph.ui.engine.ui.converter.impl.InputFileDelimitedUiConverter.java

@Override
protected Map<String, String> getRuntimeProperties() {
    LOGGER.debug("Generating Runtime Properties for -{}", componentName);
    TreeMap<String, String> runtimeMap = null;
    TypeProperties typeProperties = ((TextFileDelimited) typeBaseComponent).getRuntimeProperties();
    if (typeProperties != null) {
        runtimeMap = new TreeMap<>();
        for (Property runtimeProperty : typeProperties.getProperty()) {
            runtimeMap.put(runtimeProperty.getName(), runtimeProperty.getValue());
        }//from   w  ww. j ava  2 s  .  c  om
    }
    return runtimeMap;
}

From source file:com.heliosapm.tsdblite.metric.Metric.java

/**
 * Creates a new Metric//from  www.  j  av  a 2s . c om
 * @param node The JSON node
 * @param hashCode The long hash code
 */
Metric(final JsonNode node, final long hashCode) {
    metricName = node.get("metric").textValue();
    final JsonNode tags = node.get("tags");
    if (tags != null) {
        final TreeMap<String, String> tmp = new TreeMap<String, String>(TagKeySorter.INSTANCE);
        for (final Iterator<String> keyIter = tags.fieldNames(); keyIter.hasNext();) {
            final String key = keyIter.next();
            tmp.put(key.trim(), tags.get(key).textValue().trim());
        }
        this.tags = tmp;
    } else {
        this.tags = new TreeMap<String, String>();
    }
    this.hashCode = hashCode;
}

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);
    }/*from  w  w  w  . j a  v a  2  s .com*/
    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;
}

From source file:cn.teamlab.wg.framework.util.csv.CsvWriter.java

/**
 * Bean?CSV?/*from  ww  w.  jav a  2 s.co  m*/
 * Bean@CsvPropAnno(index = ?)
 * @param objList
 * @return
 * @throws NoSuchMethodException 
 * @throws InvocationTargetException 
 * @throws IllegalAccessException 
 */
public static String bean2Csv(List<?> objList) throws Exception {
    if (objList == null || objList.size() == 0) {
        return "";
    }
    TreeMap<Integer, CsvFieldBean> map = new TreeMap<Integer, CsvFieldBean>();
    Object bean0 = objList.get(0);
    Class<?> clazz = bean0.getClass();

    PropertyDescriptor[] arr = org.springframework.beans.BeanUtils.getPropertyDescriptors(clazz);
    for (PropertyDescriptor p : arr) {
        String fieldName = p.getName();
        Field field = FieldUtils.getDeclaredField(clazz, fieldName, true);
        if (field == null) {
            continue;
        }

        boolean isAnno = field.isAnnotationPresent(CsvFieldAnno.class);
        if (isAnno) {
            CsvFieldAnno anno = field.getAnnotation(CsvFieldAnno.class);
            int idx = anno.index();
            map.put(idx, new CsvFieldBean(idx, anno.title(), fieldName));
        }
    }

    // CSVBuffer
    StringBuffer buff = new StringBuffer();

    // ???
    boolean withTitle = clazz.isAnnotationPresent(CsvTitleAnno.class);
    // ??csv
    if (withTitle) {
        StringBuffer titleBuff = new StringBuffer();
        for (int key : map.keySet()) {
            CsvFieldBean fieldBean = map.get(key);
            titleBuff.append(Letters.QUOTE).append(fieldBean.getTitle()).append(Letters.QUOTE);
            titleBuff.append(Letters.COMMA);
        }
        buff.append(StringUtils.chop(titleBuff.toString()));
        buff.append(Letters.LF);
        titleBuff.setLength(0);
    }

    for (Object o : objList) {
        StringBuffer tmpBuff = new StringBuffer();

        for (int key : map.keySet()) {
            CsvFieldBean fieldBean = map.get(key);

            Object val = BeanUtils.getProperty(o, fieldBean.getFieldName());
            if (val != null) {
                tmpBuff.append(Letters.QUOTE).append(val).append(Letters.QUOTE);
            } else {
                tmpBuff.append(StringUtils.EMPTY);
            }
            tmpBuff.append(Letters.COMMA);
        }

        buff.append(StringUtils.chop(tmpBuff.toString()));
        buff.append(Letters.LF);
        tmpBuff.setLength(0);
    }

    return buff.toString();
}

From source file:com.amazonaws.services.sns.util.SignatureChecker.java

private TreeMap<String, String> subscribeMessageValues(Map<String, String> parsedMessage) {
    TreeMap<String, String> signables = new TreeMap<String, String>();
    String[] keys = { SUBSCRIBE_URL, MESSAGE, MESSAGE_ID, TYPE, TIMESTAMP, TOKEN, TOPIC };
    for (String key : keys) {
        if (parsedMessage.containsKey(key)) {
            signables.put(key, parsedMessage.get(key));
        }//from   w  ww .j a  va2  s . c  om
    }
    return signables;
}

From source file:hydrograph.ui.engine.ui.converter.impl.OutputDBUpdateUiConverter.java

@Override
protected Map<String, String> getRuntimeProperties() {
    LOGGER.debug("Generating Runtime Properties for -{}", componentName);
    TreeMap<String, String> runtimeMap = null;
    TypeProperties typeProperties = ((JdbcUpdate) typeBaseComponent).getRuntimeProperties();
    if (typeProperties != null) {
        runtimeMap = new TreeMap<>();
        for (Property runtimeProperty : typeProperties.getProperty()) {
            runtimeMap.put(runtimeProperty.getName(), runtimeProperty.getValue());
        }//  w ww.ja va  2  s  .c o m
    }
    return runtimeMap;
}

From source file:hydrograph.ui.engine.ui.converter.impl.OutputFileDelimitedUiConverter.java

@Override
protected Map<String, String> getRuntimeProperties() {
    LOGGER.debug("Fetching runtime properties for -", componentName);
    TreeMap<String, String> runtimeMap = null;
    TypeProperties typeProperties = ((TextFileDelimited) typeBaseComponent).getRuntimeProperties();
    if (typeProperties != null) {
        runtimeMap = new TreeMap<>();
        for (Property runtimeProperty : typeProperties.getProperty()) {
            runtimeMap.put(runtimeProperty.getName(), runtimeProperty.getValue());
        }//from   w  w w .  j a va 2s.  com
    }
    return runtimeMap;
}

From source file:hydrograph.ui.engine.ui.converter.impl.InputRedshiftUiConverter.java

@Override
protected Map<String, String> getRuntimeProperties() {
    LOGGER.debug("Generating Runtime Properties for -{}", componentName);
    TreeMap<String, String> runtimeMap = null;
    TypeProperties typeProperties = ((Redshift) typeBaseComponent).getRuntimeProperties();
    if (typeProperties != null) {
        runtimeMap = new TreeMap<>();
        for (Property runtimeProperty : typeProperties.getProperty()) {
            runtimeMap.put(runtimeProperty.getName(), runtimeProperty.getValue());
        }/* w ww  .j av  a2 s  .  c om*/
    }
    return runtimeMap;
}

From source file:hydrograph.ui.engine.ui.converter.impl.OutputHiveParquetUiConverter.java

@Override
protected Map<String, String> getRuntimeProperties() {
    LOGGER.debug("Fetching runtime properties for -", componentName);
    TreeMap<String, String> runtimeMap = null;
    TypeProperties typeProperties = ((ParquetHiveFile) typeBaseComponent).getRuntimeProperties();
    if (typeProperties != null) {
        runtimeMap = new TreeMap<>();
        for (Property runtimeProperty : typeProperties.getProperty()) {
            runtimeMap.put(runtimeProperty.getName(), runtimeProperty.getValue());
        }/* w w  w.j  av  a2s .c  o m*/
    }
    return runtimeMap;
}