@@ -45,36 +45,50 @@ public abstract class AnnotatedOpDependencyMember<T> implements
4545{
4646
4747 private final Supplier <String > keyGenerator ;
48+ private String key ;
49+ private boolean keyGenerated ;
50+
4851 private final Supplier <String > descriptionGenerator ;
52+ private String description ;
53+ private boolean descriptionGenerated ;
54+
4955 private final Type type ;
5056 private final OpDependency annotation ;
5157
52- public AnnotatedOpDependencyMember (String key , Type type ,
53- final OpDependency annotation )
54- {
55- this (key , "" , type , annotation );
56- }
57-
58+ /**
59+ * This constructor is ideal for situations where the key and description are readily available
60+ *
61+ * @param key the key
62+ * @param description the description
63+ * @param type the {@link Type} of this {@link Member}
64+ * @param annotation the {@link OpDependency} annotation
65+ */
5866 public AnnotatedOpDependencyMember (String key , String description , Type type ,
5967 final OpDependency annotation )
6068 {
6169 this (() -> key , () -> description , type , annotation );
70+ this .key = key ;
71+ this .keyGenerated = true ;
72+ this .description = description ;
73+ this .descriptionGenerated = true ;
6274 }
6375
6476 /**
6577 * This constructor is ideal for situations where obtaining the key or
6678 * description are computationally expensive.
67- *
79+ *
6880 * @param keyGenerator the {@link Supplier} able to generate the key
6981 * @param descriptionGenerator the {@link Supplier} able to generate the description
7082 * @param type the {@link Type} of this {@link Member}
71- * @param annotation
83+ * @param annotation the {@link OpDependency} annotation
7284 */
7385 public AnnotatedOpDependencyMember (Supplier <String > keyGenerator , Supplier <String > descriptionGenerator , Type type ,
7486 final OpDependency annotation )
7587 {
7688 this .keyGenerator = keyGenerator ;
89+ this .keyGenerated = false ;
7790 this .descriptionGenerator = descriptionGenerator ;
91+ this .descriptionGenerated = false ;
7892 this .type = type ;
7993 this .annotation = annotation ;
8094 }
@@ -99,16 +113,31 @@ public boolean isAdaptable() {
99113
100114 @ Override
101115 public String getKey () {
102- return keyGenerator .get ();
116+ if (!keyGenerated ) generateKey ();
117+ return key ;
118+ }
119+
120+ private synchronized void generateKey () {
121+ if (keyGenerated ) return ;
122+ key = keyGenerator .get ();
123+ keyGenerated = true ;
103124 }
104125
105126 @ Override
106127 public String getDescription () {
107- return descriptionGenerator .get ();
128+ if (!descriptionGenerated ) generateDescription ();
129+ return description ;
130+ }
131+
132+ private synchronized void generateDescription () {
133+ if (descriptionGenerated ) return ;
134+ description = descriptionGenerator .get ();
135+ descriptionGenerated = true ;
108136 }
109137
110138 @ Override
111139 public Type getType () {
112140 return type ;
113141 }
114142}
143+
0 commit comments