|
@@ -2,6 +2,7 @@ |
2 |
2 |
|
package org.litesoft.core; |
3 |
3 |
|
|
4 |
4 |
|
import org.litesoft.commonfoundation.base.*; |
|
5 |
+ |
import org.litesoft.commonfoundation.typeutils.*; |
5 |
6 |
|
|
6 |
7 |
|
import java.util.*; |
7 |
8 |
|
|
|
@@ -9,14 +10,15 @@ |
9 |
10 |
|
public ClassToInstanceMapperImpl() { |
10 |
11 |
|
} |
11 |
12 |
|
|
12 |
|
- |
private Map<Class<?>, NoInstanceFactory<?>> mFactoriesByClass = new HashMap<Class<?>, NoInstanceFactory<?>>(); |
13 |
|
- |
private Map<Class<?>, Object> mInstanceByClass = new HashMap<Class<?>, Object>(); |
|
13 |
+ |
private Map<Class<?>, NoInstanceFactory<?>> mFactoriesByClass = Maps.newHashMap(); |
|
14 |
+ |
private Map<Class<?>, Object> mInstanceByClass = Maps.newHashMap(); |
14 |
15 |
|
|
15 |
16 |
|
/** |
16 |
17 |
|
* Get a List (!null) of all the currently "register" Factories |
17 |
18 |
|
*/ |
|
19 |
+ |
@Override |
18 |
20 |
|
public synchronized List<NoInstanceFactory<?>> getNoInstanceFactories() { |
19 |
|
- |
return new ArrayList<NoInstanceFactory<?>>( mFactoriesByClass.values() ); |
|
21 |
+ |
return Lists.newArrayList(mFactoriesByClass.values() ); |
20 |
22 |
|
} |
21 |
23 |
|
|
22 |
24 |
|
/** |
|
@@ -27,6 +29,7 @@ |
27 |
29 |
|
* @throws IllegalArgumentException if pFactory is null |
28 |
30 |
|
* @throws IllegalStateException if this is a duplicate Factory |
29 |
31 |
|
*/ |
|
32 |
+ |
@Override |
30 |
33 |
|
public void register( NoInstanceFactory<?> pFactory ) { |
31 |
34 |
|
Confirm.isNotNull( "NoInstanceFactory", pFactory ); |
32 |
35 |
|
Class<?> zClass = pFactory.getFor(); |
|
@@ -48,6 +51,7 @@ |
48 |
51 |
|
* |
49 |
52 |
|
* @throws IllegalArgumentException if pClass is null |
50 |
53 |
|
*/ |
|
54 |
+ |
@Override |
51 |
55 |
|
public <T> T checkGet( Class<T> pClass ) |
52 |
56 |
|
throws IllegalArgumentException { |
53 |
57 |
|
assertClass( pClass ); |
|
@@ -68,6 +72,7 @@ |
68 |
72 |
|
* @throws IllegalArgumentException if pClass is null |
69 |
73 |
|
* @throws IllegalStateException if no instance previously 'registered' for pClass |
70 |
74 |
|
*/ |
|
75 |
+ |
@Override |
71 |
76 |
|
public <T> T get( Class<T> pClass ) |
72 |
77 |
|
throws IllegalArgumentException, IllegalStateException { |
73 |
78 |
|
assertClass( pClass ); |
|
@@ -98,6 +103,7 @@ |
98 |
103 |
|
* @throws IllegalArgumentException if either pClass or pInstance is null |
99 |
104 |
|
* @throws IllegalStateException if an instance for pClass IS currently 'registered' |
100 |
105 |
|
*/ |
|
106 |
+ |
@Override |
101 |
107 |
|
public <T, V extends T> void register( Class<T> pClass, V pInstance ) |
102 |
108 |
|
throws IllegalArgumentException, IllegalStateException { |
103 |
109 |
|
assertClassAndInstance( pClass, pInstance ); |
|
@@ -120,6 +126,7 @@ |
120 |
126 |
|
* @throws IllegalArgumentException if either pClass or pInstance is null |
121 |
127 |
|
* @throws IllegalStateException if an instance for pClass is NOT currently 'registered' |
122 |
128 |
|
*/ |
|
129 |
+ |
@Override |
123 |
130 |
|
public <T, V extends T> void forceRegister( Class<T> pClass, V pInstance ) |
124 |
131 |
|
throws IllegalArgumentException, IllegalStateException { |
125 |
132 |
|
assertClassAndInstance( pClass, pInstance ); |
|
@@ -142,6 +149,7 @@ |
142 |
149 |
|
* @throws IllegalArgumentException if either pClass or pInstance is null |
143 |
150 |
|
* @throws IllegalStateException if pInstance of pClass is NOT currently 'registered' for pClass |
144 |
151 |
|
*/ |
|
152 |
+ |
@Override |
145 |
153 |
|
public <T, V extends T> void remove( Class<T> pClass, V pInstance ) |
146 |
154 |
|
throws IllegalArgumentException, IllegalStateException { |
147 |
155 |
|
assertClassAndInstance( pClass, pInstance ); |
|
@@ -159,6 +167,7 @@ |
159 |
167 |
|
throw new IllegalStateException( "Instance to remove '" + pInstance + "' mismatchs found '" + zInstance + "' for: " + pClass ); |
160 |
168 |
|
} |
161 |
169 |
|
|
|
170 |
+ |
@Override |
162 |
171 |
|
public synchronized void clearAllInstances() { |
163 |
172 |
|
mInstanceByClass.clear(); |
164 |
173 |
|
} |