java.lang.Object
java.lang.Record
it.auties.whatsapp.model.request.Attributes
- Record Components:
toMap
- the non-null wrapped map
A utility class that wraps a map and provides easy methods to interact with its content
-
Field Summary
Modifier and TypeFieldDescriptionprivate final @NonNull ConcurrentHashMap<String,
Object> The field for thetoMap
record component. -
Constructor Summary
ConstructorDescriptionAttributes
(@NonNull ConcurrentHashMap<String, Object> toMap) Creates an instance of aAttributes
record class. -
Method Summary
Modifier and TypeMethodDescriptioncopy()
Copies this objectfinal boolean
Indicates whether some other object is "equal to" this one.<T> Optional<T>
Gets a value by key in the wrapped map<T> T
Gets a value by key in the wrapped mapboolean
getBoolean
(@NonNull String key) Gets a value as a boolean by key in the wrapped mapint
Gets a value as an int by key in the wrapped mapGets an optional value as a ContactJid by key in the wrapped maplong
Gets a value as a long by key in the wrapped mapgetNullableString
(@NonNull String key) Gets a nullable value as a string by key in the wrapped mapgetOptionalInt
(String key) Gets a value as an int by key in the wrapped mapgetOptionalLong
(@NonNull String key) Gets a value as a long by key in the wrapped mapgetOptionalString
(@NonNull String key) Gets an optional value as a string by key in the wrapped mapgetRequiredString
(@NonNull String key) Gets a non-null value as a string by key in the wrapped map.Gets a non-null value as a string by key in the wrapped map.Gets a value as a string by key in the wrapped map.final int
hashCode()
Returns a hash code value for this object.boolean
Checks whether a non-null key exists in this mapboolean
Checks whether a non-null key exists in this map and has the provided valueboolean
isEmpty()
Returns whether this object is emptystatic Attributes
Constructs a new map using the non-null provided entriesstatic Attributes
Constructs a new map using the provided non-null mapstatic Attributes
ofNullable
(Map<String, Object> map) Constructs a new map using the provided nullable mapprivate boolean
private int
private ContactJid
private long
Inserts a key-value pair in the wrapped mapInserts a key-value pair in the wrapped mapput
(@NonNull String key, Object value, @NonNull BooleanSupplier... conditions) Inserts a key-value pair in the wrapped mapfinal <T> Attributes
Inserts a key-value pair in the wrapped map@NonNull ConcurrentHashMap<String,
Object> toMap()
Returns the value of thetoMap
record component.final String
toString()
Returns a string representation of this record class.
-
Field Details
-
toMap
The field for thetoMap
record component.
-
-
Constructor Details
-
Attributes
Creates an instance of aAttributes
record class.- Parameters:
toMap
- the value for thetoMap
record component
-
-
Method Details
-
of
Constructs a new map using the non-null provided entries- Parameters:
entries
- the non-null entries- Returns:
- a new instance of Attributes
-
ofNullable
Constructs a new map using the provided nullable map- Parameters:
map
- the nullable existing map- Returns:
- a new instance of Attributes
-
of
Constructs a new map using the provided non-null map- Parameters:
map
- the non-null existing map- Returns:
- a new instance of Attributes
-
hasKey
Checks whether a non-null key exists in this map- Parameters:
key
- the non-null key- Returns:
- a boolean
-
hasKey
Checks whether a non-null key exists in this map and has the provided value- Parameters:
key
- the non-null keyvalue
- 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 keyvalue
- the nullable valueconditions
- 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 keyvalue
- the nullable valueconditions
- the non-null conditions that must be met to insert the value- Returns:
- the calling instance
-
put
Inserts a key-value pair in the wrapped map- Parameters:
key
- the non-null keyvalue
- the nullable valuecondition
- the condition that must be met to insert the value- Returns:
- the calling instance
-
put
Inserts a key-value pair in the wrapped map- Parameters:
key
- the non-null keyvalue
- 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 keydefaultValue
- the non-null default valueclazz
- the non-null type of the value that is returned- Returns:
- the non-null value
-
get
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 keyclazz
- the non-null type of the value that is returned- Returns:
- the non-null value
-
getInt
Gets a value as an int by key in the wrapped map- Parameters:
key
- the non-null key- Returns:
- the non-null value
-
getOptionalInt
Gets a value as an int by key in the wrapped map- Parameters:
key
- the non-null key- Returns:
- the non-null value
-
parseInt
-
getLong
Gets a value as a long by key in the wrapped map- Parameters:
key
- the non-null key- Returns:
- the non-null value
-
getOptionalLong
Gets a value as a long by key in the wrapped map- Parameters:
key
- the non-null key- Returns:
- the non-null value
-
parseLong
-
getString
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
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
Gets a nullable value as a string by key in the wrapped map- Parameters:
key
- the non-null key- Returns:
- the nullable value
-
getRequiredString
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
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
Gets a value as a boolean by key in the wrapped map- Parameters:
key
- the non-null key- Returns:
- a boolean
-
parseBool
-
getJid
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
-
copy
Copies this object- Returns:
- a non-null instance
-
isEmpty
public boolean isEmpty()Returns whether this object is empty- Returns:
- a boolean
-
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. -
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. -
equals
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 withObjects::equals(Object,Object)
. -
toMap
Returns the value of thetoMap
record component.- Returns:
- the value of the
toMap
record component
-