public final class SynchronizedConfig extends java.lang.Object implements ConcurrentCommentedConfig
Only one read or write can happen at the same time. This includes every read and write on sub-configurations, iterator operations, etc.
CommentedConfig.EntryUnmodifiableCommentedConfig.CommentNode| Constructor and Description |
|---|
SynchronizedConfig() |
SynchronizedConfig(ConfigFormat<?> configFormat,
java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.Object>> mapSupplier) |
SynchronizedConfig(ConfigFormat<?> configFormat,
java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.Object>> mapSupplier,
SynchronizedConfig parent) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(java.util.List<java.lang.String> path,
java.lang.Object value)
Adds a config value.
|
boolean |
add(java.lang.String path,
java.lang.Object value)
Adds a config value.
|
void |
addAll(UnmodifiableConfig other)
Adds all the values of a config to this config, without replacing existing entries.
|
<T> T |
apply(java.util.List<java.lang.String> path)
For scala: gets a config value.
|
<R> R |
bulkCommentedRead(java.util.function.Function<? super UnmodifiableCommentedConfig,R> action)
Performs multiple reads as a single atomic operation, and returns a value.
|
<R> R |
bulkCommentedUpdate(java.util.function.Function<? super CommentedConfig,R> action)
Performs multiple reads and writes as a single atomic operation and returns a value.
|
void |
clear()
Removes all values from the config.
|
void |
clearComments()
Removes all the comments from the config.
|
java.util.Map<java.lang.String,java.lang.String> |
commentMap()
Returns a Map view of the config's comments.
|
ConfigFormat<?> |
configFormat()
Returns the config's format.
|
boolean |
contains(java.util.List<java.lang.String> path)
Checks if the config contains a value at some path.
|
boolean |
containsComment(java.util.List<java.lang.String> path)
Checks if the config contains a comment at some path.
|
static SynchronizedConfig |
convert(Config c) |
SynchronizedConfig |
createSubConfig()
Creates a new sub config of this config, as created when a subconfig's creation is
implied by
Config.set(List, Object) or Config.add(List, Object). |
java.util.Set<? extends CommentedConfig.Entry> |
entrySet()
Returns a Set view of the config's entries.
|
boolean |
equals(java.lang.Object obj) |
<T> T |
get(java.util.List<java.lang.String> path)
Gets a value from the config.
|
java.lang.String |
getComment(java.util.List<java.lang.String> path)
Gets a comment from the config.
|
java.util.Map<java.lang.String,UnmodifiableCommentedConfig.CommentNode> |
getComments()
Returns a Map containing a deep copy of all the comments in the config.
|
void |
getComments(java.util.Map<java.lang.String,UnmodifiableCommentedConfig.CommentNode> destination)
Puts all the config's comments to the specified map.
|
<T> T |
getRaw(java.util.List<java.lang.String> path)
Gets a value from the config.
|
int |
hashCode() |
boolean |
isEmpty()
Checks if the config is empty.
|
boolean |
isNull(java.util.List<java.lang.String> path)
Checks if the config contains a null value at some path.
|
void |
putAll(UnmodifiableConfig other)
Copies all the values of a config into this config.
|
void |
putAllComments(java.util.Map<java.lang.String,UnmodifiableCommentedConfig.CommentNode> comments)
Puts the comments in the given map to this config.
|
void |
putAllComments(UnmodifiableCommentedConfig commentedConfig)
Puts the comments in the given config to this config.
|
<T> T |
remove(java.util.List<java.lang.String> path)
Removes a value from the config.
|
<T> T |
remove(java.lang.String path)
Removes a value from the config.
|
void |
removeAll(UnmodifiableConfig toRemove)
Removes all the values of the given config from this config.
|
java.lang.String |
removeComment(java.util.List<java.lang.String> path)
Removes a comment from the config.
|
void |
replaceContentBy(Config newContent)
Atomically replaces the content of this config by the content of the specified config.
|
void |
replaceContentBy(SynchronizedConfig newContent)
Atomically replaces the content of this config by the content of the specified config.
|
<T> T |
set(java.util.List<java.lang.String> path,
java.lang.Object value)
Sets a config value.
|
<T> T |
set(java.lang.String path,
java.lang.Object value)
Sets a config value.
|
java.lang.String |
setComment(java.util.List<java.lang.String> path,
java.lang.String comment)
Sets a config comment.
|
int |
size()
Gets the size of the config.
|
java.lang.String |
toString() |
UnmodifiableCommentedConfig |
unmodifiable()
Returns an Unmodifiable view of the config.
|
void |
update(java.util.List<java.lang.String> path,
java.lang.Object value)
For scala: sets a config value.
|
java.util.Map<java.lang.String,java.lang.Object> |
valueMap()
Deprecated.
This method is deprecated on SynchronizedConfig. Because a conversion is applied to the value that is
added to the map with
put, modifying the value after the put will, most of the time, not be reflected
to the config, i.e. once something is added to the valueMap(), you loose control over it. |
clone, finalize, getClass, notify, notifyAll, wait, wait, waitbulkCommentedRead, bulkCommentedUpdate, bulkRead, bulkUpdatechecked, concurrentCopy, concurrentCopy, concurrentCopy, concurrentCopy, copy, copy, copy, copy, copy, copy, copy, copy, fake, inMemory, inMemoryConcurrent, of, of, ofConcurrent, removeComment, setComment, wrapcontainsComment, fake, getComment, getOptionalComment, getOptionalCommentbulkRead, bulkUpdategetDefaultMapCreator, getDefaultMapCreator, inMemoryUniversal, inMemoryUniversalConcurrent, isInsertionOrderPreserved, of, of, ofConcurrent, setInsertionOrderPreserved, updateapply, contains, get, getByte, getByte, getByteOrElse, getByteOrElse, getChar, getChar, getCharOrElse, getCharOrElse, getEnum, getEnum, getEnum, getEnum, getEnumOrElse, getEnumOrElse, getEnumOrElse, getEnumOrElse, getEnumOrElse, getEnumOrElse, getEnumOrElse, getEnumOrElse, getInt, getInt, getIntOrElse, getIntOrElse, getIntOrElse, getIntOrElse, getLong, getLong, getLongOrElse, getLongOrElse, getLongOrElse, getLongOrElse, getOptional, getOptional, getOptionalEnum, getOptionalEnum, getOptionalEnum, getOptionalEnum, getOptionalInt, getOptionalInt, getOptionalLong, getOptionalLong, getOrElse, getOrElse, getOrElse, getOrElse, getRaw, getShort, getShort, getShortOrElse, getShortOrElse, isNullpublic SynchronizedConfig()
public SynchronizedConfig(ConfigFormat<?> configFormat, java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.Object>> mapSupplier)
public SynchronizedConfig(ConfigFormat<?> configFormat, java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.Object>> mapSupplier, SynchronizedConfig parent)
public static SynchronizedConfig convert(Config c)
public void replaceContentBy(SynchronizedConfig newContent)
newContent - the new content (cannot be used anymore after this)public void replaceContentBy(Config newContent)
newContent - the new content (cannot be used anymore after this)public <R> R bulkCommentedRead(java.util.function.Function<? super UnmodifiableCommentedConfig,R> action)
ConcurrentCommentedConfigIt is guaranteed that the content of the config, accessed through the provided "view", will not change during the entire operation. The configuration must be used exclusively through the object passed to the consumer (the "view"), not with the original reference. After the bulk operation, the view cannot be used anymore.
Here is an example:
config.bulkCommentedRead(conf -> {
Object value = conf.get("a.b.c");
String comment = conf.getComment("a.b.c");
// note that we use `conf` and not `config`!
});
If you don't need access to the comments, prefer to use ConcurrentCommentedConfig.bulkRead(Function),
sine it may provide a better performance.
bulkCommentedRead in interface ConcurrentCommentedConfigR - the type of the function's resultaction - a function to execute on the configuration viewpublic <R> R bulkCommentedUpdate(java.util.function.Function<? super CommentedConfig,R> action)
ConcurrentCommentedConfigIt is guaranteed that the content of the config, accessed through the provided "view", will not be concurrently modified by other threads during the entire bulk operation. The configuration must be used exclusively through the object passed to the consumer (the "view"), not with the original reference. After the bulk operation, the view cannot be used anymore.
Here is an example:
Object value = config.bulkCommentedUpdate(conf -> {
Object value = conf.get("a.b.c");
String comment = conf.getComment("a.b.c");
conf.setComment("a.b.c", comment + "\nAdditional comment here.");
// note that we use `conf` and not `config`!
return value;
});
If you don't need access to the comments, prefer to use ConcurrentCommentedConfig.bulkUpdate(Function),
since it may provide a better performance. Also, if you only have to read the configuration,
prefer to use ConcurrentCommentedConfig.bulkCommentedRead(Function).
bulkCommentedUpdate in interface ConcurrentCommentedConfigR - the type of the function's resultaction - a function to execute on the configuration viewpublic boolean add(java.util.List<java.lang.String> path,
java.lang.Object value)
Configpublic void clearComments()
CommentedConfigclearComments in interface CommentedConfigpublic java.util.Map<java.lang.String,java.lang.String> commentMap()
CommentedConfigThe comment map contains only the comments of the direct elements of the configuration, not the comments of their sub-elements.
commentMap in interface CommentedConfigcommentMap in interface UnmodifiableCommentedConfigpublic java.lang.String removeComment(java.util.List<java.lang.String> path)
CommentedConfigremoveComment in interface CommentedConfigpath - the comment's path, each element of the list is a different part of the path.nullpublic java.lang.String setComment(java.util.List<java.lang.String> path,
java.lang.String comment)
CommentedConfigsetComment in interface CommentedConfigpath - the comment's path, each element of the list is a different part of the path.comment - the comment to setnullpublic boolean containsComment(java.util.List<java.lang.String> path)
UnmodifiableCommentedConfigcontainsComment in interface UnmodifiableCommentedConfigpath - the path to check, each element of the list is a different part of the path.true if the path is associated with a comment, false if it's not.public java.lang.String getComment(java.util.List<java.lang.String> path)
UnmodifiableCommentedConfiggetComment in interface UnmodifiableCommentedConfigpath - the comment's path, each element of the list is a different part of the path.null if there is none.public ConfigFormat<?> configFormat()
UnmodifiableConfigconfigFormat in interface UnmodifiableConfigpublic void clear()
Configpublic SynchronizedConfig createSubConfig()
ConfigConfig.set(List, Object) or Config.add(List, Object).createSubConfig in interface CommentedConfigcreateSubConfig in interface ConcurrentCommentedConfigcreateSubConfig in interface ConcurrentConfigcreateSubConfig in interface Configpublic java.util.Set<? extends CommentedConfig.Entry> entrySet()
UnmodifiableConfigentrySet in interface CommentedConfigentrySet in interface ConfigentrySet in interface UnmodifiableCommentedConfigentrySet in interface UnmodifiableConfigpublic <T> T remove(java.util.List<java.lang.String> path)
Configpublic <T> T set(java.util.List<java.lang.String> path,
java.lang.Object value)
Configpublic java.lang.String toString()
toString in class java.lang.Objectpublic boolean contains(java.util.List<java.lang.String> path)
UnmodifiableConfigcontains in interface UnmodifiableConfigpath - the path to check, each element of the list is a different part of the path.true if the path is associated with a value, false if it's not.public boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic <T> T getRaw(java.util.List<java.lang.String> path)
UnmodifiableConfigNullObject.NULL_OBJECT to null.getRaw in interface UnmodifiableConfigT - the value's typepath - the value's path, each element of the list is a different part of the path.null if there is no such value.public int hashCode()
hashCode in class java.lang.Objectpublic boolean isEmpty()
UnmodifiableConfigisEmpty in interface UnmodifiableConfigtrue if the config is empty, false if it contains at least one
element.public int size()
UnmodifiableConfigsize in interface UnmodifiableConfig@Deprecated public java.util.Map<java.lang.String,java.lang.Object> valueMap()
put, modifying the value after the put will, most of the time, not be reflected
to the config, i.e. once something is added to the valueMap(), you loose control over it.valueMap in interface ConfigvalueMap in interface UnmodifiableConfigpublic boolean add(java.lang.String path,
java.lang.Object value)
Configpublic void addAll(UnmodifiableConfig other)
Configpublic void putAll(UnmodifiableConfig other)
Configpublic <T> T remove(java.lang.String path)
Configpublic void removeAll(UnmodifiableConfig toRemove)
Configpublic <T> T set(java.lang.String path,
java.lang.Object value)
Configpublic UnmodifiableCommentedConfig unmodifiable()
Configunmodifiable in interface CommentedConfigunmodifiable in interface Configpublic void update(java.util.List<java.lang.String> path,
java.lang.Object value)
Configupdate in interface Configpath - the value's path, each element of the list is a different part of the path.value - the value to setConfig.set(List, Object)public <T> T apply(java.util.List<java.lang.String> path)
UnmodifiableConfigapply in interface UnmodifiableConfigT - the value's typepath - the value's path, each element of the list is a different part of the path.UnmodifiableConfig.get(List)public <T> T get(java.util.List<java.lang.String> path)
UnmodifiableConfigget in interface UnmodifiableConfigT - the value's typepath - the value's path, each element of the list is a different part of the path.null if there is no such value.public boolean isNull(java.util.List<java.lang.String> path)
UnmodifiableConfigisNull in interface UnmodifiableConfigpath - the path to check, each element of the list is a different part of the path.true if the path is associated with NullObject.NULL_OBJECT,
false if it's associated with another value or with no value.public java.util.Map<java.lang.String,UnmodifiableCommentedConfig.CommentNode> getComments()
UnmodifiableCommentedConfiggetComments in interface UnmodifiableCommentedConfigpublic void getComments(java.util.Map<java.lang.String,UnmodifiableCommentedConfig.CommentNode> destination)
UnmodifiableCommentedConfiggetComments in interface UnmodifiableCommentedConfigdestination - the map where to put the comments.public void putAllComments(java.util.Map<java.lang.String,UnmodifiableCommentedConfig.CommentNode> comments)
CommentedConfigputAllComments in interface CommentedConfigcomments - the comments to setpublic void putAllComments(UnmodifiableCommentedConfig commentedConfig)
CommentedConfigThe comments are copied recursively, but missing sub-configurations are NOT created.
putAllComments in interface CommentedConfigcommentedConfig - the config to copy its comments