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 recordA 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 aKeyedValuerecord class.KeyedValue(Map.Entry<String, T> entry) -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.getKey()getValue()final inthashCode()Returns a hash code value for this object.@NotNull Stringkey()Returns the value of thekeyrecord component.final StringtoString()Returns a string representation of this record class.static <T> KeyedValue.UnzippedKeyValues<T> unzip(@NotNull KeyedValue<T> @NotNull [] keyedValues) Unzips an array ofKeyedValues into separate lists of keys and values.static <T> KeyedValue.UnzippedKeyValues<T> unzip(Iterator<KeyedValue<T>> keyedValues) Unzips an iterator ofKeyedValues into separate lists of keys and values.value()Returns the value of thevaluerecord component.Creates a newKeyedValuewith the same value but a different key.<U> KeyedValue<U> withValue(U newValue) Creates a newKeyedValuewith the same key but a different value.static <T> KeyedValue<T> @NotNull []Zips the given values and keys into aKeyedValuearray.
-
Constructor Details
-
KeyedValue
Creates an instance of aKeyedValuerecord class.- Parameters:
key- the value for thekeyrecord componentvalue- the value for thevaluerecord component
-
KeyedValue
-
-
Method Details
-
getKey
-
getValue
-
setValue
-
withKey
Creates a newKeyedValuewith the same value but a different key.- Parameters:
newKey- the new key for theKeyedValue- Returns:
- a new
KeyedValuewith the specified key and the same value
-
withValue
Creates a newKeyedValuewith 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
KeyedValuewith 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 aKeyedValuearray.- 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
KeyedValues - 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 ofKeyedValues into separate lists of keys and values.- Type Parameters:
T- The type of the values in theKeyedValues.- Parameters:
keyedValues- An array ofKeyedValues to unzip.- Returns:
- An
KeyedValue.UnzippedKeyValuesobject containing two lists: one for keys and one for values.
-
unzip
Unzips an iterator ofKeyedValues into separate lists of keys and values.- Type Parameters:
T- The type of the values in theKeyedValues.- Parameters:
keyedValues- An iterator ofKeyedValues to unzip.- Returns:
- An
KeyedValue.UnzippedKeyValuesobject 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 thekeyrecord component.- Returns:
- the value of the
keyrecord component
-
value
Returns the value of thevaluerecord component.- Returns:
- the value of the
valuerecord component
-