com.xlrit.gears.base.choice.DefaultChoice Maven / Gradle / Ivy
package com.xlrit.gears.base.choice;
import java.util.Objects;
public class DefaultChoice implements Choice {
private final String value;
private final String label;
private DefaultChoice(String value, String label) {
this.value = value;
this.label = label;
}
@Override
public String getValue() {
return value;
}
@Override
public String getLabel() {
return label;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
DefaultChoice that = (DefaultChoice) o;
return Objects.equals(value, that.value) && Objects.equals(label, that.label);
}
@Override
public int hashCode() {
return Objects.hash(value, label);
}
@Override
public String toString() {
return "DefaultChoice[" +
"value='" + value + "'" +
", label='" + label + "'" +
']';
}
public static Choice of(String value) {
return new DefaultChoice(value, value);
}
public static Choice of(String value, String label) {
return new DefaultChoice(value, label);
}
public static Choice fromTuple(jakarta.persistence.Tuple tuple) {
String value = tuple.get(0, String.class);
String label = tuple.get(1, String.class);
return new DefaultChoice(value, label);
}
}