DTO_NameValues
Class · Group: Data Transfer Objects
@JsonAccess(serializable='always' deserializable='always') global inherited sharing class DTO_NameValues extends DTO_JsonBaseExtends: DTO_JsonBase
Class for managing and transferring key-value pairs, represented as names and values, between classes. Provides functionalities to store, retrieve, and manipulate these name-value pairs.
Since: 1.0
Example:
DTO_NameValues params = new DTO_NameValues();
params.add('recipient', 'user@example.com');
params.add('subject', 'Hello');
String recipient = params.get('recipient');
Boolean hasAll = params.allExists(new Set<String>{'recipient', 'subject'}, true);Properties
| Property | Description |
|---|---|
| global transient Set names | Returns all the names for registered name-value pairs |
| global transient Integer size | Returns the number of name-value pairs |
| global transient List values | Returns all the values for registered name-value pairs |
Methods
| Method | Description |
|---|---|
| global void add(String name, String value) | Adds a new key-value pair to the map, or updates the value if the key already exists. |
| global Boolean allExists(Set<String> names) | Checks to see if all the parameter names provided exist in the list |
| global Boolean allExists(Set<String> namesToMatch, Boolean isNonBlank) | Determines if all keys in the provided set exist in the map, and optionally ensures that all have non-blank values. |
| global DTO_NameValues() | Constructor that initializes an empty name-value map to store key-value pairs. |
| global DTO_NameValues(Map<String, String> nameValues) | Constructor that populates name-value pairs from a provided map. |
| global DTO_NameValues(String separatedNameValues) | Constructor that accepts a delimited string of name-value pairs, converting them into key-value entries within the map. |
| global DTO_NameValues(String separatedNameValues, String separator) | Constructor that accepts a delimited string of name-value pairs, with a specified separator, and converts them into key-value entries within the map. |
| global Boolean exists(String nameToMatch) | Returns true if the objects contains a value for the specified name |
| global Boolean exists(String nameToMatch, Boolean isNonBlank) | Determines if a key exists in the map and, optionally, if it is non-blank. |
| global String get(String name) | Retrieves the value associated with the specified key in the map. |
| global override Type getObjectType() | Returns the type of this DTO for deserialization purposes, useful for reconstructing the object from JSON. |
| global Boolean isEmpty() | Checks if the DTO contains no key-value pairs. |
| global override String serialize() | Serializes the map to a JSON string. |
| global String toParameterString() | Converts the name-value pairs in the map into a parameter string in the format "name1=value1,name2=value2". |
Property Details
names
global transient Set<String> namesType: Set
Returns all the names for registered name-value pairs
Since:
Example:
size
global transient Integer sizeType: Integer
Returns the number of name-value pairs
Since:
Example:
values
global transient List<String> valuesType: List
Returns all the values for registered name-value pairs
Since:
Example:
Method Details
DTO_NameValues
global DTO_NameValues()Constructor that initializes an empty name-value map to store key-value pairs.
Since: 1.0
Example:
DTO_NameValues instance = new DTO_NameValues();DTO_NameValues
global DTO_NameValues(Map<String, String> nameValues)Constructor that populates name-value pairs from a provided map.
Parameters:
nameValues(Map) - A map of key-value pairs where both keys and values are strings.
Since: 1.0
Example:
DTO_NameValues instance = new DTO_NameValues(new Map<String, String>{'key' => 'value'});DTO_NameValues
global DTO_NameValues(String separatedNameValues)Constructor that accepts a delimited string of name-value pairs, converting them into key-value entries within the map.
Parameters:
separatedNameValues(String) - A string of name-value pairs separated by a comma, e.g., "paramName=paramValue,paramName2=paramValue2".
Since: 1.0
Example:
DTO_NameValues instance = new DTO_NameValues('value');DTO_NameValues
global DTO_NameValues(String separatedNameValues, String separator)Constructor that accepts a delimited string of name-value pairs, with a specified separator, and converts them into key-value entries within the map.
Parameters:
separatedNameValues(String) - A string of name-value pairs, e.g., "paramName=paramValue|paramName2=paramValue2".separator(String) - The delimiter to separate each name-value pair. If null, defaults to a comma.
Since: 1.0
Example:
DTO_NameValues instance = new DTO_NameValues('value', ',');add
global void add(String name, String value)Adds a new key-value pair to the map, or updates the value if the key already exists.
Parameters:
Since: 1.0
Example:
instance.add('myName', 'value');allExists
global Boolean allExists(Set<String> names)Checks to see if all the parameter names provided exist in the list
Parameters:
names(Set) - A list of names on which to match (please note this is case sensitive)
Returns: Boolean - True if ALL the parameters exist
Since: 1.0
Example:
Boolean result = instance.allExists(new Set<String>{'a', 'b'});allExists
global Boolean allExists(Set<String> namesToMatch, Boolean isNonBlank)Determines if all keys in the provided set exist in the map, and optionally ensures that all have non-blank values.
Parameters:
namesToMatch(Set) - A set of keys to check for existence. Case-sensitive.isNonBlank(String) - If true, requires that all specified keys have non-blank values.
Returns: Boolean - true if all keys exist (and have non-blank values if specified).
Since: 1.0
Example:
Boolean result = instance.allExists(new Set<String>{'a', 'b'}, true);exists
global Boolean exists(String nameToMatch)Returns true if the objects contains a value for the specified name
Parameters:
nameToMatch(String) - Name against which to find a key, note the compare is case-sensitive
Returns: Boolean - Null or the item found
Since: 1.0
Example:
Boolean result = instance.exists('value');exists
global Boolean exists(String nameToMatch, Boolean isNonBlank)Determines if a key exists in the map and, optionally, if it is non-blank. A non-blank value is neither null nor an empty string.
Parameters:
nameToMatch(String) - Name against which to find a key, note the compare is case-sensitiveisNonBlank(Boolean) - Will return false if item exists and it's blank (either null or empty string)
Returns: Boolean - true if the key exists (and has a non-blank value if specified).
Since: 1.0
Example:
Boolean result = instance.exists('value', true);get
global String get(String name)Retrieves the value associated with the specified key in the map. If the key does not exist, returns null.
Parameters:
name(String) - The key for which to retrieve the value. Case-sensitive.
Returns: String - The value associated with the specified key, or null if the key is absent.
Since: 1.0
Example:
String result = instance.get('myName');getObjectType
global override Type getObjectType()Returns the type of this DTO for deserialization purposes, useful for reconstructing the object from JSON.
Returns: Type - The type class of DTO_NameValues.
Since: 1.0
Example:
Type result = instance.getObjectType();isEmpty
global Boolean isEmpty()Checks if the DTO contains no key-value pairs. Returns true if the object has zero key-value pairs.
Returns: Boolean - true if there are no entries, false otherwise.
Since: 1.0
Example:
Boolean result = instance.isEmpty();serialize
global override String serialize()Serializes the map to a JSON string. If the map is empty, returns an empty JSON object {}.
Returns: String - A JSON string representation of the map.
Since: 1.0
Example:
String result = instance.serialize();toParameterString
global String toParameterString()Converts the name-value pairs in the map into a parameter string in the format "name1=value1,name2=value2".
Returns: String - A string of comma-separated name-value pairs.
Since: 1.0
Example:
String result = instance.toParameterString();