Repository: dbs-leipzig/gradoop
Issue: PropertyValue returns wrong types

The function PropertyValue.getType() returns the wrong objects for the following types:

- `TYPE_LIST`
- `TYPE_DATE`
- `TYPE_TIME`
- `TYPE_DATETIME`

Fix bug and add unit tests for this function.

Changed files:
gradoop-common/src/test/java/org/gradoop/common/model/impl/properties/PropertyValueTest.java
gradoop-common/src/main/java/org/gradoop/common/model/impl/properties/PropertyValue.java

diff --git a/gradoop-common/src/main/java/org/gradoop/common/model/impl/properties/PropertyValue.java b/gradoop-common/src/main/java/org/gradoop/common/model/impl/properties/PropertyValue.java
index 8e0d06c20d4..6ed36757fd1 100644
--- a/gradoop-common/src/main/java/org/gradoop/common/model/impl/properties/PropertyValue.java
+++ b/gradoop-common/src/main/java/org/gradoop/common/model/impl/properties/PropertyValue.java
@@ -41,6 +41,7 @@ import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Collections;
 
 /**
  * Represents a single property value in the EPGM.
@@ -137,6 +138,11 @@ public class PropertyValue implements Value, Serializable, Comparable<PropertyVa
    */
   private static final long serialVersionUID = 1L;
 
+  /**
+   * Mapping from byte value to associated Class
+   */
+  private static final Map<Byte, Class> TYPE_MAPPING = getTypeMap();
+
   /**
    * Stores the type and the value
     */
@@ -723,21 +729,36 @@ public class PropertyValue implements Value, Serializable, Comparable<PropertyVa
   // Util
   //----------------------------------------------------------------------------
 
+  /**
+   * Get the data type as class object according to the first position of the rawBytes[] array
+   *
+   * @return Class object
+   */
   public Class<?> getType() {
-    return rawBytes[0] == TYPE_BOOLEAN ?
-      Boolean.class     : rawBytes[0] == TYPE_INTEGER     ?
-      Integer.class     : rawBytes[0] == TYPE_LONG        ?
-      Long.class        : rawBytes[0] == TYPE_FLOAT       ?
-      Float.class       : rawBytes[0] == TYPE_DOUBLE      ?
-      Double.class      : rawBytes[0] == TYPE_STRING      ?
-      String.class      : rawBytes[0] == TYPE_BIG_DECIMAL ?
-      BigDecimal.class  : rawBytes[0] == TYPE_GRADOOP_ID  ?
-      GradoopId.class   : rawBytes[0] == TYPE_MAP         ?
-      Map.class         : rawBytes[0] == TYPE_LIST        ?
-      LocalDate.class   : rawBytes[0] == TYPE_DATE        ?
-      LocalTime.class   : rawBytes[0] == TYPE_TIME        ?
-      LocalDateTime.class : rawBytes[0] == TYPE_DATETIME  ?
-      List.class        : null;
+    return TYPE_MAPPING.get(rawBytes[0]);
+  }
+
+  /**
+   * Creates a type mapping HashMap to assign a byte value to its represented Class
+   *
+   * @return a Map with byte to class assignments
+   */
+  private static Map<Byte, Class> getTypeMap() {
+    Map<Byte, Class> map = new HashMap<>();
+    map.put(TYPE_BOOLEAN, Boolean.class);
+    map.put(TYPE_INTEGER, Integer.class);
+    map.put(TYPE_LONG, Long.class);
+    map.put(TYPE_FLOAT, Float.class);
+    map.put(TYPE_DOUBLE, Double.class);
+    map.put(TYPE_STRING, String.class);
+    map.put(TYPE_BIG_DECIMAL, BigDecimal.class);
+    map.put(TYPE_GRADOOP_ID, GradoopId.class);
+    map.put(TYPE_MAP, Map.class);
+    map.put(TYPE_LIST, List.class);
+    map.put(TYPE_DATE, LocalDate.class);
+    map.put(TYPE_TIME, LocalTime.class);
+    map.put(TYPE_DATETIME, LocalDateTime.class);
+    return Collections.unmodifiableMap(map);
   }
 
   public int getByteSize() {
diff --git a/gradoop-common/src/test/java/org/gradoop/common/model/impl/properties/PropertyValueTest.java b/gradoop-common/src/test/java/org/gradoop/common/model/impl/properties/PropertyValueTest.java
index 988b8da4303..f3b81a48623 100644
--- a/gradoop-common/src/test/java/org/gradoop/common/model/impl/properties/PropertyValueTest.java
+++ b/gradoop-common/src/test/java/org/gradoop/common/model/impl/properties/PropertyValueTest.java
@@ -898,6 +898,52 @@ public class PropertyValueTest {
     p = create(DATETIME_VAL_d);
     assertEquals(p, writeAndReadFields(PropertyValue.class, p));
   }
+
+  @Test
+  public void testGetType() {
+    PropertyValue p = create(NULL_VAL_0);
+    assertNull(p.getType());
+
+    p = create(BOOL_VAL_1);
+    assertEquals(Boolean.class, p.getType());
+
+    p = create(INT_VAL_2);
+    assertEquals(Integer.class, p.getType());
+
+    p = create(LONG_VAL_3);
+    assertEquals(Long.class, p.getType());
+
+    p = create(FLOAT_VAL_4);
+    assertEquals(Float.class, p.getType());
+
+    p = create(DOUBLE_VAL_5);
+    assertEquals(Double.class, p.getType());
+
+    p = create(STRING_VAL_6);
+    assertEquals(String.class, p.getType());
+
+    p = create(BIG_DECIMAL_VAL_7);
+    assertEquals(BigDecimal.class, p.getType());
+
+    p = create(GRADOOP_ID_VAL_8);
+    assertEquals(GradoopId.class, p.getType());
+
+    p = create(MAP_VAL_9);
+    assertEquals(Map.class, p.getType());
+
+    p = create(LIST_VAL_a);
+    assertEquals(List.class, p.getType());
+
+    p = create(DATE_VAL_b);
+    assertEquals(LocalDate.class, p.getType());
+
+    p = create(TIME_VAL_c);
+    assertEquals(LocalTime.class, p.getType());
+
+    p = create(DATETIME_VAL_d);
+    assertEquals(LocalDateTime.class, p.getType());
+  }
+
   /**
    * Assumes that p1 == p2 < p3
    */