com.netflix.archaius.api.PropertyRepository Maven / Gradle / Ivy
package com.netflix.archaius.api;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import java.util.Set;
public interface PropertyRepository {
/**
* Fetch a property of a specific type. A {@link Property} object is returned regardless of
* whether a key for it exists in the backing configuration. The {@link Property} is attached
* to a dynamic configuration system and will have its value automatically updated
* whenever the backing configuration is updated. Fallback properties and default values
* may be specified through the {@link Property} API.
*
* This method does not handle polymorphic return types such as collections. Use {@link #get(String, Type)} or one
* of the specialized utility methods in the interface for that case.
*
* @param key Property name
* @param type The type for the property value. This *can* be an array type, but not a primitive array
* (ie, you can use {@code Integer[].class} but not {@code int[].class})
*/
Property get(String key, Class type);
/**
* Fetch a property of a specific type. A {@link Property} object is returned regardless of
* whether a key for it exists in the backing configuration. The {@link Property} is attached
* to a dynamic configuration system and will have its value automatically updated
* whenever the backing configuration is updated. Fallback properties and default values
* may be specified through the {@link Property} API.
*
* Use this method to request polymorphic return types such as collections. See the utility methods in
* {@link ArchaiusType} to get types for lists, sets and maps, or call the utility methods in this interface directly.
*
* @see ArchaiusType#forListOf(Class)
* @see ArchaiusType#forSetOf(Class)
* @see ArchaiusType#forMapOf(Class, Class)
* @param key Property name
* @param type Type of property value.
*/
Property get(String key, Type type);
/**
* Fetch a property with a {@link List} value. This is just an utility wrapper around {@link #get(String, Type)}.
* See that method's documentation for more details.
*/
default Property> getList(String key, Class listElementType) {
return get(key, ArchaiusType.forListOf(listElementType));
}
/**
* Fetch a property with a {@link Set} value. This is just an utility wrapper around {@link #get(String, Type)}.
* See that method's documentation for more details.
*/
default Property> getSet(String key, Class setElementType) {
return get(key, ArchaiusType.forSetOf(setElementType));
}
/**
* Fetch a property with a {@link Map} value. This is just an utility wrapper around {@link #get(String, Type)}.
* See that method's documentation for more details.
*/
default Property