Package jsonvalues
Interface MutableMap
-
public interface MutableMap
Represents a mutable data structure where pairs of a JsObj are stored. Each mutable Json factoryMutableJsons
has an implementation of this interface, that can be defined using the methodMutableJsons.withMap(Class)
. The default mutable implementation thatJsons.mutable
uses is the JavaHashMap
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
contains(String key)
returns true if the map contains the keyMutableMap
copy()
creates and returns a copy of this mapJsElem
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 mapvoid
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.void
update(String key, JsElem je)
updates the element associated with the key with a new element.
-
-
-
Method Detail
-
copy
MutableMap copy()
creates and returns a copy of this map- Returns:
- a new instance
-
remove
void 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
-
update
void 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
-
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
-
-