forked from TrueCloudLab/frostfs-sdk-java
[#14] add lombok and refactor exceptions. Provide validator.
Signed-off-by: Ori Bruk <o.bruk@yadro.com>
This commit is contained in:
parent
15cf0893c7
commit
388428af76
87 changed files with 819 additions and 970 deletions
|
@ -1,21 +1,22 @@
|
|||
package info.frostfs.sdk;
|
||||
|
||||
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.UUID;
|
||||
|
||||
import static info.frostfs.sdk.constants.AppConst.UUID_BYTE_ARRAY_LENGTH;
|
||||
import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING_TEMPLATE;
|
||||
import static info.frostfs.sdk.constants.ErrorConst.WRONG_UUID_SIZE_TEMPLATE;
|
||||
import static java.util.Objects.isNull;
|
||||
|
||||
public class UuidExtension {
|
||||
private static final int UUID_BYTE_ARRAY_LENGTH = 16;
|
||||
private static final String ERROR_WRONG_UUID_SIZE = "Uuid byte array length must be " + UUID_BYTE_ARRAY_LENGTH;
|
||||
private static final String ERROR_UUID_MISSING = "Uuid is not present";
|
||||
|
||||
private UuidExtension() {
|
||||
}
|
||||
|
||||
public static UUID asUuid(byte[] bytes) {
|
||||
if (isNull(bytes) || bytes.length != UUID_BYTE_ARRAY_LENGTH) {
|
||||
throw new IllegalArgumentException(ERROR_WRONG_UUID_SIZE);
|
||||
throw new ValidationFrostFSException(String.format(WRONG_UUID_SIZE_TEMPLATE, UUID_BYTE_ARRAY_LENGTH));
|
||||
}
|
||||
|
||||
ByteBuffer bb = ByteBuffer.wrap(bytes);
|
||||
|
@ -26,7 +27,9 @@ public class UuidExtension {
|
|||
|
||||
public static byte[] asBytes(UUID uuid) {
|
||||
if (isNull(uuid)) {
|
||||
throw new IllegalArgumentException(ERROR_UUID_MISSING);
|
||||
throw new ValidationFrostFSException(
|
||||
String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, UUID.class.getName())
|
||||
);
|
||||
}
|
||||
|
||||
ByteBuffer bb = ByteBuffer.allocate(UUID_BYTE_ARRAY_LENGTH);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue