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 immutableSetofSettingobjects, with the additional property that no two settings having the sameidentifiercan be simultaneously present in aSettingsobject.- Author:
- Hans Brende (hansbrende@apache.org)
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontains(Object o)Optional<Setting<?>>find(String identifier)<S extends Setting<?>>
Optional<S>find(S setting)This method is semantically equivalent to:
<E> Eget(Setting<E> defaultSetting)This method is semantically equivalent to:
Iterator<Setting<?>>iterator()static Settingsof()Returns an emptySettingsobject.static Settingsof(Collection<? extends Setting<?>> c)static Settingsof(Setting<?> s)Returns a singletonSettingsobject, containing only the supplied Setting.static Settingsof(Setting<?>... settings)intsize()-
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:
containsin interfaceCollection<Setting<?>>- Specified by:
containsin interfaceSet<Setting<?>>- Overrides:
containsin classAbstractCollection<Setting<?>>
-
size
public int size()
- Specified by:
sizein interfaceCollection<Setting<?>>- Specified by:
sizein interfaceSet<Setting<?>>- Specified by:
sizein classAbstractCollection<Setting<?>>
-
of
public static Settings of(Setting<?> s)
Returns a singletonSettingsobject, containing only the supplied Setting.
-
of
public static Settings of(Setting<?>... settings)
- Parameters:
settings- one or moreSetting's- Returns:
- a
Settingsobject 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 populatedCollectionofSetting's- Returns:
- a
Settingsobject containing the supplied settings. - Throws:
IllegalArgumentException- if any two settings have the same identifier
-
-