Skip to content

Commit

Permalink
refactor: rename StorageValueType to StorageItemType
Browse files Browse the repository at this point in the history
To align with the cache naming, we rename this to `StorageItemType`. A
future RPC could be `getItemType` and the name will align.
  • Loading branch information
malandis committed Jun 20, 2024
1 parent 81b25c2 commit 95fa872
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package momento.sdk.responses.storage;

/** Type of item in a store. */
public enum StorageItemType {
/** Item is a byte array. */
BYTE_ARRAY,
/** Item is a string. */
STRING,
/** Item is a long. */
LONG,
/** Item is a double. */
DOUBLE
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,56 @@

public class StorageValue {
private final Object value;
private final ValueType valueType;
private final StorageItemType itemType;

private StorageValue(Object value, ValueType valueType) {
private StorageValue(Object value, StorageItemType itemType) {
this.value = value;
this.valueType = valueType;
this.itemType = itemType;
}

public static StorageValue of(byte[] value) {
return new StorageValue(value, ValueType.BYTE_ARRAY);
return new StorageValue(value, StorageItemType.BYTE_ARRAY);
}

public static StorageValue of(String value) {
return new StorageValue(value, ValueType.STRING);
return new StorageValue(value, StorageItemType.STRING);
}

public static StorageValue of(long value) {
return new StorageValue(value, ValueType.LONG);
return new StorageValue(value, StorageItemType.LONG);
}

public static StorageValue of(double value) {
return new StorageValue(value, ValueType.DOUBLE);
return new StorageValue(value, StorageItemType.DOUBLE);
}

public ValueType getType() {
return valueType;
public StorageItemType getType() {
return itemType;
}

public Optional<byte[]> getByteArray() {
if (valueType != ValueType.BYTE_ARRAY) {
if (itemType != StorageItemType.BYTE_ARRAY) {
return Optional.empty();
}
return Optional.of((byte[]) value);
}

public Optional<String> getString() {
if (valueType != ValueType.STRING) {
if (itemType != StorageItemType.STRING) {
return Optional.empty();
}
return Optional.of((String) value);
}

public Optional<Long> getLong() {
if (valueType != ValueType.LONG) {
if (itemType != StorageItemType.LONG) {
return Optional.empty();
}
return Optional.of((long) value);
}

public Optional<Double> getDouble() {
if (valueType != ValueType.DOUBLE) {
if (itemType != StorageItemType.DOUBLE) {
return Optional.empty();
}
return Optional.of((double) value);
Expand Down

This file was deleted.

0 comments on commit 95fa872

Please sign in to comment.