- All Implemented Interfaces:
Serializable,Cloneable,Map<String,LinkedHashSet<String>>
A class representing a collection of grouped sets, parsed from a configuration file. In the file, groups are
separated by square brackets
[], and each group contains a set of unique string values. Ungrouped values and
values in a [] group are merged. Duplicate group names are also merged.
Example file format:
[group1] aaa bbb ccc [group2] aaa ccc ddd
- Since:
- Java 17+
- Author:
- Kimi Liu
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> -
Constructor Summary
ConstructorsConstructorDescriptionGroupedSet(File configFile, Charset charset) Constructs aGroupedSetfrom aFile.GroupedSet(String pathOnClasspath) Constructs aGroupedSetby loading a file from the classpath with UTF-8 encoding.GroupedSet(String path, Class<?> clazz, Charset charset) Constructs aGroupedSetfrom a path relative to a given class.GroupedSet(String pathOnClasspath, Charset charset) Constructs aGroupedSetby loading a file from the classpath.GroupedSet(URL url, Charset charset) Constructs aGroupedSetfrom aURL.GroupedSet(Charset charset) Constructs a new, emptyGroupedSetwith a specified charset. -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks if a group contains one or more specified values.booleancontains(String group, Collection<String> values) Checks if a group contains all values from a given collection.getPath()Gets the set of values for a specific group.booleanInitializes thisGroupedSetby loading from a URL.voidload(InputStream settingStream) Loads settings from anInputStream.booleanLoads the settings from the specified URL.voidreload()Reloads the configuration file from the original URL.Methods inherited from class java.util.HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, newHashMap, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, valuesMethods inherited from class java.util.AbstractMap
equals, hashCode, toString
-
Constructor Details
-
GroupedSet
Constructs a new, emptyGroupedSetwith a specified charset. The configuration must be initialized manually by callinginit(java.net.URL, java.nio.charset.Charset)orload(java.net.URL).- Parameters:
charset- The character set to use.
-
GroupedSet
Constructs aGroupedSetby loading a file from the classpath.- Parameters:
pathOnClasspath- The relative path from the root of the classpath.charset- The character set to use.
-
GroupedSet
Constructs aGroupedSetfrom aFile.- Parameters:
configFile- The configuration file.charset- The character set to use.
-
GroupedSet
Constructs aGroupedSetfrom a path relative to a given class.- Parameters:
path- The path relative to the class.clazz- The class to which the path is relative.charset- The character set to use.
-
GroupedSet
Constructs aGroupedSetfrom aURL.- Parameters:
url- The URL of the configuration file.charset- The character set to use.
-
GroupedSet
Constructs aGroupedSetby loading a file from the classpath with UTF-8 encoding.- Parameters:
pathOnClasspath- The relative path from the root of the classpath.
-
-
Method Details
-
init
Initializes thisGroupedSetby loading from a URL.- Parameters:
groupedSetUrl- The URL of the configuration file.charset- The character set to use.- Returns:
trueif loading was successful.
-
load
Loads the settings from the specified URL.- Parameters:
groupedSetUrl- The URL of the configuration file.- Returns:
trueif loading was successful,falseotherwise.
-
reload
public void reload()Reloads the configuration file from the original URL. -
load
Loads settings from anInputStream. This method does not close the stream.- Parameters:
settingStream- The input stream to read from.- Throws:
IOException- if an I/O error occurs.
-
getPath
- Returns:
- The path of the loaded settings file.
-
getGroups
- Returns:
- A set of all group names.
-
getValues
Gets the set of values for a specific group.- Parameters:
group- The group name. If null, the default (ungrouped) group is used.- Returns:
- The set of values, or null if the group does not exist.
-
contains
Checks if a group contains one or more specified values.- Parameters:
group- The group name.value- The primary value to check for.otherValues- Additional values to check for.- Returns:
trueif the group's set contains the value(s).
-
contains
Checks if a group contains all values from a given collection.- Parameters:
group- The group name.values- The collection of values to check for.- Returns:
trueif the group's set contains all the specified values.
-