Subversion Repository Public Repository

litesoft

Diff Revisions 952 vs 953 for /trunk/Java/core/Anywhere/src/org/litesoft/core/ClassToInstanceMapper.java

Diff revisions: vs.
  @@ -1,86 +1,64 @@
1 1 // This Source Code is in the Public Domain per: http://unlicense.org
2 2 package org.litesoft.core;
3 3
4 + import org.litesoft.commonfoundation.annotations.*;
5 +
4 6 import java.util.*;
5 7
6 8 public interface ClassToInstanceMapper {
7 9 public interface NoInstanceFactory<T> {
8 - /**
9 - * @return !null
10 - */
11 - Class<T> getFor();
12 -
13 - /**
14 - * @return should probably not be null
15 - */
16 - T createInstance();
10 + @NotNull Class<T> getFor();
11 +
12 + @NotNull T createInstance();
17 13 }
18 14
19 15 /**
20 - * Get a List (!null) of all the currently "set" Factories
16 + * Get all the currently "registered" Factories
21 17 */
22 - List<NoInstanceFactory<?>> getNoInstanceFactories();
18 + @NotNull List<NoInstanceFactory<?>> getNoInstanceFactories();
23 19
24 20 /**
25 - * Set a Factory into this Mapper. This Factory is used to create an Instance (and register it) when "get" is called and no Instance is currently registered.
26 - *
27 - * @param pFactory !null
28 - *
29 - * @throws IllegalArgumentException if pFactory is null
30 - * @throws IllegalStateException if this is a duplicate Factory
21 + * @return current instance registered, or null
31 22 */
32 - void setNoInstanceFactory( NoInstanceFactory<?> pFactory );
23 + @Nullable <T> T checkGet( @NotNull Class<T> pClass );
33 24
34 25 /**
35 - * @param pClass !null
26 + * Get the previously 'registered' (register &/ replaced) instance of pClass.
27 + * NOTE: if there is no instance currently registered, then one is attempted to be added using a previously registered NoInstanceFactory.
36 28 *
37 - * @return null if not found or current instance set / replaced
29 + * @return instance of pClass
38 30 *
39 - * @throws IllegalArgumentException if pClass is null
31 + * @throws IllegalStateException if no instance previously 'registered' for pClass
40 32 */
41 - <T> T checkGet( Class<T> pClass )
42 - throws IllegalArgumentException;
33 + @NotNull <T> T get( @NotNull Class<T> pClass )
34 + throws IllegalStateException;
43 35
44 36 /**
45 - * Get the previously 'registered' (set &/ replaced) instance of pClass.
46 - * NOTE: if there is no instance currently registered, then one is attempted to be added using a previously registered NoInstanceFactory.
47 - *
48 - * @param pClass !null
37 + * Register a Factory into this Mapper.
49 38 *
50 - * @return instance of pClass
39 + * This Factory is used to create an Instance (and register it) when "get" is called and no Instance is currently registered.
40 + * These factories can be copied into new ClassToInstanceMapper(s) so that a "singleton" instance exists "per" ClassToInstanceMapper.
51 41 *
52 - * @throws IllegalArgumentException if pClass is null
53 - * @throws IllegalStateException if no instance previously 'registered' for pClass
42 + * @throws IllegalStateException if this is a duplicate Factory
54 43 */
55 - <T> T get( Class<T> pClass )
56 - throws IllegalArgumentException, IllegalStateException;
44 + void register( @NotNull NoInstanceFactory<?> pFactory )
45 + throws IllegalStateException;
57 46
58 47 /**
59 - * Set or register an instance (pInstance) of pClass, that is NOT currently 'registered' (previously set &/ replaced, but not subsequently removed)
60 - *
61 - * @param pClass !null
62 - * @param pInstance !null
48 + * Register an instance (pInstance) of pClass, that is NOT currently 'registered' (previously registered, but not subsequently removed)
63 49 *
64 - * @throws IllegalArgumentException if either pClass or pInstance is null
65 50 * @throws IllegalStateException if an instance for pClass IS currently 'registered'
66 51 */
67 - <T, V extends T> void set( Class<T> pClass, V pInstance )
68 - throws IllegalArgumentException, IllegalStateException;
52 + <T, V extends T> void register( @NotNull Class<T> pClass, @NotNull V pInstance )
53 + throws IllegalStateException;
69 54
70 55 /**
71 - * Replace or re-register an instance (pInstance) of pClass, that IS currently 'registered' (previously set &/ replaced, but not subsequently removed)
72 - *
73 - * @param pClass !null
74 - * @param pInstance !null
75 - *
76 - * @throws IllegalArgumentException if either pClass or pInstance is null
77 - * @throws IllegalStateException if an instance for pClass is NOT currently 'registered'
56 + * Register an instance (pInstance) of pClass, regardless of its current registered state.
78 57 */
79 - <T, V extends T> void replace( Class<T> pClass, V pInstance )
80 - throws IllegalArgumentException, IllegalStateException;
58 + <T, V extends T> void forceRegister( @NotNull Class<T> pClass, @NotNull V pInstance );
81 59
82 60 /**
83 - * Remove the instance (pInstance) of pClass, that IS currently 'registered' (previously set &/ replaced, but not subsequently removed)
61 + * Remove the instance (pInstance) of pClass, that IS currently 'registered' (previously register &/ replaced, but not subsequently removed)
84 62 *
85 63 * @param pClass !null
86 64 * @param pInstance !null
  @@ -88,7 +66,7 @@
88 66 * @throws IllegalArgumentException if either pClass or pInstance is null
89 67 * @throws IllegalStateException if pInstance of pClass is NOT currently 'registered' for pClass
90 68 */
91 - <T, V extends T> void remove( Class<T> pClass, V pInstance )
69 + <T, V extends T> void remove( @NotNull Class<T> pClass, V pInstance )
92 70 throws IllegalArgumentException, IllegalStateException;
93 71
94 72 void clearAllInstances();