Interface StringObjectMap<M extends StringObjectMap<M>>

Type Parameters:
M - the type extending this interface
All Superinterfaces:
Map<String,Object>
All Known Subinterfaces:
Document, SearchDocument
All Known Implementing Classes:
DefaultStringObjectMap, EntityAsMap, SearchDocumentAdapter, Settings

public interface StringObjectMap<M extends StringObjectMap<M>> extends Map<String,Object>
Defines an interface for a Map<String, Object> with additional convenience methods. All iterators must preserve original insertion order.

StringObjectMap does not allow null keys. It allows null values.

Implementing classes can bei either mutable or immutable. In case a subclass is immutable, its methods may throw UnsupportedOperationException when calling modifying methods. *

Since:
4.2
Author:
Peter-Josef Meisch
  • Method Details

    • append

      default M append(String key, Object value)
      Map.put(Object, Object) the key/value tuple and return this object.
      Parameters:
      key - key with which the specified value is to be associated. must not be null.
      value - value to be associated with the specified key.
      Returns:
      this object.
    • get

      @Nullable default <T> T get(Object key, Class<T> type)
      Returns the value to which the specified key is mapped, or null if this document contains no mapping for the key. The value is casted within the method which makes it useful for calling code as it does not require casting on the calling side. If the value type is not assignable to type, then this method throws ClassCastException.
      Type Parameters:
      T - expected return type.
      Parameters:
      key - the key whose associated value is to be returned
      type - the expected return value type.
      Returns:
      the value to which the specified key is mapped, or null if this document contains no mapping for the key.
      Throws:
      ClassCastException - if the value of the given key is not of type T.
    • getBoolean

      @Nullable default Boolean getBoolean(String key)
      Returns the value to which the specified key is mapped, or null if this document contains no mapping for the key. If the value type is not a Boolean, then this method throws ClassCastException.
      Parameters:
      key - the key whose associated value is to be returned
      Returns:
      the value to which the specified key is mapped, or null if this document contains no mapping for the key.
      Throws:
      ClassCastException - if the value of the given key is not a Boolean.
    • getBooleanOrDefault

      default boolean getBooleanOrDefault(String key, boolean defaultValue)
      Returns the value to which the specified key is mapped or defaultValue if this document contains no mapping for the key. If the value type is not a Boolean, then this method throws ClassCastException.
      Parameters:
      key - the key whose associated value is to be returned
      Returns:
      the value to which the specified key is mapped or defaultValue if this document contains no mapping for the key.
      Throws:
      ClassCastException - if the value of the given key is not a Boolean.
    • getBooleanOrDefault

      default boolean getBooleanOrDefault(String key, BooleanSupplier defaultValue)
      Returns the value to which the specified key is mapped or the value from defaultValue if this document contains no mapping for the key. If the value type is not a Boolean, then this method throws ClassCastException.
      Parameters:
      key - the key whose associated value is to be returned
      Returns:
      the value to which the specified key is mapped or the value from defaultValue if this document contains no mapping for the key.
      Throws:
      ClassCastException - if the value of the given key is not a Boolean.
      See Also:
    • getInt

      @Nullable default Integer getInt(String key)
      Returns the value to which the specified key is mapped, or null if this document contains no mapping for the key. If the value type is not a Integer, then this method throws ClassCastException.
      Parameters:
      key - the key whose associated value is to be returned
      Returns:
      the value to which the specified key is mapped, or null if this document contains no mapping for the key.
      Throws:
      ClassCastException - if the value of the given key is not a Integer.
    • getIntOrDefault

      default int getIntOrDefault(String key, int defaultValue)
      Returns the value to which the specified key is mapped or defaultValue if this document contains no mapping for the key. If the value type is not a Integer, then this method throws ClassCastException.
      Parameters:
      key - the key whose associated value is to be returned
      Returns:
      the value to which the specified key is mapped or defaultValue if this document contains no mapping for the key.
      Throws:
      ClassCastException - if the value of the given key is not a Integer.
    • getIntOrDefault

      default int getIntOrDefault(String key, IntSupplier defaultValue)
      Returns the value to which the specified key is mapped or the value from defaultValue if this document contains no mapping for the key. If the value type is not a Integer, then this method throws ClassCastException.
      Parameters:
      key - the key whose associated value is to be returned
      Returns:
      the value to which the specified key is mapped or the value from defaultValue if this document contains no mapping for the key.
      Throws:
      ClassCastException - if the value of the given key is not a Integer.
      See Also:
    • getLong

      @Nullable default Long getLong(String key)
      Returns the value to which the specified key is mapped, or null if this document contains no mapping for the key. If the value type is not a Long, then this method throws ClassCastException.
      Parameters:
      key - the key whose associated value is to be returned
      Returns:
      the value to which the specified key is mapped, or null if this document contains no mapping for the key.
      Throws:
      ClassCastException - if the value of the given key is not a Long.
    • getLongOrDefault

      default long getLongOrDefault(String key, long defaultValue)
      Returns the value to which the specified key is mapped or defaultValue if this document contains no mapping for the key. If the value type is not a Long, then this method throws ClassCastException.
      Parameters:
      key - the key whose associated value is to be returned
      Returns:
      the value to which the specified key is mapped or defaultValue if this document contains no mapping for the key.
      Throws:
      ClassCastException - if the value of the given key is not a Long.
    • getLongOrDefault

      default long getLongOrDefault(String key, LongSupplier defaultValue)
      Returns the value to which the specified key is mapped or the value from defaultValue if this document contains no mapping for the key. If the value type is not a Long, then this method throws ClassCastException.
      Parameters:
      key - the key whose associated value is to be returned
      Returns:
      the value to which the specified key is mapped or the value from defaultValue if this document contains no mapping for the key.
      Throws:
      ClassCastException - if the value of the given key is not a Long.
      See Also:
    • getString

      @Nullable default String getString(String key)
      Returns the value to which the specified key is mapped, or null if this document contains no mapping for the key. If the value type is not a String, then this method throws ClassCastException.
      Parameters:
      key - the key whose associated value is to be returned
      Returns:
      the value to which the specified key is mapped, or null if this document contains no mapping for the key.
      Throws:
      ClassCastException - if the value of the given key is not a String.
    • getStringOrDefault

      default String getStringOrDefault(String key, String defaultValue)
      Returns the value to which the specified key is mapped or defaultValue if this document contains no mapping for the key. If the value type is not a String, then this method throws ClassCastException.
      Parameters:
      key - the key whose associated value is to be returned
      Returns:
      the value to which the specified key is mapped or defaultValue if this document contains no mapping for the key.
      Throws:
      ClassCastException - if the value of the given key is not a String.
    • getStringOrDefault

      default String getStringOrDefault(String key, Supplier<String> defaultValue)
      Returns the value to which the specified key is mapped or the value from defaultValue if this document contains no mapping for the key. If the value type is not a String, then this method throws ClassCastException.
      Parameters:
      key - the key whose associated value is to be returned
      Returns:
      the value to which the specified key is mapped or the value from defaultValue if this document contains no mapping for the key.
      Throws:
      ClassCastException - if the value of the given key is not a String.
      See Also:
    • toJson

      String toJson()
      Render this Document to JSON. Auxiliary values such as Id and version are not considered within the JSON representation.
      Returns:
      a JSON representation of this document.
    • fromJson

      M fromJson(String json)
      initializes this object from the given JSON String.
      Parameters:
      json - must not be null