java.lang.Object
java.lang.Record
io.jstach.ezkv.kvs.KeyValue
- Record Components:
key
- the key associated with this key-value pair.expanded
- the value after any interpolation.meta
- additional metadata associated with this key-value pair.
Represents a key-value pair in the Ezkv configuration system. Unlike a simple
Map.Entry<String, String>
, this record holds additional metadata that provides
more context about the key-value pair, such as:
- The original raw value (before any interpolation).
- The expanded value (after interpolation).
- Source information indicating where the key-value pair was loaded from.
- Flags indicating special behavior (e.g., sensitive data or disabling interpolation).
Example Usage
The following example shows how to load key-values using the Ezkv system:
var kvs = KeyValuesSystem.defaults()
.loader()
.add("classpath:/start.properties")
.add("system:///")
.add("env:///")
.load();
// Accessing key-value pairs:
for (KeyValue kv : kvs) {
System.out.println("Key: " + kv.key() + ", Value: " + kv.value());
}
-
Nested Class Summary
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddFlags
(Collection<KeyValue.Flag> flagsCol) Adds additional flags to thisKeyValue
and returns a new instance.final boolean
Indicates whether some other object is "equal to" this one.expanded()
Returns the value of theexpanded
record component.final int
hashCode()
Returns a hash code value for this object.boolean
isFlag
(KeyValue.Flag flag) Checks if a specific flag is set on thisKeyValue
.boolean
Checks if theKeyValue.Flag.NO_INTERPOLATION
flag is set on thisKeyValue
.boolean
Checks if theKeyValue.Flag.SENSITIVE
flag is set on thisKeyValue
.key()
Returns the value of thekey
record component.meta()
Returns the value of themeta
record component.raw()
Gets the original raw value before any interpolation.redact()
Redacts the sensitive value in this key-value pair by replacing it with a default message.Redacts the sensitive value in this key-value pair by replacing it with a custom message.toString()
Returns a string representation of this record class.value()
Gets the expanded value after interpolation.withExpanded
(String expanded) Creates a newKeyValue
with an updated expanded value.withExpanded
(Function<String, @Nullable String> expanded) Returns a newKeyValue
instance with its value expanded using the provided function.Creates a new KeyValue with an updated key.
-
Field Details
-
REDACTED_MESSAGE
- See Also:
-
-
Constructor Details
-
KeyValue
Constructs a newKeyValue
with the given key, expanded value, and associated metadata.- Parameters:
key
- the key associated with this key-value pair (cannot benull
).expanded
- the value after any interpolation (cannot benull
).meta
- additional metadata (cannot benull
).
-
KeyValue
Constructs a newKeyValue
with a raw value, using the provided key and raw value. TheKeyValue.Meta
information will be initialized with default settings.- Parameters:
key
- the key associated with this key-value pair.raw
- the raw (unexpanded) value associated with this key.
-
-
Method Details
-
value
Gets the expanded value after interpolation.- Returns:
- the expanded value.
-
raw
Gets the original raw value before any interpolation.- Returns:
- the raw value.
-
withKey
Creates a new KeyValue with an updated key.- Parameters:
key
- the new key.- Returns:
- new key value.
-
withExpanded
Creates a newKeyValue
with an updated expanded value.- Parameters:
expanded
- the new expanded value.- Returns:
- a new
KeyValue
with the updated expanded value.
-
withExpanded
Returns a newKeyValue
instance with its value expanded using the provided function. The expansion function takes the key as input and returns the expanded value, ornull
if no expansion is necessary. If an expanded value is provided by the function, a newKeyValue
instance is created with that expanded value; otherwise, the current instance is returned unchanged.- Parameters:
expanded
- a function that takes the key as input and returns the expanded value ornull
if no expansion is needed- Returns:
- a new
KeyValue
instance with the expanded value, or the original instance if no expansion was applied
-
addFlags
Adds additional flags to thisKeyValue
and returns a new instance.- Parameters:
flagsCol
- a collection of flags to add.- Returns:
- a new
KeyValue
with the added flags.
-
isNoInterpolation
Checks if theKeyValue.Flag.NO_INTERPOLATION
flag is set on thisKeyValue
. This indicates that the value should not undergo any interpolation or variable substitution.- Returns:
true
if theNO_INTERPOLATION
flag is set, otherwisefalse
.
-
isSensitive
Checks if theKeyValue.Flag.SENSITIVE
flag is set on thisKeyValue
. A sensitive value is marked to indicate that it should be treated as confidential and may be redacted when displayed to prevent leaking sensitive information.- Returns:
true
if theSENSITIVE
flag is set, otherwisefalse
.
-
isFlag
Checks if a specific flag is set on thisKeyValue
.- Parameters:
flag
- the flag to check- Returns:
true
if the specified flag is set, otherwisefalse
.
-
redact
Redacts the sensitive value in this key-value pair by replacing it with a default message.- Returns:
- a new
KeyValue
with the sensitive data redacted.
-
redact
Redacts the sensitive value in this key-value pair by replacing it with a custom message.- Parameters:
redactMessage
- the message to use for redaction.- Returns:
- a new
KeyValue
with the sensitive data redacted.
-
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
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)
. -
key
Returns the value of thekey
record component.- Returns:
- the value of the
key
record component
-
expanded
Returns the value of theexpanded
record component.- Returns:
- the value of the
expanded
record component
-
meta
Returns the value of themeta
record component.- Returns:
- the value of the
meta
record component
-