Package ch.njol.skript.lang
Record Class KeyedValue<T>
java.lang.Object
java.lang.Record
ch.njol.skript.lang.KeyedValue<T>
- Type Parameters:
T
- The type of the value associated with the key.
public record KeyedValue<T>(@NotNull String key, T value)
extends Record
implements Map.Entry<String,T>
A record that represents a key-value pair
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final record
A record that represents a pair of lists: one for keys and one for values. -
Constructor Summary
ConstructorsConstructorDescriptionKeyedValue
(@NotNull String key, T value) Creates an instance of aKeyedValue
record class.KeyedValue
(Map.Entry<String, T> entry) -
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
Indicates whether some other object is "equal to" this one.getKey()
getValue()
final int
hashCode()
Returns a hash code value for this object.@NotNull String
key()
Returns the value of thekey
record component.final String
toString()
Returns a string representation of this record class.static <T> KeyedValue.UnzippedKeyValues
<T> unzip
(@NotNull KeyedValue<T> @NotNull [] keyedValues) Unzips an array ofKeyedValue
s into separate lists of keys and values.static <T> KeyedValue.UnzippedKeyValues
<T> unzip
(Iterator<KeyedValue<T>> keyedValues) Unzips an iterator ofKeyedValue
s into separate lists of keys and values.value()
Returns the value of thevalue
record component.Creates a newKeyedValue
with the same value but a different key.<U> KeyedValue
<U> withValue
(U newValue) Creates a newKeyedValue
with the same key but a different value.static <T> KeyedValue<T> @NotNull []
Zips the given values and keys into aKeyedValue
array.
-
Constructor Details
-
KeyedValue
Creates an instance of aKeyedValue
record class.- Parameters:
key
- the value for thekey
record componentvalue
- the value for thevalue
record component
-
KeyedValue
-
-
Method Details
-
getKey
-
getValue
-
setValue
-
withKey
Creates a newKeyedValue
with the same value but a different key.- Parameters:
newKey
- the new key for theKeyedValue
- Returns:
- a new
KeyedValue
with the specified key and the same value
-
withValue
Creates a newKeyedValue
with the same key but a different value.- Type Parameters:
U
- the type of the new value- Parameters:
newValue
- the new value for theKeyedValue
- Returns:
- a new
KeyedValue
with the same key and the specified value
-
zip
public static <T> KeyedValue<T> @NotNull [] zip(@NotNull T @NotNull [] values, @NotNull @NotNull String @Nullable [] keys) Zips the given values and keys into aKeyedValue
array.- Type Parameters:
T
- the type of the values- Parameters:
values
- the values to zipkeys
- the keys to zip with the values, or null to use numerical indices (1, 2, 3, ..., n)- Returns:
- an array of
KeyedValue
s - Throws:
IllegalArgumentException
- if the keys are present and the lengths of values and keys do not match
-
unzip
public static <T> KeyedValue.UnzippedKeyValues<T> unzip(@NotNull @NotNull KeyedValue<T> @NotNull [] keyedValues) Unzips an array ofKeyedValue
s into separate lists of keys and values.- Type Parameters:
T
- The type of the values in theKeyedValue
s.- Parameters:
keyedValues
- An array ofKeyedValue
s to unzip.- Returns:
- An
KeyedValue.UnzippedKeyValues
object containing two lists: one for keys and one for values.
-
unzip
Unzips an iterator ofKeyedValue
s into separate lists of keys and values.- Type Parameters:
T
- The type of the values in theKeyedValue
s.- Parameters:
keyedValues
- An iterator ofKeyedValue
s to unzip.- Returns:
- An
KeyedValue.UnzippedKeyValues
object containing two lists: one for keys and one for values.
-
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)
. -
key
Returns the value of thekey
record component.- Returns:
- the value of the
key
record component
-
value
Returns the value of thevalue
record component.- Returns:
- the value of the
value
record component
-