Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 1 | package aQute.libg.generics; |
| 2 | |
| 3 | import java.util.*; |
| 4 | |
| 5 | public class Create { |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 6 | |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 7 | public static <K, V> Map<K,V> map() { |
| 8 | return new LinkedHashMap<K,V>(); |
| 9 | } |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 10 | |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 11 | public static <K, V> Map<K,V> map(Class<K> key, Class<V> value) { |
| 12 | return Collections.checkedMap(new LinkedHashMap<K,V>(), key, value); |
| 13 | } |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 14 | |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 15 | public static <T> List<T> list() { |
| 16 | return new ArrayList<T>(); |
| 17 | } |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 18 | |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 19 | public static <T> List<T> list(Class<T> c) { |
| 20 | return Collections.checkedList(new ArrayList<T>(), c); |
| 21 | } |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 22 | |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 23 | public static <T> Set<T> set() { |
| 24 | return new HashSet<T>(); |
| 25 | } |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 26 | |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 27 | public static <T> Set<T> set(Class<T> c) { |
| 28 | return Collections.checkedSet(new HashSet<T>(), c); |
| 29 | } |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 30 | |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 31 | public static <T> List<T> list(T[] source) { |
| 32 | return new ArrayList<T>(Arrays.asList(source)); |
| 33 | } |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 34 | |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 35 | public static <T> Set<T> set(T[] source) { |
| 36 | return new HashSet<T>(Arrays.asList(source)); |
| 37 | } |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 38 | |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 39 | public static <K, V> Map<K,V> copy(Map<K,V> source) { |
| 40 | return new LinkedHashMap<K,V>(source); |
| 41 | } |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 42 | |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 43 | public static <T> List<T> copy(List<T> source) { |
| 44 | return new ArrayList<T>(source); |
| 45 | } |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 46 | |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 47 | public static <T> Set<T> copy(Collection<T> source) { |
| 48 | if (source == null) |
| 49 | return set(); |
| 50 | return new HashSet<T>(source); |
| 51 | } |
| 52 | |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 53 | } |