io.contek.zeus.ClientOrderLabel Maven / Gradle / Ivy
package io.contek.zeus;
import com.google.common.io.BaseEncoding;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import java.util.Random;
import static com.google.common.io.BaseEncoding.base32Hex;
@Immutable
public final class ClientOrderLabel extends StringKey {
private static final BaseEncoding ENCODING = base32Hex().lowerCase().omitPadding();
private static final Random random = new Random();
private ClientOrderLabel(String stringValue) {
super(stringValue);
}
public static ClientOrderLabel nextBase32() {
byte[] bytes = new byte[8];
random.nextBytes(bytes);
return of(ENCODING.encode(bytes));
}
public static ClientOrderLabel of(String stringValue) {
ClientOrderLabel result = ofNullable(stringValue);
if (result == null) {
throw new IllegalArgumentException(stringValue);
}
return result;
}
@Nullable
public static ClientOrderLabel ofNullable(@Nullable String stringValue) {
if (stringValue == null || stringValue.isEmpty()) {
return null;
}
return new ClientOrderLabel(stringValue);
}
}