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 mapM
empty()
It creates an empty map of the same type of this instanceV
emptyArray()
returns an empty seq.JsElem
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 mapM
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.M
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
-
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
-
tail
M tail(String head)
the tail of the map given a head. It's only called by the library if the map is not empty.- Parameters:
head
- the element returned byhead()
- Returns:
- the tail of the map given a head
-
empty
M empty()
It creates an empty map of the same type of this instance- Returns:
- an empty map of the same type
-
remove
M 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
M 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
-
emptyArray
V emptyArray()
returns an empty seq. Every data structure defined to model a Json object has its dual to model a Json Array and has to be defined when creating a Json factory.- Returns:
- en empty seq of the dual data structure to model JsArray
-
-