1 7 8 package com.sun.jmx.mbeanserver; 9 10 import java.util.ArrayList ; 11 import java.util.Collection ; 12 import java.util.Collections ; 13 import java.util.Comparator ; 14 import java.util.HashMap ; 15 import java.util.HashSet ; 16 import java.util.IdentityHashMap ; 17 import java.util.LinkedHashMap ; 18 import java.util.List ; 19 import java.util.Map ; 20 import java.util.Set ; 21 import java.util.SortedMap ; 22 import java.util.TreeMap ; 23 24 public class Util { 25 static <K, V> Map <K, V> newMap() { 26 return new HashMap <K, V>(); 27 } 28 29 static <K, V> Map <K, V> newSynchronizedMap() { 30 return Collections.synchronizedMap(Util.<K, V>newMap()); 31 } 32 33 static <K, V> IdentityHashMap <K, V> newIdentityHashMap() { 34 return new IdentityHashMap <K, V>(); 35 } 36 37 static <K, V> Map <K, V> newSynchronizedIdentityHashMap() { 38 Map <K, V> map = newIdentityHashMap(); 39 return Collections.synchronizedMap(map); 40 } 41 42 static <K, V> SortedMap <K, V> newSortedMap() { 43 return new TreeMap <K, V>(); 44 } 45 46 static <K, V> SortedMap <K, V> newSortedMap(Comparator <? super K> comp) { 47 return new TreeMap <K, V>(comp); 48 } 49 50 static <K, V> Map <K, V> newInsertionOrderMap() { 51 return new LinkedHashMap <K, V>(); 52 } 53 54 static <E> Set <E> newSet() { 55 return new HashSet <E>(); 56 } 57 58 static <E> Set <E> newSet(Collection <E> c) { 59 return new HashSet <E>(c); 60 } 61 62 static <E> List <E> newList() { 63 return new ArrayList <E>(); 64 } 65 66 static <E> List <E> newList(Collection <E> c) { 67 return new ArrayList <E>(c); 68 } 69 70 79 @SuppressWarnings ("unchecked") 80 public static <T> T cast(Object x) { 81 return (T) x; 82 } 83 } 84 | Popular Tags |