Package org.apache.any23.configuration
Class Settings
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<Setting<?>>
-
- org.apache.any23.configuration.Settings
-
public final class Settings extends AbstractSet<Setting<?>>
This class represents an immutableSet
ofSetting
objects, with the additional property that no two settings having the sameidentifier
can be simultaneously present in aSettings
object.- Author:
- Hans Brende (hansbrende@apache.org)
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
contains(Object o)
Optional<Setting<?>>
find(String identifier)
<S extends Setting<?>>
Optional<S>find(S setting)
This method is semantically equivalent to:
<E> E
get(Setting<E> defaultSetting)
This method is semantically equivalent to:
Iterator<Setting<?>>
iterator()
static Settings
of()
Returns an emptySettings
object.static Settings
of(Collection<? extends Setting<?>> c)
static Settings
of(Setting<?> s)
Returns a singletonSettings
object, containing only the supplied Setting.static Settings
of(Setting<?>... settings)
int
size()
-
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
-
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, containsAll, isEmpty, remove, retainAll, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
-
-
-
Method Detail
-
find
public Optional<Setting<?>> find(String identifier)
- Parameters:
identifier
- the identifier of the setting to find- Returns:
- the setting with the identifier supplied, if present
-
find
public <S extends Setting<?>> Optional<S> find(S setting)
This method is semantically equivalent to:
find(setting.getIdentifier()).flatMap(s -> s.as(setting))
- Type Parameters:
S
- generic setting type- Parameters:
setting
- a setting key- Returns:
- the setting with the same setting key as the supplied setting, if present.
-
get
public <E> E get(Setting<E> defaultSetting)
This method is semantically equivalent to:
find(defaultSetting).orElse(defaultSetting).getValue()
- Type Parameters:
E
- generic setting type- Parameters:
defaultSetting
- a default key for which to obtain a value set- Returns:
- the value set for
defaultSetting
's key, if present. Otherwise, returnsdefaultSetting
's value.
-
contains
public boolean contains(Object o)
- Specified by:
contains
in interfaceCollection<Setting<?>>
- Specified by:
contains
in interfaceSet<Setting<?>>
- Overrides:
contains
in classAbstractCollection<Setting<?>>
-
size
public int size()
- Specified by:
size
in interfaceCollection<Setting<?>>
- Specified by:
size
in interfaceSet<Setting<?>>
- Specified by:
size
in classAbstractCollection<Setting<?>>
-
of
public static Settings of(Setting<?> s)
Returns a singletonSettings
object, containing only the supplied Setting.
-
of
public static Settings of(Setting<?>... settings)
- Parameters:
settings
- one or moreSetting
's- Returns:
- a
Settings
object containing the supplied settings. For any two settings having the same key, the first will be overwritten by the second. - Throws:
IllegalArgumentException
- if any two settings have the same identifier
-
of
public static Settings of(Collection<? extends Setting<?>> c)
- Parameters:
c
- a populatedCollection
ofSetting
's- Returns:
- a
Settings
object containing the supplied settings. - Throws:
IllegalArgumentException
- if any two settings have the same identifier
-
-