KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jmx > mbeanserver > Util


1 /*
2  * @(#)Util.java 1.6 07/01/02
3  *
4  * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.jmx.mbeanserver;
9
10 import java.util.ArrayList JavaDoc;
11 import java.util.Collection JavaDoc;
12 import java.util.Collections JavaDoc;
13 import java.util.Comparator JavaDoc;
14 import java.util.HashMap JavaDoc;
15 import java.util.HashSet JavaDoc;
16 import java.util.IdentityHashMap JavaDoc;
17 import java.util.LinkedHashMap JavaDoc;
18 import java.util.List JavaDoc;
19 import java.util.Map JavaDoc;
20 import java.util.Set JavaDoc;
21 import java.util.SortedMap JavaDoc;
22 import java.util.TreeMap JavaDoc;
23
24 public class Util {
25     static <K, V> Map JavaDoc<K, V> newMap() {
26         return new HashMap JavaDoc<K, V>();
27     }
28     
29     static <K, V> Map JavaDoc<K, V> newSynchronizedMap() {
30         return Collections.synchronizedMap(Util.<K, V>newMap());
31     }
32     
33     static <K, V> IdentityHashMap JavaDoc<K, V> newIdentityHashMap() {
34         return new IdentityHashMap JavaDoc<K, V>();
35     }
36     
37     static <K, V> Map JavaDoc<K, V> newSynchronizedIdentityHashMap() {
38         Map JavaDoc<K, V> map = newIdentityHashMap();
39         return Collections.synchronizedMap(map);
40     }
41     
42     static <K, V> SortedMap JavaDoc<K, V> newSortedMap() {
43         return new TreeMap JavaDoc<K, V>();
44     }
45     
46     static <K, V> SortedMap JavaDoc<K, V> newSortedMap(Comparator JavaDoc<? super K> comp) {
47         return new TreeMap JavaDoc<K, V>(comp);
48     }
49     
50     static <K, V> Map JavaDoc<K, V> newInsertionOrderMap() {
51         return new LinkedHashMap JavaDoc<K, V>();
52     }
53     
54     static <E> Set JavaDoc<E> newSet() {
55         return new HashSet JavaDoc<E>();
56     }
57     
58     static <E> Set JavaDoc<E> newSet(Collection JavaDoc<E> c) {
59         return new HashSet JavaDoc<E>(c);
60     }
61     
62     static <E> List JavaDoc<E> newList() {
63         return new ArrayList JavaDoc<E>();
64     }
65     
66     static <E> List JavaDoc<E> newList(Collection JavaDoc<E> c) {
67         return new ArrayList JavaDoc<E>(c);
68     }
69     
70     /* This method can be used by code that is deliberately violating the
71      * allowed checked casts. Rather than marking the whole method containing
72      * the code with @SuppressWarnings, you can use a call to this method for
73      * the exact place where you need to escape the constraints. Typically
74      * you will "import static" this method and then write either
75      * X x = cast(y);
76      * or, if that doesn't work (e.g. X is a type variable)
77      * Util.<X>cast(y);
78      */

79     @SuppressWarnings JavaDoc("unchecked")
80     public static <T> T cast(Object JavaDoc x) {
81         return (T) x;
82     }
83 }
84
Popular Tags