-
- All Known Subinterfaces:
TcConfig,TcConfigSection
- All Known Implementing Classes:
FileConfig,FileConfigSection,MemoryConfigSection
public interface DataStorageRepresents configuration section data storage.- Since:
- 1.0
- See Also:
TcConfigSection
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default <T> Tcompute(@NotNull String path, @NotNull Class<T> type, @NotNull BiFunction<String,? super T,? extends T> remappingFn)Attempts to compute a mapping for the given path and its current mapped value (or null if there is no current mapping).default <T> TcomputeIfAbsent(@NotNull String path, @NotNull Class<T> type, @NotNull Function<String,? extends T> mappingFn)Gets the value if existed, else this method attempts to compute its value using the given mapping function and enters it into this storage unless null.default <T> TcomputeIfPresent(@NotNull String path, @NotNull Class<T> type, @NotNull BiFunction<String,? super T,? extends T> remappingFn)Attempts to compute a new mapping given the key and its current mapped value, if the value for the given path is present.default booleancontains(@NotNull String path)Checks if this storage contains this value path.default <T> booleancontains(@NotNull String path, @NotNull Class<T> type)Checks if this storage contains this path and the value is instance of the type.default @NotNull Optional<?>find(@NotNull String path)Finds the object with given path.default <T> @NotNull Optional<T>find(@NotNull String path, Class<T> type)Finds the object with given path.@Nullable Objectget(@NotNull String path)Gets the object with given path.<T> Tget(@NotNull String path, @NotNull Class<T> type)Gets the value with given path.default booleangetBoolean(@NotNull String path)Gets the boolean value with given path, returnsfalsewhen value wasn't existed.default doublegetDouble(@NotNull String path)Gets the double value with given path, returns0Dwhen value wasn't existed.default @UnmodifiableView @NotNull List<Double>getDoubleList(@NotNull String path)Gets theList<Double>value with given path.default intgetInt(@NotNull String path)Gets the int value with given path, returns0when value wasn't existed.default @UnmodifiableView @NotNull List<Integer>getIntegerList(@NotNull String path)Gets theList<Integer>value with given path.default @UnmodifiableView @NotNull Set<String>getKeys()Gets the shallow set of key that contains in this storage.@UnmodifiableView @NotNull Set<String>getKeys(boolean deep)Gets the set of key that contains in this storage.default @UnmodifiableView @NotNull List<?>getList(@NotNull String path)Gets theListvalue with given path.default <T> @UnmodifiableView @NotNull List<T>getList(@NotNull String path, @NotNull Class<T> type)Gets theListvalue with given path.default longgetLong(@NotNull String path)Gets the long value with given path, returns0Lwhen value wasn't existed.default @UnmodifiableView @NotNull List<Map<String,?>>getMapList(@NotNull String path)Gets theList<Map<String, ?>>value with given path.<T> TgetOrDefault(@NotNull String path, @NotNull Class<T> type, T def)Gets the value with given path, returns the default value if requested value is null.@Nullable ObjectgetOrDefault(@NotNull String path, @Nullable Object def)Gets the value with given path, returns the default value if requested value is null.default @NotNull StringgetString(@NotNull String path)Gets theStringvalue with given path.default @UnmodifiableView @NotNull List<String>getStringList(@NotNull String path)Gets theList<String>value with given path.@NotNull Map<String,?>getValues()Gets the copy map of values.default booleanisBoolean(@NotNull String path)Checks if this storage contains this path and the value type isboolean.default booleanisDouble(@NotNull String path)Checks if this storage contains this path and the value type isdouble.default booleanisInt(@NotNull String path)Checks if this storage contains this path and the value type isint.default booleanisList(@NotNull String path)Checks if this storage contains this path and the value type isList.default booleanisLong(@NotNull String path)Checks if this storage contains this path and the value type islong.default booleanisString(@NotNull String path)Checks if this storage contains this path and the value type isString.default <T> Tmerge(@NotNull String path, @NotNull Class<T> type, T value, @NotNull BiFunction<? super T,? super T,? extends T> remappingFn)Gets the value and recomputes it, then put it into this storage.default @Nullable Objectremove(@NotNull String path)Removes the value where path indicated.default booleanreplace(@NotNull String path, @NotNull Object oldValue, @Nullable Object newValue)Replaces the value for the given path.@Nullable Objectset(@NotNull String path, @Nullable Object value)Sets the value to which the path is specified.@Nullable ObjectsetIfAbsent(@NotNull String path, @Nullable Object value)Sets the value to which the path is specified, the action is canceled when the path isn't in this storage.
-
-
-
Method Detail
-
contains
default <T> boolean contains(@NotNull @NotNull String path, @NotNull @NotNull Class<T> type)
Checks if this storage contains this path and the value is instance of the type.- Type Parameters:
T- Type of value- Parameters:
path- Path to value.type- The class type of value.- Returns:
- True if this storage contains this path and the value is instance of the type.
-
contains
default boolean contains(@NotNull @NotNull String path)
Checks if this storage contains this value path.- Parameters:
path- Path to value.- Returns:
- True if this storage contains this path.
-
get
@Nullable <T> T get(@NotNull @NotNull String path, @NotNull @NotNull Class<T> type) throws TcConfigSerializationException
Gets the value with given path.If the requested is instance of
TcConfigSection, the requested value will be deserialized to new object.If the requested value isn't instance of the type, this method will return
null.- Type Parameters:
T- Type of value.- Parameters:
path- Path to value.type- The class type of value.- Returns:
- The requested object.
- Throws:
TcConfigSerializationException- Thrown when no serializer represented the type.- See Also:
TcConfigSerializations.deserializeObject(Class, Map)
-
getOrDefault
@Nullable <T> T getOrDefault(@NotNull @NotNull String path, @NotNull @NotNull Class<T> type, @Nullable T def) throws TcConfigSerializationException
Gets the value with given path, returns the default value if requested value is null.If the requested is instance of
TcConfigSection, the requested value will be deserialized to new object.- Type Parameters:
T- Type of value.- Parameters:
path- Path to value.type- The class type of value.def- The default value.- Returns:
- The requested object.
- Throws:
TcConfigSerializationException- Thrown when no serializer represented the type.- See Also:
TcConfigSerializations.deserializeObject(Class, Map)
-
get
@Nullable @Nullable Object get(@NotNull @NotNull String path)
Gets the object with given path.- Parameters:
path- Path to object.- Returns:
- The requested object.
-
getOrDefault
@Nullable @Nullable Object getOrDefault(@NotNull @NotNull String path, @Nullable @Nullable Object def)
Gets the value with given path, returns the default value if requested value is null.- Parameters:
path- Path to value.def- The default value.- Returns:
- The requested object.
-
find
@NotNull default <T> @NotNull Optional<T> find(@NotNull @NotNull String path, Class<T> type)
Finds the object with given path.If the requested value isn't instance of the type, this method will return
Optional.empty().- Type Parameters:
T- Type of value.- Parameters:
path- Value path to find.type- The class of value.- Returns:
- Optional wrap the requested object.
-
find
@NotNull default @NotNull Optional<?> find(@NotNull @NotNull String path)
Finds the object with given path.- Parameters:
path- Value path to find.- Returns:
- Optional wrap the requested object.
-
set
@Nullable @Nullable Object set(@NotNull @NotNull String path, @Nullable @Nullable Object value)
Sets the value to which the path is specified.If
valueis null, the path will be removed.- Parameters:
path- The path where the value will be set.value- The value to set.- Returns:
- The previous value.
-
setIfAbsent
@Nullable @Nullable Object setIfAbsent(@NotNull @NotNull String path, @Nullable @Nullable Object value)
Sets the value to which the path is specified, the action is canceled when the path isn't in this storage.- Parameters:
path- The path where the value will be set.value- The value to set.- Returns:
- The previous value.
-
remove
@Nullable default @Nullable Object remove(@NotNull @NotNull String path)
Removes the value where path indicated.- Parameters:
path- The path where the value will be removed.- Returns:
- The previous value.
- See Also:
set(String, Object)
-
replace
default boolean replace(@NotNull @NotNull String path, @NotNull @NotNull Object oldValue, @Nullable @Nullable Object newValue)
Replaces the value for the given path.- Parameters:
path- Path to value.oldValue- The expected value.newValue- The value to replace.- Returns:
- True if the value was replaced.
-
computeIfAbsent
@Nullable default <T> T computeIfAbsent(@NotNull @NotNull String path, @NotNull @NotNull Class<T> type, @NotNull @NotNull Function<String,? extends T> mappingFn)
Gets the value if existed, else this method attempts to compute its value using the given mapping function and enters it into this storage unless null.- Type Parameters:
T- Type of value.- Parameters:
path- Path to value.type- The class type of value.mappingFn- The mapping function to compute a value.- Returns:
- The current (existing or computed) value, or null if the computed value is null.
-
computeIfPresent
@Nullable default <T> T computeIfPresent(@NotNull @NotNull String path, @NotNull @NotNull Class<T> type, @NotNull @NotNull BiFunction<String,? super T,? extends T> remappingFn)
Attempts to compute a new mapping given the key and its current mapped value, if the value for the given path is present.- Type Parameters:
T- Type of value.- Parameters:
path- Path to value.type- The class type of value.remappingFn- The remapping function to compute a value.- Returns:
- The new value.
-
compute
@Nullable default <T> T compute(@NotNull @NotNull String path, @NotNull @NotNull Class<T> type, @NotNull @NotNull BiFunction<String,? super T,? extends T> remappingFn)
Attempts to compute a mapping for the given path and its current mapped value (or null if there is no current mapping).- Type Parameters:
T- Type of value.- Parameters:
path- Path to value.type- The class type of value.remappingFn- The remapping function to compute a value.- Returns:
- The new value.
-
merge
@Nullable default <T> T merge(@NotNull @NotNull String path, @NotNull @NotNull Class<T> type, @Nullable T value, @NotNull @NotNull BiFunction<? super T,? super T,? extends T> remappingFn)
Gets the value and recomputes it, then put it into this storage.- Type Parameters:
T- Type of value- Parameters:
path- Path to object.type- The class type of value.value- The value to set.remappingFn- The remapping function to recompute a value if present- Returns:
- The new value.
-
getKeys
@NotNull default @UnmodifiableView @NotNull Set<String> getKeys()
Gets the shallow set of key that contains in this storage.- Returns:
- Shallow set of keys contained within this storage.
- See Also:
getKeys(boolean)
-
getKeys
@NotNull @UnmodifiableView @NotNull Set<String> getKeys(boolean deep)
Gets the set of key that contains in this storage.If
deepistrue, this method will take the keys until the key isn't the key of the storage. Otherwise, this method only takes the 1st layer of this storage.- Parameters:
deep- Whether to take the keys of the child storage.- Returns:
- Set of keys contained within this storage.
-
getValues
@NotNull @NotNull Map<String,?> getValues()
Gets the copy map of values.Mapwill be representingTcConfigSection.- Returns:
- Copy map of values.
-
isInt
default boolean isInt(@NotNull @NotNull String path)
Checks if this storage contains this path and the value type isint.- Parameters:
path- Path to int.- Returns:
- True if this storage contains this path and the value type is
int. - See Also:
contains(String, Class)
-
getInt
default int getInt(@NotNull @NotNull String path)
Gets the int value with given path, returns0when value wasn't existed.- Parameters:
path- Path to int.- Returns:
- The requested int.
- See Also:
get(String)
-
isLong
default boolean isLong(@NotNull @NotNull String path)
Checks if this storage contains this path and the value type islong.- Parameters:
path- Path to long.- Returns:
- True if this storage contains this path and the value type is
long. - See Also:
contains(String, Class)
-
getLong
default long getLong(@NotNull @NotNull String path)
Gets the long value with given path, returns0Lwhen value wasn't existed.- Parameters:
path- Path to long.- Returns:
- The requested long.
- See Also:
get(String)
-
isDouble
default boolean isDouble(@NotNull @NotNull String path)
Checks if this storage contains this path and the value type isdouble.- Parameters:
path- Path to double.- Returns:
- True if this storage contains this path and the value type is
double. - See Also:
contains(String, Class)
-
getDouble
default double getDouble(@NotNull @NotNull String path)
Gets the double value with given path, returns0Dwhen value wasn't existed.- Parameters:
path- Path to double.- Returns:
- The requested double.
- See Also:
get(String)
-
isBoolean
default boolean isBoolean(@NotNull @NotNull String path)
Checks if this storage contains this path and the value type isboolean.- Parameters:
path- Path to double.- Returns:
- True if this storage contains this path and the value type is
boolean. - See Also:
contains(String, Class)
-
getBoolean
default boolean getBoolean(@NotNull @NotNull String path)
Gets the boolean value with given path, returnsfalsewhen value wasn't existed.- Parameters:
path- Path to boolean.- Returns:
- The requested boolean.
- See Also:
get(String)
-
isString
default boolean isString(@NotNull @NotNull String path)
Checks if this storage contains this path and the value type isString.- Parameters:
path- Path to string.- Returns:
- True if this storage contains this path and the value type is
String. - See Also:
contains(String, Class)
-
getString
@NotNull default @NotNull String getString(@NotNull @NotNull String path)
Gets theStringvalue with given path.- Parameters:
path- Path to string.- Returns:
- The requested string.
- See Also:
get(String),String.valueOf(Object)
-
isList
default boolean isList(@NotNull @NotNull String path)
Checks if this storage contains this path and the value type isList.- Parameters:
path- Path to list.- Returns:
- True if this storage contains this path and the value type is
List. - See Also:
contains(String, Class)
-
getList
@NotNull default @UnmodifiableView @NotNull List<?> getList(@NotNull @NotNull String path)
Gets theListvalue with given path.- Parameters:
path- Path to list.- Returns:
- The requested list.
- See Also:
get(String)
-
getList
@NotNull default <T> @UnmodifiableView @NotNull List<T> getList(@NotNull @NotNull String path, @NotNull @NotNull Class<T> type)
Gets theListvalue with given path.- Type Parameters:
T- Type of element- Parameters:
path- Path to list.type- The class type of list element- Returns:
- The requested list.
- See Also:
get(String)
-
getStringList
@NotNull default @UnmodifiableView @NotNull List<String> getStringList(@NotNull @NotNull String path)
Gets theList<String>value with given path.- Parameters:
path- Path to list.- Returns:
- The requested list.
- See Also:
get(String)
-
getIntegerList
@NotNull default @UnmodifiableView @NotNull List<Integer> getIntegerList(@NotNull @NotNull String path)
Gets theList<Integer>value with given path.- Parameters:
path- Path to list.- Returns:
- The requested list.
- See Also:
get(String)
-
getDoubleList
@NotNull default @UnmodifiableView @NotNull List<Double> getDoubleList(@NotNull @NotNull String path)
Gets theList<Double>value with given path.- Parameters:
path- Path to list.- Returns:
- The requested list.
- See Also:
get(String)
-
getMapList
@NotNull default @UnmodifiableView @NotNull List<Map<String,?>> getMapList(@NotNull @NotNull String path)
Gets theList<Map<String, ?>>value with given path.- Parameters:
path- Path to list.- Returns:
- The requested list.
- See Also:
get(String)
-
-