Package jsonvalues
Interface ImmutableMap
-
public interface ImmutableMap
Represents an immutable data structure where pairs of a JsObj are stored. Each immutable Json factoryImmutableJsons
has an implementation of this interface, that can be defined using the methodImmutableJsons.withMap(Class)
. The default immutable implementation thatJsons.immutable
uses is the immutable Scala HashMap.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
contains(String key)
returns true if the map contains the keyJsElem
get(String key)
return the element associated with the key.Optional<JsElem>
getOptional(String key)
return the element associated with the key wrapped into an optional.Map.Entry<String,JsElem>
head()
an entry of this map.boolean
isEmpty()
returns true if this map is emptyIterator<Map.Entry<String,JsElem>>
iterator()
returns an iterator of this map.Set<String>
keys()
returns the keys of this mapImmutableMap
remove(String key)
removes the key associated with this map.int
size()
returns the size of the mapM
tail(String head)
the tail of the map given a head.ImmutableMap
update(String key, JsElem je)
updates the element associated with the key with a new element.
-
-
-
Method Detail
-
remove
ImmutableMap remove(String key)
removes the key associated with this map. It will be called by the library only if the key exists- Parameters:
key
- the given key- Returns:
- a map with the key removed
-
update
ImmutableMap update(String key, JsElem je)
updates the element associated with the key with a new element. It will be called by the library only if the key exists,- Parameters:
key
- the given keyje
- the new element- Returns:
- a map with the key element updated
-
contains
boolean contains(String key)
returns true if the map contains the key- Parameters:
key
- the given key- Returns:
- true if the map contains the key, false if not
-
get
JsElem get(String key)
return the element associated with the key. It will be called by the library only if the key exists, so an error can be thrown if it doesn't- Parameters:
key
- the given key- Returns:
- the element associated with the key or JsNothing if it doesn't exist
-
getOptional
Optional<JsElem> getOptional(String key)
return the element associated with the key wrapped into an optional. It's called by the library without checking the existence of the key.- Parameters:
key
- the given key- Returns:
- the element associated with the key or Optional.empty() if it doesn't exist
-
head
Map.Entry<String,JsElem> head()
an entry of this map. A map is unordered, so any element could be the head. It's only called by the library if the map is not empty.- Returns:
- an entry of this map
-
isEmpty
boolean isEmpty()
returns true if this map is empty- Returns:
- true if empty, false otherwise
-
iterator
Iterator<Map.Entry<String,JsElem>> iterator()
returns an iterator of this map.- Returns:
- an iterator of this map
-
size
int size()
returns the size of the map- Returns:
- the size of the map
-
-