MultiKey Example 2 : Collection « Apache Common « Java






MultiKey Example 2

import java.util.HashMap;

import org.apache.commons.collections.keyvalue.MultiKey;

public class MultiKeyExampleV2 {

  private static HashMap codeAndLangToText;

  public static void main(String args[]) {

    codeAndLangToText = new HashMap();
    addMultiKeyAndValue("en", "GM", "Good Morning");
    addMultiKeyAndValue("en", "GE", "Good Evening");
    addMultiKeyAndValue("en", "GN", "Good Night");
    addMultiKeyAndValue("de", "GM", "Guten Morgen");
    addMultiKeyAndValue("de", "GE", "Guten Abend");
    addMultiKeyAndValue("de", "GN", "Guten Nacht");

    System.err.println("Good Evening in English: " +
      codeAndLangToText.get(new MultiKey("en", "GE")));
    System.err.println("Good Night in German: " +
      codeAndLangToText.get(new MultiKey("de", "GN")));
  }

  private static void addMultiKeyAndValue(
    Object key1, Object key2, Object value) {

    MultiKey key = new MultiKey(key1, key2);
    codeAndLangToText.put(key, value);
  }
}
           
       








ApacheCommonMultiKeyExampleV2.zip( 514 k)

Related examples in the same category

1.Collection Bag
2.Transformer Example
3.Collection BidiMap
4.Collection Buffer
5.Collection Closure
6.Comparator Example For BuildIn Data Type
7.Comparator Example For User Defined Class
8.Cookie Bag 2
9.Factory Example 1
10.HashMap Example 1
11.List Example 1
12.MapHeaven 1
13.Multi Key Example 1
14.Set Example 1
15.Set Example 2
16.Bean Comparator ( Sorting based on Properties of class )Bean Comparator ( Sorting based on Properties of class )