Example usage for java.util Map values

List of usage examples for java.util Map values

Introduction

In this page you can find the example usage for java.util Map values.

Prototype

Collection<V> values();

Source Link

Document

Returns a Collection view of the values contained in this map.

Usage

From source file:com.adobe.acs.tools.csv.impl.Column.java

public static Map<String, Column> getColumns(final String[] row, final String multiDelimiter,
        final String[] ignoreProperties, final String[] requiredProperties) throws CsvException {
    final Map<String, Column> map = new HashMap<String, Column>();

    for (int i = 0; i < row.length; i++) {
        final Column col = new Column(row[i], i);

        col.setIgnore(ArrayUtils.contains(ignoreProperties, col.getPropertyName()));
        col.setMultiDelimiter(multiDelimiter);

        map.put(col.getPropertyName(), col);
    }/*from ww w .  j  av a2 s .  c o m*/

    final List<String> missingRequiredProperties = hasRequiredFields(map.values(), requiredProperties);

    if (!missingRequiredProperties.isEmpty()) {
        throw new CsvException(
                "Could not find required columns in CSV: " + StringUtils.join(missingRequiredProperties, ", "));
    }

    return map;
}

From source file:com.davis.ddf.crs.utils.CheckUtil.java

public static List<CRSEndpointResponse> checkForResults(Date start, Date end, String bottomRight,
        String topLeft, String queryString, Map<String, CRSEndpointResponse> cannedResponses) {
    List<CRSEndpointResponse> result = new ArrayList<>();
    String latSegments[] = StringUtils.split(topLeft);
    String lngSegments[] = StringUtils.split(bottomRight);
    double topLeftLat = Double.parseDouble(latSegments[0]);

    double topLeftLng = Double.parseDouble(latSegments[1]);

    double bottomRightLat = Double.parseDouble(lngSegments[0]);

    double bottomRightLng = Double.parseDouble(lngSegments[1]);

    for (CRSEndpointResponse e : cannedResponses.values()) {
        if (checkResultForMatching(topLeftLat, topLeftLng, bottomRightLat, bottomRightLng, queryString, start,
                end, e)) {//from  ww w  . j a v  a2s . c  o m
            result.add(e);
        }
    }

    return result;
}

From source file:it.units.malelab.ege.util.Utils.java

public static <T> T selectRandom(Map<T, Double> options, Random random) {
    double sum = 0;
    for (Double rate : options.values()) {
        sum = sum + rate;//from w w  w  . ja  va  2s.c o m
    }
    double d = random.nextDouble() * sum;
    for (Map.Entry<T, Double> option : options.entrySet()) {
        if (d < option.getValue()) {
            return option.getKey();
        }
        d = d - option.getValue();
    }
    return (T) options.keySet().toArray()[0];
}

From source file:com.turbospaces.spaces.tx.TransactionModificationContext.java

private static void notifyByTemplate(final Map<EntryKeyLockQuard, WriteTakeEntry> map,
        final SpaceNotificationListener listener, final CacheStoreEntryWrapper template,
        final SpaceStore memoryManager, final boolean returnAsBytes) {
    if (!CollectionUtils.isEmpty(map))
        for (final WriteTakeEntry entry : map.values())
            if (entry.getObj().getClass()
                    .isAssignableFrom(template.getPersistentEntity().getOriginalPersistentEntity().getType())) {
                Object[] templatePropertyValues = template.asPropertyValuesArray();
                Object[] entryPropertyValues = entry.getPropertyValues();

                if (SpaceUtility.macthesByPropertyValues(templatePropertyValues, entryPropertyValues)) {
                    assert entry.getObj() != null;
                    memoryManager.getSpaceConfiguration().getListeningExecutorService().execute(new Runnable() {
                        @Override
                        public void run() {
                            listener.handleNotification(
                                    returnAsBytes ? entry.getPointer().getSerializedDataBuffer()
                                            : entry.getObj(),
                                    entry.getSpaceOperation());
                        }//from   w  w  w.j  a  v  a 2  s .c  o m
                    });
                }
            }
}

From source file:contestTabulation.Main.java

private static void updateRegistrations(Level level, Map<String, School> schools) {
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

    for (School school : schools.values()) {
        Filter schoolNameFilter = new FilterPredicate("schoolName", FilterOperator.EQUAL, school.getName());
        Filter schoolLevelFilter = new FilterPredicate("schoolLevel", FilterOperator.EQUAL, level.toString());
        Filter regTypeFilter = new FilterPredicate("registrationType", FilterOperator.EQUAL, "coach");

        Query query = new Query("registration")
                .setFilter(CompositeFilterOperator.and(schoolNameFilter, schoolLevelFilter, regTypeFilter));
        List<Entity> registrations = datastore.prepare(query).asList(FetchOptions.Builder.withDefaults());

        if (registrations.size() > 0) {
            Entity registration = registrations.get(0);
            for (Entry<Test, Integer> numTest : school.getNumTests().entrySet()) {
                registration.setProperty(numTest.getKey().toString(), numTest.getValue());
            }//w  w w.  j a  va 2s .  co  m
            datastore.put(registration);
        }
    }
}

From source file:de.christianseipl.utilities.maputils.MapMath.java

/**
 * Berechnet die Summe der Werte in der Map
 * /* w  w  w  . ja  v  a2s  .c  o  m*/
 * @param <K> ein beliebiger Objekttyp
 * @param _map
 * @return die Summe der Werte
 */
public static <K> double sumValues(Map<? extends K, ? extends Number> _map) {
    return CollectionsMath.sum(_map.values());
}

From source file:com.adobe.acs.tools.csv_asset_importer.impl.Column.java

public static Map<String, Column> getColumns(final String[] row, final String multiDelimiter,
        final String[] ignoreProperties, final String[] requiredProperties) throws CsvAssetImportException {
    final Map<String, Column> map = new HashMap<String, Column>();

    for (int i = 0; i < row.length; i++) {
        final Column col = new Column(row[i], i);

        col.setIgnore(ArrayUtils.contains(ignoreProperties, col.getPropertyName()));
        col.setMultiDelimiter(multiDelimiter);

        map.put(col.getPropertyName(), col);
    }//  w  ww  .  j a v  a 2  s .c  o m

    final List<String> missingRequiredProperties = hasRequiredFields(map.values(), requiredProperties);

    if (!missingRequiredProperties.isEmpty()) {
        throw new CsvAssetImportException(
                "Could not find required columns in CSV: " + StringUtils.join(missingRequiredProperties, ", "));
    }

    return map;
}

From source file:com.feilong.core.util.AggregateUtil.java

/**
 * <code>map</code>,keys,? value ?.
 * /*from www .j a v  a2  s. co  m*/
 * <h3>:</h3>
 * <blockquote>
 * 
 * <pre class="code">
 * Map{@code <String, Integer>} map = new HashMap{@code <String, Integer>}();
 * 
 * map.put("a", 3007);
 * map.put("b", 3001);
 * map.put("c", 3002);
 * map.put("d", 3003);
 * map.put("e", 3004);
 * map.put("f", 3005);
 * map.put("g", -1005);
 * 
 * LOGGER.info("" + AggregateUtil.getMinValue(map, "a", "b", "d", "g", "m"));
 * </pre>
 * 
 * <b>:</b>
 * -1005
 * 
 * </blockquote>
 * 
 * @param <K>
 *            the key type
 * @param <T>
 *            the generic type
 * @param map
 *            map
 * @param keys
 *            key
 * @return  <code>map</code> nullempty, null;<br>
 *          <code>keys</code> nullempty,<code>map</code>value?<br>
 *          key?map key?,mapkey,warn level log<br>
 *          keys key ? map  ,null
 * @see MapUtil#getSubMap(Map, Object...)
 * @see java.util.Collections#min(Collection)
 */
@SafeVarargs
public static <K, T extends Number & Comparable<? super T>> T getMinValue(Map<K, T> map, K... keys) {
    Map<K, T> subMap = MapUtil.getSubMap(map, keys);
    return isNullOrEmpty(subMap) ? null : Collections.min(subMap.values()); //? Number Comparable?
}

From source file:org.yardstickframework.gridgain.GridGainNode.java

/**
 * @param springCfgPath Spring configuration file path.
 * @return Grid configuration./*from  w  w  w. ja v a  2  s . co  m*/
 * @throws Exception If failed.
 */
private static GridConfiguration loadConfiguration(String springCfgPath) throws Exception {
    URL url;

    try {
        url = new URL(springCfgPath);
    } catch (MalformedURLException e) {
        url = GridUtils.resolveGridGainUrl(springCfgPath);

        if (url == null)
            throw new GridException("Spring XML configuration path is invalid: " + springCfgPath
                    + ". Note that this path should be either absolute or a relative local file system path, "
                    + "relative to META-INF in classpath or valid URL to GRIDGAIN_HOME.", e);
    }

    GenericApplicationContext springCtx;

    try {
        springCtx = new GenericApplicationContext();

        new XmlBeanDefinitionReader(springCtx).loadBeanDefinitions(new UrlResource(url));

        springCtx.refresh();
    } catch (BeansException e) {
        throw new Exception("Failed to instantiate Spring XML application context [springUrl=" + url + ", err="
                + e.getMessage() + ']', e);
    }

    Map<String, GridConfiguration> cfgMap;

    try {
        cfgMap = springCtx.getBeansOfType(GridConfiguration.class);
    } catch (BeansException e) {
        throw new Exception(
                "Failed to instantiate bean [type=" + GridConfiguration.class + ", err=" + e.getMessage() + ']',
                e);
    }

    if (cfgMap == null || cfgMap.isEmpty())
        throw new Exception("Failed to find grid configuration in: " + url);

    return cfgMap.values().iterator().next();
}

From source file:edu.msu.cme.rdp.graph.utils.ContigMerger.java

private static List<MergedContig> mergeContigs(Map<String, Sequence> leftContigs,
        Map<String, Sequence> rightContigs, String kmer, String gene, ProfileHMM hmm) {
    List<MergedContig> finalized = new ArrayList();
    List<MergedContig> candidates = new ArrayList();
    int k = kmer.length();

    Map<String, Set<MergedContig>> contigToMerges = new HashMap();

    for (Sequence leftContig : leftContigs.values()) {
        String leftSeq = leftContig.getSeqString();
        leftSeq = leftSeq.substring(0, leftSeq.length() - k);

        for (Sequence rightContig : rightContigs.values()) {
            String seq = leftSeq + rightContig.getSeqString();

            MergedContig mergedContig = new MergedContig();
            if (hmm.getAlphabet() == SequenceType.Protein) {
                mergedContig.nuclSeq = seq;
                seq = mergedContig.protSeq = ProteinUtils.getInstance().translateToProtein(seq, true, 11);
            } else if (hmm.getAlphabet() == SequenceType.Nucleotide) {
                mergedContig.nuclSeq = seq;
            } else {
                throw new IllegalStateException("Cannot handle hmm alpha " + hmm.getAlphabet());
            }/*www.  ja va2  s  .  c  om*/
            mergedContig.score = ForwardScorer.scoreSequence(hmm, seq);
            mergedContig.leftContig = leftContig.getSeqName();
            mergedContig.rightContig = rightContig.getSeqName();
            mergedContig.length = seq.length();
            mergedContig.gene = gene;

            candidates.add(mergedContig);

            for (String seqid : new String[] { mergedContig.leftContig, mergedContig.rightContig }) {
                if (!contigToMerges.containsKey(seqid)) {
                    contigToMerges.put(seqid, new HashSet());
                }

                contigToMerges.get(seqid).add(mergedContig);
            }
        }
    }

    Collections.sort(candidates);

    while (candidates.size() > 0) {
        MergedContig mc = candidates.remove(0);

        candidates.removeAll(contigToMerges.get(mc.leftContig));
        candidates.removeAll(contigToMerges.get(mc.rightContig));

        finalized.add(mc);
    }

    return finalized;
}