This repository has been archived on 2023-01-02. You can view files and clone it, but cannot push or open issues or pull requests.
data-generator-runtime/src/main/java/it/cavallium/data/generator/nativedata/Nullablebyte.java

108 lines
1.9 KiB
Java

package it.cavallium.data.generator.nativedata;
import java.io.Serial;
import java.io.Serializable;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class Nullablebyte implements Serializable, IGenericNullable {
@Serial
private static final long serialVersionUID = 1L;
private static final Nullablebyte NULL = new Nullablebyte(null);
private final Byte value;
public Nullablebyte(Byte value) {
this.value = value;
}
public static Nullablebyte of(byte value) {
return new Nullablebyte(value);
}
public static Nullablebyte ofNullable(@Nullable Byte value) {
if (value == null) {
return NULL;
} else {
return new Nullablebyte(value);
}
}
public static Nullablebyte empty() {
return NULL;
}
public boolean isEmpty() {
return value == null;
}
public boolean isPresent() {
return value != null;
}
public byte get() {
if (value == null) {
throw new NullPointerException();
} else {
return value;
}
}
public byte orElse(byte defaultValue) {
if (value == null) {
return defaultValue;
} else {
return value;
}
}
@Override
public Byte $getNullable() {
return this.getNullable();
}
@Nullable
public Byte getNullable() {
return value;
}
public byte getNullable(byte defaultValue) {
return value == null ? defaultValue : value;
}
@NotNull
@Override
public Nullablebyte clone() {
if (value != null) {
return Nullablebyte.of(value);
} else {
return Nullablebyte.empty();
}
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Nullablebyte that = (Nullablebyte) o;
return Objects.equals(value, that.value);
}
@Override
public int hashCode() {
return Objects.hash(value);
}
@Override
public String toString() {
if (value == null) return "null";
return "" + value;
}
}