Example usage for java.util EnumMap put

List of usage examples for java.util EnumMap put

Introduction

In this page you can find the example usage for java.util EnumMap 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:Tutorial.java

public static void main(String[] args) {
    EnumMap<Tutorial, String> map = new EnumMap<Tutorial, String>(Tutorial.class);

    map.put(Tutorial.CSS, "1");
    map.put(Tutorial.Python, "2");
    map.put(Tutorial.PHP, "3");
    map.put(Tutorial.Java, "4");

    System.out.println(map);/*from   w ww .j a v  a 2  s  .co m*/

    String oldValue1 = map.put(Tutorial.Javascript, "5");

    String oldValue2 = map.put(Tutorial.CSS, "20");

    System.out.println("Updated Map: " + map);
    System.out.println("First update returns:" + oldValue1);
    System.out.println("Second update returns:" + oldValue2);

}

From source file:Tutorial.java

public static void main(String[] args) {
    EnumMap<Tutorial, String> map = new EnumMap<Tutorial, String>(Tutorial.class);

    map.put(Tutorial.CSS, "1");
    map.put(Tutorial.Python, "2");
    map.put(Tutorial.PHP, "3");
    map.put(Tutorial.Java, "4");

    System.out.println(map);//from  w  w  w . ja  va  2  s .  c o m

    boolean contains = map.containsKey(Tutorial.CSS);

    System.out.println("Tutorial.CSS has a mapping:" + contains);

    contains = map.containsKey(Tutorial.Javascript);

    System.out.println("Tutorial.Javascript has a mapping:" + contains);

}

From source file:Tutorial.java

public static void main(String[] args) {
    EnumMap<Tutorial, String> map = new EnumMap<Tutorial, String>(Tutorial.class);

    map.put(Tutorial.CSS, "1");
    map.put(Tutorial.Python, "2");
    map.put(Tutorial.PHP, "3");
    map.put(Tutorial.Java, "4");

    System.out.println(map);/*from ww  w  . ja  v a  2 s.  c  o m*/

    boolean contains = map.containsValue("1");

    System.out.println("Map contains '1':" + contains);

    contains = map.containsValue("5");

    System.out.println("Map contains '5':" + contains);

}

From source file:Tutorial.java

public static void main(String[] args) {
    EnumMap<Tutorial, String> map = new EnumMap<Tutorial, String>(Tutorial.class);

    EnumMap<Tutorial, String> map1 = new EnumMap<Tutorial, String>(map);

    map.put(Tutorial.CSS, "1");
    map.put(Tutorial.Python, "2");
    map.put(Tutorial.PHP, "3");
    map.put(Tutorial.Java, "4");

    System.out.println(map.hashCode());

}

From source file:Tutorial.java

public static void main(String[] args) {
    EnumMap<Tutorial, String> map1 = new EnumMap<Tutorial, String>(Tutorial.class);
    EnumMap<Tutorial, String> map2 = new EnumMap<Tutorial, String>(Tutorial.class);

    map1.put(Tutorial.CSS, "1");
    map1.put(Tutorial.Python, "2");
    map1.put(Tutorial.PHP, "3");
    map1.put(Tutorial.Java, "4");

    System.out.println("map1:" + map1);

    map2 = map1.clone();//w  w  w  .j  a  v a 2 s.c om

    System.out.println("map2:" + map2);
}

From source file:Tutorial.java

public static void main(String[] args) {
    EnumMap<Tutorial, String> map1 = new EnumMap<Tutorial, String>(Tutorial.class);
    EnumMap<Tutorial, String> map2 = new EnumMap<Tutorial, String>(Tutorial.class);

    map1.put(Tutorial.CSS, "1");
    map1.put(Tutorial.Python, "2");
    map1.put(Tutorial.PHP, "3");
    map1.put(Tutorial.Java, "4");

    System.out.println("Map1: " + map1);
    System.out.println("Map2: " + map2);

    map2.putAll(map1);//from  w ww  .j a va 2  s  .c  om

    System.out.println("Map1: " + map1);
    System.out.println("Map2: " + map2);
}

From source file:Tutorial.java

public static void main(String[] args) {
    EnumMap<Tutorial, String> map1 = new EnumMap<Tutorial, String>(Tutorial.class);
    EnumMap<Tutorial, String> map2 = new EnumMap<Tutorial, String>(Tutorial.class);

    map1.put(Tutorial.CSS, "1");
    map1.put(Tutorial.Python, "2");
    map1.put(Tutorial.PHP, "3");
    map1.put(Tutorial.Java, "4");

    map2.put(Tutorial.CSS, "1");
    map2.put(Tutorial.Python, "2");
    map2.put(Tutorial.PHP, "3");
    map2.put(Tutorial.Java, "4");

    System.out.println("map1:" + map1);
    System.out.println("map2:" + map2);

    boolean equal = map1.equals(map2);

    System.out.println("Map1 and map 2 are equal:" + equal);

    map2.put(Tutorial.Javascript, "5");

    equal = map1.equals(map2);//  w w w.j a v  a  2 s .  c  o m

    System.out.println("Map1 and map 2 are equal:" + equal);
}

From source file:eu.crisis_economics.utilities.EnumDistribution.java

static public void main(String[] args) {
    try {/*from  www .  ja  v a  2  s . c om*/
        EnumDistribution<ScheduleIntervals> dice = EnumDistribution.create(ScheduleIntervals.class,
                "./test.dat");
        EnumMap<ScheduleIntervals, Integer> tallies = new EnumMap<ScheduleIntervals, Integer>(
                ScheduleIntervals.class);
        for (ScheduleIntervals value : ScheduleIntervals.values())
            tallies.put(value, 0);
        final int numSamples = 10000000;
        for (int i = 0; i < numSamples; ++i) {
            ScheduleIntervals value = dice.sample();
            tallies.put(value, tallies.get(value) + 1);
        }
        for (Entry<ScheduleIntervals, Integer> record : tallies.entrySet()) {
            ScheduleIntervals value = record.getKey();
            int tally = tallies.get(value);
            System.out.printf("%20s %16.10g\n", value.name(), tally / (double) numSamples);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static <K extends Enum<K>, V> EnumMap<K, V> newEnumMap(Class<K> type, Map.Entry<K, V>... entries) {

    EnumMap<K, V> map = new EnumMap<K, V>(type);

    for (Map.Entry<K, V> entry : entries) {
        map.put(entry.getKey(), entry.getValue());
    }/*from w ww. j  a  va  2  s.  co m*/
    return map;
}

From source file:de.unentscheidbar.validation.builtin.FilePropertiesValidator.java

private static Map<Type, FilePropertiesValidator> instances() {

    EnumMap<Type, FilePropertiesValidator> map = new EnumMap<>(Type.class);
    for (Type type : Type.values()) {
        map.put(type, new FilePropertiesValidator(type));
    }/*from  ww  w . j a  va2s .  c om*/
    return map;
}