me.datafox.dfxengine.text.api.ConfigurationKey Maven / Gradle / Ivy
package me.datafox.dfxengine.text.api;
import lombok.*;
/**
* Data class that is used as a key for {@link TextConfiguration}. Contains a hidden index to keep the hashcode unique
* and a default value that is used when the configured value is not set or cannot be obtained.
*
* @author datafox
*/
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@EqualsAndHashCode
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@ToString
public final class ConfigurationKey {
private static int counter = 0;
@ToString.Exclude
private final int index = counter++;
/**
* Default value for this configuration key.
*/
@EqualsAndHashCode.Exclude
@Getter
private T defaultValue;
/**
* @param defaultValue value to be set as the default value
* @throws UnsupportedOperationException if the default value has already been set
*/
public void setDefaultValue(T defaultValue) {
if(this.defaultValue != null) {
throw new UnsupportedOperationException("Default value has already been set");
}
this.defaultValue = defaultValue;
}
/**
* @param defaultValue default value for the configuration key
* @return new {@link ConfigurationKey} with the specified default value
* @param type of the value of this configuration key
*/
public static ConfigurationKey of(T defaultValue) {
return new ConfigurationKey<>(defaultValue);
}
/**
* Any class calling this method must also call {@link #setDefaultValue(Object)} on the returned configuration key.
*
* @return new {@link ConfigurationKey} with the specified default value
* @param type of the value of this configuration key
*/
public static ConfigurationKey of() {
return new ConfigurationKey<>();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy