Rename packages from openecomp to onap.
[sdc.git] / common / onap-common-configuration-management / onap-configuration-management-api / src / main / java / org / onap / config / api / Configuration.java
1 package org.onap.config.api;
2
3 import java.util.Arrays;
4 import java.util.List;
5 import java.util.Map;
6
7 /**
8  * The interface Configuration.
9  */
10 public interface Configuration {
11   /**
12    * The constant tenant.
13    */
14   public static ThreadLocal<String> tenant = new ThreadLocal<>();
15
16   /**
17    * Sets tenant id.
18    *
19    * @param id the id
20    */
21   public static void setTenantId(String id) {
22     if (id != null && id.trim().length() > 0) {
23       tenant.set(id);
24     }
25   }
26
27   /**
28    * Gets as string.
29    *
30    * @param key the key
31    * @return the as string
32    */
33   public default String getAsString(String key) {
34     return getAsString(null, key);
35   }
36
37   /**
38    * Gets as string.
39    *
40    * @param namespace the namespace
41    * @param key       the key
42    * @return the as string
43    */
44   public default String getAsString(String namespace, String key) {
45     return getAsString(tenant.get(), namespace, key);
46   }
47
48   /**
49    * Gets as string.
50    *
51    * @param tenantId  the tenant id
52    * @param namespace the namespace
53    * @param key       the key
54    * @return the as string
55    */
56   public default String getAsString(String tenantId, String namespace, String key) {
57     return get(tenantId, namespace, key, String.class);
58   }
59
60   /**
61    * Gets as byte value.
62    *
63    * @param key the key
64    * @return the as byte value
65    */
66   public default Byte getAsByteValue(String key) {
67     return getAsByteValue(null, key);
68   }
69
70   /**
71    * Gets as byte value.
72    *
73    * @param namespace the namespace
74    * @param key       the key
75    * @return the as byte value
76    */
77   public default Byte getAsByteValue(String namespace, String key) {
78     return getAsByteValue(tenant.get(), namespace, key);
79   }
80
81   /**
82    * Gets as byte value.
83    *
84    * @param tenantId  the tenant id
85    * @param namespace the namespace
86    * @param key       the key
87    * @return the as byte value
88    */
89   public default Byte getAsByteValue(String tenantId, String namespace, String key) {
90     return get(tenantId, namespace, key, Byte.class);
91   }
92
93   /**
94    * Gets as short value.
95    *
96    * @param key the key
97    * @return the as short value
98    */
99   public default Short getAsShortValue(String key) {
100     return getAsShortValue(null, key);
101   }
102
103   /**
104    * Gets as short value.
105    *
106    * @param namespace the namespace
107    * @param key       the key
108    * @return the as short value
109    */
110   public default Short getAsShortValue(String namespace, String key) {
111     return getAsShortValue(tenant.get(), namespace, key);
112   }
113
114   /**
115    * Gets as short value.
116    *
117    * @param tenantId  the tenant id
118    * @param namespace the namespace
119    * @param key       the key
120    * @return the as short value
121    */
122   public default Short getAsShortValue(String tenantId, String namespace, String key) {
123     return get(tenantId, namespace, key, Short.class);
124   }
125
126   /**
127    * Gets as integer value.
128    *
129    * @param key the key
130    * @return the as integer value
131    */
132   public default Integer getAsIntegerValue(String key) {
133     return getAsIntegerValue(null, key);
134   }
135
136   /**
137    * Gets as integer value.
138    *
139    * @param namespace the namespace
140    * @param key       the key
141    * @return the as integer value
142    */
143   public default Integer getAsIntegerValue(String namespace, String key) {
144     return getAsIntegerValue(tenant.get(), namespace, key);
145   }
146
147   /**
148    * Gets as integer value.
149    *
150    * @param tenantId  the tenant id
151    * @param namespace the namespace
152    * @param key       the key
153    * @return the as integer value
154    */
155   public default Integer getAsIntegerValue(String tenantId, String namespace, String key) {
156     return get(tenantId, namespace, key, Integer.class);
157   }
158
159   /**
160    * Gets as long value.
161    *
162    * @param key the key
163    * @return the as long value
164    */
165   public default Long getAsLongValue(String key) {
166     return getAsLongValue(null, key);
167   }
168
169   /**
170    * Gets as long value.
171    *
172    * @param namespace the namespace
173    * @param key       the key
174    * @return the as long value
175    */
176   public default Long getAsLongValue(String namespace, String key) {
177     return getAsLongValue(tenant.get(), namespace, key);
178   }
179
180   /**
181    * Gets as long value.
182    *
183    * @param tenantId  the tenant id
184    * @param namespace the namespace
185    * @param key       the key
186    * @return the as long value
187    */
188   public default Long getAsLongValue(String tenantId, String namespace, String key) {
189     return get(tenantId, namespace, key, Long.class);
190   }
191
192   /**
193    * Gets as float value.
194    *
195    * @param key the key
196    * @return the as float value
197    */
198   public default Float getAsFloatValue(String key) {
199     return getAsFloatValue(null, key);
200   }
201
202   /**
203    * Gets as float value.
204    *
205    * @param namespace the namespace
206    * @param key       the key
207    * @return the as float value
208    */
209   public default Float getAsFloatValue(String namespace, String key) {
210     return getAsFloatValue(tenant.get(), namespace, key);
211   }
212
213   /**
214    * Gets as float value.
215    *
216    * @param tenantId  the tenant id
217    * @param namespace the namespace
218    * @param key       the key
219    * @return the as float value
220    */
221   public default Float getAsFloatValue(String tenantId, String namespace, String key) {
222     return get(tenantId, namespace, key, Float.class);
223   }
224
225   /**
226    * Gets as double value.
227    *
228    * @param key the key
229    * @return the as double value
230    */
231   public default Double getAsDoubleValue(String key) {
232     return getAsDoubleValue(null, key);
233   }
234
235   /**
236    * Gets as double value.
237    *
238    * @param namespace the namespace
239    * @param key       the key
240    * @return the as double value
241    */
242   public default Double getAsDoubleValue(String namespace, String key) {
243     return getAsDoubleValue(tenant.get(), namespace, key);
244   }
245
246   /**
247    * Gets as double value.
248    *
249    * @param tenantId  the tenant id
250    * @param namespace the namespace
251    * @param key       the key
252    * @return the as double value
253    */
254   public default Double getAsDoubleValue(String tenantId, String namespace, String key) {
255     return get(tenantId, namespace, key, Double.class);
256   }
257
258   /**
259    * Gets as boolean value.
260    *
261    * @param key the key
262    * @return the as boolean value
263    */
264   public default Boolean getAsBooleanValue(String key) {
265     return getAsBooleanValue(null, key);
266   }
267
268   /**
269    * Gets as boolean value.
270    *
271    * @param namespace the namespace
272    * @param key       the key
273    * @return the as boolean value
274    */
275   public default Boolean getAsBooleanValue(String namespace, String key) {
276     return getAsBooleanValue(tenant.get(), namespace, key);
277   }
278
279   /**
280    * Gets as boolean value.
281    *
282    * @param tenantId  the tenant id
283    * @param namespace the namespace
284    * @param key       the key
285    * @return the as boolean value
286    */
287   public default Boolean getAsBooleanValue(String tenantId, String namespace, String key) {
288     return get(tenantId, namespace, key, Boolean.class);
289   }
290
291   /**
292    * Gets as char value.
293    *
294    * @param key the key
295    * @return the as char value
296    */
297   public default Character getAsCharValue(String key) {
298     return getAsCharValue(null, key);
299   }
300
301   /**
302    * Gets as char value.
303    *
304    * @param namespace the namespace
305    * @param key       the key
306    * @return the as char value
307    */
308   public default Character getAsCharValue(String namespace, String key) {
309     return getAsCharValue(tenant.get(), namespace, key);
310   }
311
312   /**
313    * Gets as char value.
314    *
315    * @param tenantId  the tenant id
316    * @param namespace the namespace
317    * @param key       the key
318    * @return the as char value
319    */
320   public default Character getAsCharValue(String tenantId, String namespace, String key) {
321     return get(tenantId, namespace, key, Character.class);
322   }
323
324   /**
325    * Populate configuration t.
326    *
327    * @param <T>   the type parameter
328    * @param clazz the clazz
329    * @return the t
330    */
331   public default <T> T populateConfiguration(Class<T> clazz) {
332     return populateConfiguration(null, clazz);
333   }
334
335   /**
336    * Populate configuration t.
337    *
338    * @param <T>       the type parameter
339    * @param namespace the namespace
340    * @param clazz     the clazz
341    * @return the t
342    */
343   public default <T> T populateConfiguration(String namespace, Class<T> clazz) {
344     return populateConfiguration(tenant.get(), namespace, clazz);
345   }
346
347   /**
348    * Populate configuration t.
349    *
350    * @param <T>       the type parameter
351    * @param tenantId  the tenant id
352    * @param namespace the namespace
353    * @param clazz     the clazz
354    * @return the t
355    */
356   public default <T> T populateConfiguration(String tenantId, String namespace, Class<T> clazz) {
357     return get(tenantId, namespace, null, clazz, Hint.EXTERNAL_LOOKUP);
358   }
359
360   /**
361    * Gets dynamic configuration.
362    *
363    * @param <T>          the type parameter
364    * @param key          the key
365    * @param clazz        the clazz
366    * @param defaultValue the default value
367    * @return the dynamic configuration
368    */
369   public default <T> DynamicConfiguration<T> getDynamicConfiguration(String key, Class<T> clazz,
370                                                                      T defaultValue) {
371     return getDynamicConfiguration(null, key, clazz, defaultValue);
372   }
373
374   /**
375    * Gets dynamic configuration.
376    *
377    * @param <T>          the type parameter
378    * @param namespace    the namespace
379    * @param key          the key
380    * @param clazz        the clazz
381    * @param defaultValue the default value
382    * @return the dynamic configuration
383    */
384   public default <T> DynamicConfiguration<T> getDynamicConfiguration(String namespace, String key,
385                                                                      Class<T> clazz,
386                                                                      T defaultValue) {
387     return getDynamicConfiguration(tenant.get(), namespace, key, clazz, defaultValue);
388   }
389
390   /**
391    * Gets dynamic configuration.
392    *
393    * @param <T>          the type parameter
394    * @param tenant       the tenant
395    * @param namespace    the namespace
396    * @param key          the key
397    * @param clazz        the clazz
398    * @param defaultValue the default value
399    * @return the dynamic configuration
400    */
401   public default <T> DynamicConfiguration<T> getDynamicConfiguration(String tenant,
402                                                                      String namespace, String key,
403                                                                      Class<T> clazz,
404                                                                      T defaultValue) {
405     return DynamicConfiguration
406         .getDynamicConfiguration(tenant, namespace, key, clazz, defaultValue, this);
407   }
408
409   /**
410    * Gets dynamic configuration values.
411    *
412    * @param <T>          the type parameter
413    * @param key          the key
414    * @param clazz        the clazz
415    * @param defaultValue the default value
416    * @return the dynamic configuration values
417    */
418   public default <T> DynamicConfiguration<List<T>> getDynamicConfigurationValues(String key,
419                                                                                  Class<T> clazz,
420                                                                                  T defaultValue) {
421     return getDynamicConfigurationValues(null, key, clazz, defaultValue);
422   }
423
424   /**
425    * Gets dynamic configuration values.
426    *
427    * @param <T>          the type parameter
428    * @param namespace    the namespace
429    * @param key          the key
430    * @param clazz        the clazz
431    * @param defaultValue the default value
432    * @return the dynamic configuration values
433    */
434   public default <T> DynamicConfiguration<List<T>> getDynamicConfigurationValues(String namespace,
435                                                                                  String key,
436                                                                                  Class<T> clazz,
437                                                                                  T defaultValue) {
438     return getDynamicConfigurationValues(tenant.get(), namespace, key, clazz, defaultValue);
439   }
440
441   /**
442    * Gets dynamic configuration values.
443    *
444    * @param <T>          the type parameter
445    * @param tenant       the tenant
446    * @param namespace    the namespace
447    * @param key          the key
448    * @param clazz        the clazz
449    * @param defaultValue the default value
450    * @return the dynamic configuration values
451    */
452   public default <T> DynamicConfiguration<List<T>> getDynamicConfigurationValues(String tenant,
453                                                                                  String namespace,
454                                                                                  String key,
455                                                                                  Class<T> clazz,
456                                                                                  T defaultValue) {
457     return DynamicConfiguration
458         .getDynConfiguration(tenant, namespace, key, clazz, defaultValue, this);
459   }
460
461   /**
462    * Gets as string values.
463    *
464    * @param key the key
465    * @return the as string values
466    */
467   public default List<String> getAsStringValues(String key) {
468     return getAsStringValues(null, key);
469   }
470
471   /**
472    * Gets as string values.
473    *
474    * @param namespace the namespace
475    * @param key       the key
476    * @return the as string values
477    */
478   public default List<String> getAsStringValues(String namespace, String key) {
479     return getAsStringValues(tenant.get(), namespace, key);
480   }
481
482   /**
483    * Gets as string values.
484    *
485    * @param tenantId  the tenant id
486    * @param namespace the namespace
487    * @param key       the key
488    * @return the as string values
489    */
490   public default List<String> getAsStringValues(String tenantId, String namespace, String key) {
491     String[] tempArray = get(tenantId, namespace, key, String[].class);
492     return tempArray == null ? Arrays.asList() : Arrays.asList(tempArray);
493   }
494
495   /**
496    * Gets as byte values.
497    *
498    * @param key the key
499    * @return the as byte values
500    */
501   public default List<Byte> getAsByteValues(String key) {
502     return getAsByteValues(null, key);
503   }
504
505   /**
506    * Gets as byte values.
507    *
508    * @param namespace the namespace
509    * @param key       the key
510    * @return the as byte values
511    */
512   public default List<Byte> getAsByteValues(String namespace, String key) {
513     return getAsByteValues(tenant.get(), namespace, key);
514   }
515
516   /**
517    * Gets as byte values.
518    *
519    * @param tenantId  the tenant id
520    * @param namespace the namespace
521    * @param key       the key
522    * @return the as byte values
523    */
524   public default List<Byte> getAsByteValues(String tenantId, String namespace, String key) {
525     Byte[] tempArray = get(tenantId, namespace, key, Byte[].class);
526     return tempArray == null ? Arrays.asList() : Arrays.asList(tempArray);
527   }
528
529   /**
530    * Gets as short values.
531    *
532    * @param key the key
533    * @return the as short values
534    */
535   public default List<Short> getAsShortValues(String key) {
536     return getAsShortValues(null, key);
537   }
538
539   /**
540    * Gets as short values.
541    *
542    * @param namespace the namespace
543    * @param key       the key
544    * @return the as short values
545    */
546   public default List<Short> getAsShortValues(String namespace, String key) {
547     return getAsShortValues(tenant.get(), namespace, key);
548   }
549
550   /**
551    * Gets as short values.
552    *
553    * @param tenantId  the tenant id
554    * @param namespace the namespace
555    * @param key       the key
556    * @return the as short values
557    */
558   public default List<Short> getAsShortValues(String tenantId, String namespace, String key) {
559     Short[] tempArray = get(tenantId, namespace, key, Short[].class);
560     return tempArray == null ? Arrays.asList() : Arrays.asList(tempArray);
561   }
562
563   /**
564    * Gets as integer values.
565    *
566    * @param key the key
567    * @return the as integer values
568    */
569   public default List<Integer> getAsIntegerValues(String key) {
570     return getAsIntegerValues(null, key);
571   }
572
573   /**
574    * Gets as integer values.
575    *
576    * @param namespace the namespace
577    * @param key       the key
578    * @return the as integer values
579    */
580   public default List<Integer> getAsIntegerValues(String namespace, String key) {
581     return getAsIntegerValues(tenant.get(), namespace, key);
582   }
583
584   /**
585    * Gets as integer values.
586    *
587    * @param tenantId  the tenant id
588    * @param namespace the namespace
589    * @param key       the key
590    * @return the as integer values
591    */
592   public default List<Integer> getAsIntegerValues(String tenantId, String namespace, String key) {
593     Integer[] tempArray = get(tenantId, namespace, key, Integer[].class);
594     return tempArray == null ? Arrays.asList() : Arrays.asList(tempArray);
595   }
596
597   /**
598    * Gets as double values.
599    *
600    * @param key the key
601    * @return the as double values
602    */
603   public default List<Double> getAsDoubleValues(String key) {
604     return getAsDoubleValues(null, key);
605   }
606
607   /**
608    * Gets as double values.
609    *
610    * @param namespace the namespace
611    * @param key       the key
612    * @return the as double values
613    */
614   public default List<Double> getAsDoubleValues(String namespace, String key) {
615     return getAsDoubleValues(tenant.get(), namespace, key);
616   }
617
618   /**
619    * Gets as double values.
620    *
621    * @param tenantId  the tenant id
622    * @param namespace the namespace
623    * @param key       the key
624    * @return the as double values
625    */
626   public default List<Double> getAsDoubleValues(String tenantId, String namespace, String key) {
627     Double[] tempArray = get(tenantId, namespace, key, Double[].class);
628     return tempArray == null ? Arrays.asList() : Arrays.asList(tempArray);
629   }
630
631   /**
632    * Gets as float values.
633    *
634    * @param key the key
635    * @return the as float values
636    */
637   public default List<Float> getAsFloatValues(String key) {
638     return getAsFloatValues(null, key);
639   }
640
641   /**
642    * Gets as float values.
643    *
644    * @param namespace the namespace
645    * @param key       the key
646    * @return the as float values
647    */
648   public default List<Float> getAsFloatValues(String namespace, String key) {
649     return getAsFloatValues(tenant.get(), namespace, key);
650   }
651
652   /**
653    * Gets as float values.
654    *
655    * @param tenantId  the tenant id
656    * @param namespace the namespace
657    * @param key       the key
658    * @return the as float values
659    */
660   public default List<Float> getAsFloatValues(String tenantId, String namespace, String key) {
661     Float[] tempArray = get(tenantId, namespace, key, Float[].class);
662     return tempArray == null ? Arrays.asList() : Arrays.asList(tempArray);
663   }
664
665   /**
666    * Gets as boolean values.
667    *
668    * @param key the key
669    * @return the as boolean values
670    */
671   public default List<Boolean> getAsBooleanValues(String key) {
672     return getAsBooleanValues(null, key);
673   }
674
675   /**
676    * Gets as boolean values.
677    *
678    * @param namespace the namespace
679    * @param key       the key
680    * @return the as boolean values
681    */
682   public default List<Boolean> getAsBooleanValues(String namespace, String key) {
683     return getAsBooleanValues(tenant.get(), namespace, key);
684   }
685
686   /**
687    * Gets as boolean values.
688    *
689    * @param tenantId  the tenant id
690    * @param namespace the namespace
691    * @param key       the key
692    * @return the as boolean values
693    */
694   public default List<Boolean> getAsBooleanValues(String tenantId, String namespace, String key) {
695     Boolean[] tempArray = get(tenantId, namespace, key, Boolean[].class);
696     return tempArray == null ? Arrays.asList() : Arrays.asList(tempArray);
697   }
698
699   /**
700    * Gets as character values.
701    *
702    * @param key the key
703    * @return the as character values
704    */
705   public default List<Character> getAsCharacterValues(String key) {
706     return getAsCharacterValues(null, key);
707   }
708
709   /**
710    * Gets as character values.
711    *
712    * @param namespace the namespace
713    * @param key       the key
714    * @return the as character values
715    */
716   public default List<Character> getAsCharacterValues(String namespace, String key) {
717     return getAsCharacterValues(tenant.get(), namespace, key);
718   }
719
720   /**
721    * Gets as character values.
722    *
723    * @param tenantId  the tenant id
724    * @param namespace the namespace
725    * @param key       the key
726    * @return the as character values
727    */
728   public default List<Character> getAsCharacterValues(String tenantId, String namespace,
729                                                       String key) {
730     Character[] tempArray = get(tenantId, namespace, key, Character[].class);
731     return tempArray == null ? Arrays.asList() : Arrays.asList(tempArray);
732   }
733
734   /**
735    * Get t.
736    *
737    * @param <T>       the type parameter
738    * @param tenant    the tenant
739    * @param namespace the namespace
740    * @param key       the key
741    * @param clazz     the clazz
742    * @param hints     the hints
743    * @return the t
744    */
745   public <T> T get(String tenant, String namespace, String key, Class<T> clazz, Hint... hints);
746
747   /**
748    * Add configuration change listener.
749    *
750    * @param key    the key
751    * @param myself the myself
752    */
753   public default void addConfigurationChangeListener(String key,
754                                                      ConfigurationChangeListener myself) {
755     addConfigurationChangeListener(null, key, myself);
756   }
757
758   /**
759    * Add configuration change listener.
760    *
761    * @param namespace the namespace
762    * @param key       the key
763    * @param myself    the myself
764    */
765   public default void addConfigurationChangeListener(String namespace, String key,
766                                                      ConfigurationChangeListener myself) {
767     addConfigurationChangeListener(tenant.get(), namespace, key, myself);
768   }
769
770   /**
771    * Add configuration change listener.
772    *
773    * @param tenant    the tenant
774    * @param namespace the namespace
775    * @param key       the key
776    * @param myself    the myself
777    */
778   public void addConfigurationChangeListener(String tenant, String namespace, String key,
779                                              ConfigurationChangeListener myself);
780
781   /**
782    * Remove configuration change listener.
783    *
784    * @param key    the key
785    * @param myself the myself
786    */
787   public default void removeConfigurationChangeListener(String key,
788                                                         ConfigurationChangeListener myself) {
789     removeConfigurationChangeListener(null, key, myself);
790   }
791
792   /**
793    * Remove configuration change listener.
794    *
795    * @param namespace the namespace
796    * @param key       the key
797    * @param myself    the myself
798    */
799   public default void removeConfigurationChangeListener(String namespace, String key,
800                                                         ConfigurationChangeListener myself) {
801     removeConfigurationChangeListener(tenant.get(), namespace, key, myself);
802   }
803
804   /**
805    * Remove configuration change listener.
806    *
807    * @param tenant    the tenant
808    * @param namespace the namespace
809    * @param key       the key
810    * @param myself    the myself
811    */
812   public void removeConfigurationChangeListener(String tenant, String namespace, String key,
813                                                 ConfigurationChangeListener myself);
814
815   public default <T> Map<String, T> populateMap(String key, Class<T> clazz){
816     return populateMap(null, key, clazz);
817   }
818   public default <T> Map<String, T> populateMap(String namespace, String key, Class<T> clazz){
819     return populateMap(tenant.get(), namespace, key, clazz);
820   }
821   public <T> Map<String, T> populateMap(String tenantId, String namespace, String key, Class<T> clazz);
822
823   public default Map generateMap(String key){
824     return generateMap(null, key);
825   }
826   public default Map generateMap(String namespace, String key){
827     return generateMap(tenant.get(), namespace, key);
828   }
829   public Map generateMap(String tenantId, String namespace, String key);
830
831 }