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:Main.java

public static int countCollectionValues(Map<?, ? extends Collection<?>> map) {
    int counter = 0;
    for (Collection<?> c : map.values()) {
        if (c != null)
            counter += c.size();//from   w w  w  .  j  a va2  s. c o  m
    }
    return counter;
}

From source file:com.microsoft.azure.shortcuts.services.samples.RegionsSample.java

public static void test(Azure azure) throws Exception {
    // List regions supporting VM
    Set<String> regionNames = azure.regions().list(LocationAvailableServiceNames.PERSISTENTVMROLE).keySet();
    System.out.println("Available regions supporting VMs: " + StringUtils.join(regionNames, ", "));

    // List all regions info
    Map<String, Region> regions = azure.regions().asMap();
    for (Region r : regions.values()) {
        printRegion(r);/*from  ww w .  j  a  va 2s.c  o m*/
    }

    // Get info about a specific region
    Region region = azure.regions("West US");
    printRegion(region);
}

From source file:Main.java

public static <K, V> List<V> mapToList(Map<K, V> result) {
    List<V> list = new ArrayList<V>();
    for (V v : result.values()) {
        list.add(v);// w w w . ja va 2s.c o m
    }
    return list;
}

From source file:Main.java

public static <T> List<T> joinListValues(Map<?, List<T>> map) {
    List<T> joinedValues = new ArrayList<>();
    for (List<T> list : map.values()) {
        joinedValues.addAll(list);/*from w  w  w. java2 s .c o  m*/
    }
    return joinedValues;
}

From source file:Main.java

/**
 * @param mp/*from www  . j  a va 2  s . com*/
 * @return the values of mp or an empty set, if <code>mp == null</code>.
 * @postcondition result != null
 */
public static <K, V> Collection<V> valuesOrEmptySet(Map<K, V> mp) {
    final Collection<V> result = (mp == null) ? Collections.<V>emptySet() : mp.values();
    assert result != null;
    return result;
}

From source file:Main.java

public static <T extends Object> List<T> convertMapToList(Map<String, T> map) {
    List<T> list = new ArrayList<T>();
    for (T t : map.values()) {
        list.add(t);/* w w w . j a  v a 2s .com*/
    }
    return list;
}

From source file:Main.java

public static String suggest(Map map/*<String, Object>*/, String prefix, boolean key) {
    return suggest(key ? map.keySet() : map.values(), prefix);
}

From source file:Main.java

/**
 * Returns whether given ringtone uri is valid (will produce sound). Can be used to determine
 * validity of a ring tone uri which is retrieved from preferences.
 *
 * @param context {@link Context} used to access system data.
 * @param ringTone {@link Uri} for ring tone.
 *
 * @return true if there is a registered ring tone with given uri, false otherwise.
 *//*w  ww . j  a va 2s  . c o m*/
public static boolean isRingtoneValid(@NonNull Context context, @NonNull Uri ringTone) {
    Map<String, String> ringTones = getRingtones(context);
    return (ringTones.values().contains(ringTone.toString()));
}

From source file:Main.java

/**
 * Normalize  all values so the sum is 1
 * @param <K>//from ww w.  j  av  a 2 s.c o m
 * @param map 
 */
public static <K> void normalizeMap(Map<K, Double> map) {
    Set<K> keys = map.keySet();
    double sum = 0.0 + map.values().stream().mapToDouble(Double::doubleValue).sum();

    for (K key : keys) {
        map.put(key, map.get(key) / sum);
    }
}

From source file:Main.java

public static int[] getMaxAndSum(Map<DateMidnight, Integer> map) {
    int max = 0;//from  www  .  j  a v  a2  s.com
    int sum = 0;
    for (Integer count : map.values()) {
        sum += count;
        max = Math.max(max, count);
    }

    return new int[] { max, sum };
}