1 | /* |
2 | * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0, |
3 | * and the EPL 1.0 (http://h2database.com/html/license.html). |
4 | * Initial Developer: H2 Group |
5 | */ |
6 | package org.h2.util; |
7 | |
8 | import java.util.ArrayList; |
9 | import java.util.Collection; |
10 | import java.util.HashMap; |
11 | import java.util.HashSet; |
12 | |
13 | /** |
14 | * This class contains static methods to construct commonly used generic objects |
15 | * such as ArrayList. |
16 | */ |
17 | public class New { |
18 | |
19 | /** |
20 | * Create a new ArrayList. |
21 | * |
22 | * @param <T> the type |
23 | * @return the object |
24 | */ |
25 | public static <T> ArrayList<T> arrayList() { |
26 | return new ArrayList<T>(4); |
27 | } |
28 | |
29 | /** |
30 | * Create a new HashMap. |
31 | * |
32 | * @param <K> the key type |
33 | * @param <V> the value type |
34 | * @return the object |
35 | */ |
36 | public static <K, V> HashMap<K, V> hashMap() { |
37 | return new HashMap<K, V>(); |
38 | } |
39 | |
40 | /** |
41 | * Create a new HashMap. |
42 | * |
43 | * @param <K> the key type |
44 | * @param <V> the value type |
45 | * @param initialCapacity the initial capacity |
46 | * @return the object |
47 | */ |
48 | public static <K, V> HashMap<K, V> hashMap(int initialCapacity) { |
49 | return new HashMap<K, V>(initialCapacity); |
50 | } |
51 | |
52 | /** |
53 | * Create a new HashSet. |
54 | * |
55 | * @param <T> the type |
56 | * @return the object |
57 | */ |
58 | public static <T> HashSet<T> hashSet() { |
59 | return new HashSet<T>(); |
60 | } |
61 | |
62 | /** |
63 | * Create a new ArrayList. |
64 | * |
65 | * @param <T> the type |
66 | * @param c the collection |
67 | * @return the object |
68 | */ |
69 | public static <T> ArrayList<T> arrayList(Collection<T> c) { |
70 | return new ArrayList<T>(c); |
71 | } |
72 | |
73 | /** |
74 | * Create a new ArrayList. |
75 | * |
76 | * @param <T> the type |
77 | * @param initialCapacity the initial capacity |
78 | * @return the object |
79 | */ |
80 | public static <T> ArrayList<T> arrayList(int initialCapacity) { |
81 | return new ArrayList<T>(initialCapacity); |
82 | } |
83 | |
84 | } |