Skip to content

Commit

Permalink
add missing GTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
Cole-Greer committed Nov 28, 2024
1 parent 99e357f commit d60eca3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@

import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.OffsetDateTime;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

/**
* An enum that describes types that are used in the Gremlin language.
Expand All @@ -36,17 +38,23 @@ public enum GType {
BIG_DECIMAL(BigDecimal.class),
BIG_INTEGER(BigInteger.class),
BOOLEAN(Boolean.class),
BYTE(Byte.class),
CHARACTER(Character.class),
DATETIME(OffsetDateTime.class),
DOUBLE(Double.class),
EDGE(Edge.class),
FLOAT(Float.class),
INTEGER(Integer.class),
LIST(List.class),
LONG(Long.class),
MAP(Map.class),
PATH(Path.class),
PROPERTY(Property.class),
SET(Set.class),
SHORT(Short.class),
STRING(String.class),
UNKNOWN(null),
UUID(UUID.class),
VERTEX(Vertex.class);

private Class<?> javaType;
Expand All @@ -63,7 +71,8 @@ public Class<?> getJavaType() {
* Returns {@code true} if the type is a number.
*/
public boolean isNumeric() {
return this == INTEGER || this == DOUBLE || this == LONG || this == BIG_INTEGER || this == BIG_DECIMAL;
return this == BYTE || this == SHORT || this == INTEGER || this == LONG ||
this == FLOAT || this == DOUBLE || this == BIG_INTEGER || this == BIG_DECIMAL;
}

/**
Expand All @@ -85,8 +94,12 @@ public boolean isElement() {
*/
public static GType getType(final Object object) {
if (object instanceof String) return STRING;
else if (object instanceof Byte) return BYTE;
else if (object instanceof Short) return SHORT;
else if (object instanceof Character) return CHARACTER;
else if (object instanceof Integer) return INTEGER;
else if (object instanceof Boolean) return BOOLEAN;
else if (object instanceof Float) return FLOAT;
else if (object instanceof Double) return DOUBLE;
else if (object instanceof Long) return LONG;
else if (object instanceof Map) return MAP;
Expand All @@ -98,6 +111,8 @@ public static GType getType(final Object object) {
else if (object instanceof Property) return PROPERTY;
else if (object instanceof BigInteger) return BIG_INTEGER;
else if (object instanceof BigDecimal) return BIG_DECIMAL;
else if (object instanceof OffsetDateTime) return DATETIME;
else if (object instanceof UUID) return UUID;
else return UNKNOWN;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@

import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.OffsetDateTime;
import java.util.Collections;
import java.util.UUID;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -37,7 +39,10 @@ public class GTypeTest {

@Test
public void shouldReturnTrueForNumericTypes() {
assertThat(GType.BYTE.isNumeric(), is(true));
assertThat(GType.SHORT.isNumeric(), is(true));
assertThat(GType.INTEGER.isNumeric(), is(true));
assertThat(GType.FLOAT.isNumeric(), is(true));
assertThat(GType.DOUBLE.isNumeric(), is(true));
assertThat(GType.LONG.isNumeric(), is(true));
assertThat(GType.BIG_INTEGER.isNumeric(), is(true));
Expand All @@ -50,6 +55,15 @@ public void shouldReturnFalseForNonNumericTypes() {
assertThat(GType.BOOLEAN.isNumeric(), is(false));
assertThat(GType.EDGE.isNumeric(), is(false));
assertThat(GType.VERTEX.isNumeric(), is(false));
assertThat(GType.CHARACTER.isNumeric(), is(false));
assertThat(GType.DATETIME.isNumeric(), is(false));
assertThat(GType.LIST.isNumeric(), is(false));
assertThat(GType.MAP.isNumeric(), is(false));
assertThat(GType.PATH.isNumeric(), is(false));
assertThat(GType.PROPERTY.isNumeric(), is(false));
assertThat(GType.SET.isNumeric(), is(false));
assertThat(GType.UUID.isNumeric(), is(false));
assertThat(GType.UNKNOWN.isNumeric(), is(false));
}

@Test
Expand All @@ -68,6 +82,12 @@ public void shouldReturnCorrectGType() {
assertEquals(GType.PROPERTY, GType.getType(mock(Property.class)));
assertEquals(GType.BIG_INTEGER, GType.getType(BigInteger.ONE));
assertEquals(GType.BIG_DECIMAL, GType.getType(BigDecimal.ONE));
assertEquals(GType.BYTE, GType.getType((byte) 123));
assertEquals(GType.CHARACTER, GType.getType('A'));
assertEquals(GType.DATETIME, GType.getType(OffsetDateTime.now()));
assertEquals(GType.FLOAT, GType.getType(123.45f));
assertEquals(GType.SHORT, GType.getType((short) 123));
assertEquals(GType.UUID, GType.getType(UUID.randomUUID()));
}

@Test
Expand Down

0 comments on commit d60eca3

Please sign in to comment.