Example usage for java.util EnumMap EnumMap

List of usage examples for java.util EnumMap EnumMap

Introduction

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

Prototype

public EnumMap(Map<K, ? extends V> m) 

Source Link

Document

Creates an enum map initialized from the specified map.

Usage

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();/*from www . j  a  v a  2  s .  c o  m*/

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

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  . j  a  v a  2 s.co 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);//  w w w .ja va 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);

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

    System.out.println(map);//w ww .j  a v a2s . com

    map.clear();

    System.out.println(map);

}

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 v a 2 s. com

    System.out.println("Number of mappings:" + map.size());

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

    // print the new number of mappings of this map
    System.out.println("Number of mappings:" + map.size());
}

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 ww  . j  a  v a2  s  .c o  m

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

From source file:color.java

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

    map.put(color.red, letter.a);//from  ww w  . ja va  2  s .  c om
    map.put(color.green, letter.b);
    map.put(color.blue, letter.c);

    Map<color, letter> map2 = new EnumMap<color, letter>(color.class);
    letter[] letters = new letter[] { letter.a, letter.b, letter.c };

    for (int i = 0; i < color.values().length; i++) {
        map2.put(color.values()[i], letters[i]);
    }
    System.out.println(map);
    System.out.println(map2);
}

From source file:Tutorial.java

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

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

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

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

static public void main(String[] args) {
    try {//from www . ja va 2s . 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();
    }
}