Package it.tidalwave.util
Interface TypeSafeMap
-
- All Superinterfaces:
java.lang.Iterable<java.lang.Object>
@Immutable public interface TypeSafeMap extends java.lang.Iterable<java.lang.Object>A map that is type safe, i.e the pairs (key, value) are type-checked. It's immutable.- Author:
- Fabrizio Giudici
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description java.util.Map<Key<?>,java.lang.Object>asMap()Returns the contents as a plainMap.booleancontainsKey(Key<?> key)Checks whether a pair has been stored.<T> Tget(Key<T> key)Deprecated.UsegetOptional(Key)insteadjava.util.Set<Key<?>>getKeys()Returns a set of all the contained keys.default <T> java.util.Optional<T>getOptional(Key<T> key)intgetSize()Returns the size of this map.static TypeSafeMapnewInstance()Creates a new empty instance.static TypeSafeMapofCloned(java.util.Map<Key<?>,java.lang.Object> map)Creates an instance cloning the given map.<T> TypeSafeMapwith(Key<T> key, T value)Create a new instance with an additional pair (key, value=
-
-
-
Method Detail
-
get
@Nonnull @Deprecated <T> T get(@Nonnull Key<T> key) throws NotFoundExceptionDeprecated.UsegetOptional(Key)insteadReturns a value given its key.- Type Parameters:
T- the type- Parameters:
key- the key- Returns:
- the value
- Throws:
NotFoundException- if the key is not found
-
getOptional
@Nonnull default <T> java.util.Optional<T> getOptional(@Nonnull Key<T> key)- Since:
- 3.2-ALPHA-1
-
containsKey
boolean containsKey(@Nonnull Key<?> key)Checks whether a pair has been stored.- Parameters:
key- the key- Returns:
trueif the pair is present
-
getKeys
@Nonnull java.util.Set<Key<?>> getKeys()
Returns a set of all the contained keys.- Returns:
- the keys as a mutable set
-
getSize
@Nonnegative int getSize()
Returns the size of this map.- Returns:
- the size
-
asMap
@Nonnull java.util.Map<Key<?>,java.lang.Object> asMap()
Returns the contents as a plainMap.- Returns:
- the contents as a mutable map
-
newInstance
@Nonnull static TypeSafeMap newInstance()
Creates a new empty instance.- Returns:
- the new instance
- Since:
- 3.2-ALPHA-2
-
ofCloned
@Nonnull static TypeSafeMap ofCloned(@Nonnull java.util.Map<Key<?>,java.lang.Object> map)
Creates an instance cloning the given map.- Parameters:
map- the map to clone- Returns:
- the new instance
- Since:
- 3.2-ALPHA-2
-
with
@Nonnull <T> TypeSafeMap with(@Nonnull Key<T> key, @Nonnull T value)
Create a new instance with an additional pair (key, value=- Parameters:
key- the keyvalue- the value- Returns:
- the new instance
- Since:
- 3.2-ALPHA-2
-
-