Record Class Attributes

java.lang.Object
java.lang.Record
it.auties.whatsapp.model.request.Attributes
Record Components:
toMap - the non-null wrapped map

public record Attributes(@NonNull ConcurrentHashMap<String,Object> toMap) extends Record
A utility class that wraps a map and provides easy methods to interact with its content
  • Field Details

  • Constructor Details

    • Attributes

      public Attributes(@NonNull @NonNull ConcurrentHashMap<String,Object> toMap)
      Creates an instance of a Attributes record class.
      Parameters:
      toMap - the value for the toMap record component
  • Method Details

    • of

      @SafeVarargs public static Attributes of(@NonNull @NonNull Map.Entry<String,Object>... entries)
      Constructs a new map using the non-null provided entries
      Parameters:
      entries - the non-null entries
      Returns:
      a new instance of Attributes
    • ofNullable

      public static Attributes ofNullable(Map<String,Object> map)
      Constructs a new map using the provided nullable map
      Parameters:
      map - the nullable existing map
      Returns:
      a new instance of Attributes
    • of

      public static Attributes of(@NonNull @NonNull Map<String,Object> map)
      Constructs a new map using the provided non-null map
      Parameters:
      map - the non-null existing map
      Returns:
      a new instance of Attributes
    • hasKey

      public boolean hasKey(@NonNull @NonNull String key)
      Checks whether a non-null key exists in this map
      Parameters:
      key - the non-null key
      Returns:
      a boolean
    • hasKey

      public boolean hasKey(@NonNull @NonNull String key, String value)
      Checks whether a non-null key exists in this map and has the provided value
      Parameters:
      key - the non-null key
      value - the nullable value to check against
      Returns:
      a boolean
    • put

      @SafeVarargs public final <T> Attributes put(@NonNull @NonNull String key, T value, @NonNull @NonNull Function<T,Boolean>... conditions)
      Inserts a key-value pair in the wrapped map
      Type Parameters:
      T - the type of the value
      Parameters:
      key - the non-null key
      value - the nullable value
      conditions - the non-null conditions that must be met to insert the value
      Returns:
      the calling instance
    • put

      public Attributes put(@NonNull @NonNull String key, Object value, @NonNull @NonNull BooleanSupplier... conditions)
      Inserts a key-value pair in the wrapped map
      Parameters:
      key - the non-null key
      value - the nullable value
      conditions - the non-null conditions that must be met to insert the value
      Returns:
      the calling instance
    • put

      public Attributes put(@NonNull @NonNull String key, Object value, boolean condition)
      Inserts a key-value pair in the wrapped map
      Parameters:
      key - the non-null key
      value - the nullable value
      condition - the condition that must be met to insert the value
      Returns:
      the calling instance
    • put

      public Attributes put(@NonNull @NonNull String key, Object value)
      Inserts a key-value pair in the wrapped map
      Parameters:
      key - the non-null key
      value - the nullable value
      Returns:
      the calling instance
    • get

      public <T> T get(@NonNull @NonNull String key, @NonNull T defaultValue, @NonNull @NonNull Class<T> clazz)
      Gets a value by key in the wrapped map
      Type Parameters:
      T - the type of the value that is returned
      Parameters:
      key - the non-null key
      defaultValue - the non-null default value
      clazz - the non-null type of the value that is returned
      Returns:
      the non-null value
    • get

      public <T> Optional<T> get(@NonNull @NonNull String key, @NonNull @NonNull Class<T> clazz)
      Gets a value by key in the wrapped map
      Type Parameters:
      T - the type of the value that is returned
      Parameters:
      key - the non-null key
      clazz - the non-null type of the value that is returned
      Returns:
      the non-null value
    • getInt

      public int getInt(@NonNull @NonNull String key)
      Gets a value as an int by key in the wrapped map
      Parameters:
      key - the non-null key
      Returns:
      the non-null value
    • getOptionalInt

      public Optional<Integer> getOptionalInt(String key)
      Gets a value as an int by key in the wrapped map
      Parameters:
      key - the non-null key
      Returns:
      the non-null value
    • parseInt

      private int parseInt(Object value)
    • getLong

      public long getLong(@NonNull @NonNull String key)
      Gets a value as a long by key in the wrapped map
      Parameters:
      key - the non-null key
      Returns:
      the non-null value
    • getOptionalLong

      public Optional<Long> getOptionalLong(@NonNull @NonNull String key)
      Gets a value as a long by key in the wrapped map
      Parameters:
      key - the non-null key
      Returns:
      the non-null value
    • parseLong

      private long parseLong(Object value)
    • getString

      public String getString(@NonNull @NonNull String key)
      Gets a non-null value as a string by key in the wrapped map. If the key doesn't exist, unknown is returned.
      Parameters:
      key - the non-null key
      Returns:
      the non-null value
    • getString

      public String getString(@NonNull @NonNull String key, String defaultValue)
      Gets a value as a string by key in the wrapped map. If the value is null, defaultValue is returned.
      Parameters:
      key - the non-null key
      Returns:
      a non-null string
    • getNullableString

      public String getNullableString(@NonNull @NonNull String key)
      Gets a nullable value as a string by key in the wrapped map
      Parameters:
      key - the non-null key
      Returns:
      the nullable value
    • getRequiredString

      public String getRequiredString(@NonNull @NonNull String key)
      Gets a non-null value as a string by key in the wrapped map. Throws an exception if the key doesn't exist.
      Parameters:
      key - the non-null key
      Returns:
      the non-null value
    • getOptionalString

      public Optional<String> getOptionalString(@NonNull @NonNull String key)
      Gets an optional value as a string by key in the wrapped map
      Parameters:
      key - the non-null key
      Returns:
      a non-null optional
    • getBoolean

      public boolean getBoolean(@NonNull @NonNull String key)
      Gets a value as a boolean by key in the wrapped map
      Parameters:
      key - the non-null key
      Returns:
      a boolean
    • parseBool

      private boolean parseBool(Object value)
    • getJid

      public Optional<ContactJid> getJid(@NonNull @NonNull String key)
      Gets an optional value as a ContactJid by key in the wrapped map
      Parameters:
      key - the non-null key
      Returns:
      a non-null optional
    • parseJid

      private ContactJid parseJid(Object value)
    • copy

      public Attributes copy()
      Copies this object
      Returns:
      a non-null instance
    • isEmpty

      public boolean isEmpty()
      Returns whether this object is empty
      Returns:
      a boolean
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • toMap

      @NonNull public @NonNull ConcurrentHashMap<String,Object> toMap()
      Returns the value of the toMap record component.
      Returns:
      the value of the toMap record component