Skip to content
Permalink
Browse files

[#1184] Refactor type byte constants (#1251)

fixes #1184
  • Loading branch information...
Rascat authored and galpha committed May 7, 2019
1 parent 76ff80c commit 591c9d9ddf3b0a5939748248d87d7cdb19121457
Showing with 222 additions and 251 deletions.
  1. +33 −125 gradoop-common/src/main/java/org/gradoop/common/model/impl/metadata/MetaData.java
  2. +2 −65 gradoop-common/src/main/java/org/gradoop/common/model/impl/properties/PropertyValue.java
  3. +94 −0 gradoop-common/src/main/java/org/gradoop/common/model/impl/properties/Type.java
  4. +2 −1 ...-common/src/main/java/org/gradoop/common/model/impl/properties/strategies/BigDecimalStrategy.java
  5. +2 −1 ...oop-common/src/main/java/org/gradoop/common/model/impl/properties/strategies/BooleanStrategy.java
  6. +3 −1 gradoop-common/src/main/java/org/gradoop/common/model/impl/properties/strategies/DateStrategy.java
  7. +3 −1 ...op-common/src/main/java/org/gradoop/common/model/impl/properties/strategies/DateTimeStrategy.java
  8. +3 −1 gradoop-common/src/main/java/org/gradoop/common/model/impl/properties/strategies/DoubleStrategy.java
  9. +3 −1 gradoop-common/src/main/java/org/gradoop/common/model/impl/properties/strategies/FloatStrategy.java
  10. +3 −1 ...p-common/src/main/java/org/gradoop/common/model/impl/properties/strategies/GradoopIdStrategy.java
  11. +3 −1 ...oop-common/src/main/java/org/gradoop/common/model/impl/properties/strategies/IntegerStrategy.java
  12. +3 −1 gradoop-common/src/main/java/org/gradoop/common/model/impl/properties/strategies/ListStrategy.java
  13. +3 −1 gradoop-common/src/main/java/org/gradoop/common/model/impl/properties/strategies/LongStrategy.java
  14. +4 −2 gradoop-common/src/main/java/org/gradoop/common/model/impl/properties/strategies/MapStrategy.java
  15. +2 −2 gradoop-common/src/main/java/org/gradoop/common/model/impl/properties/strategies/NullStrategy.java
  16. +3 −2 ...c/main/java/org/gradoop/common/model/impl/properties/strategies/PropertyValueStrategyFactory.java
  17. +2 −1 gradoop-common/src/main/java/org/gradoop/common/model/impl/properties/strategies/SetStrategy.java
  18. +3 −1 gradoop-common/src/main/java/org/gradoop/common/model/impl/properties/strategies/ShortStrategy.java
  19. +3 −1 gradoop-common/src/main/java/org/gradoop/common/model/impl/properties/strategies/StringStrategy.java
  20. +3 −1 gradoop-common/src/main/java/org/gradoop/common/model/impl/properties/strategies/TimeStrategy.java
  21. +15 −15 gradoop-common/src/test/java/org/gradoop/common/model/impl/properties/PropertyValueUtilsTest.java
  22. +18 −17 gradoop-flink/src/main/java/org/gradoop/flink/io/impl/csv/metadata/CSVMetaDataParser.java
  23. +2 −1 ...c/test/java/org/gradoop/flink/model/impl/operators/cypher/capf/query/CAPFPatternMatchingTest.java
  24. +4 −3 ...p-flink/src/test/java/org/gradoop/flink/model/impl/operators/cypher/capf/query/CAPFQueryTest.java
  25. +4 −3 ...gradoop-hbase/src/main/java/org/gradoop/storage/impl/hbase/predicate/filter/HBaseFilterUtils.java
  26. +2 −2 ...op-hbase/src/test/java/org/gradoop/storage/impl/hbase/predicate/filter/impl/HBasePropRegTest.java
@@ -17,6 +17,7 @@

import org.gradoop.common.model.impl.id.GradoopId;
import org.gradoop.common.model.impl.properties.PropertyValue;
import org.gradoop.common.model.impl.properties.Type;

import java.math.BigDecimal;
import java.time.LocalDate;
@@ -87,22 +88,22 @@ protected MetaData(Map<String, List<PropertyMetaData>> graphMetaData,
*/
private static Map<String, Class<?>> createStringToClassMap() {
Map<String, Class<?>> stringClassMap = new HashMap<>();
stringClassMap.put(TypeString.NULL.getTypeString(), null);
stringClassMap.put(TypeString.SHORT.getTypeString(), Short.class);
stringClassMap.put(TypeString.INTEGER.getTypeString(), Integer.class);
stringClassMap.put(TypeString.LONG.getTypeString(), Long.class);
stringClassMap.put(TypeString.FLOAT.getTypeString(), Float.class);
stringClassMap.put(TypeString.DOUBLE.getTypeString(), Double.class);
stringClassMap.put(TypeString.BOOLEAN.getTypeString(), Boolean.class);
stringClassMap.put(TypeString.STRING.getTypeString(), String.class);
stringClassMap.put(TypeString.BIGDECIMAL.getTypeString(), BigDecimal.class);
stringClassMap.put(TypeString.GRADOOPID.getTypeString(), GradoopId.class);
stringClassMap.put(TypeString.MAP.getTypeString(), Map.class);
stringClassMap.put(TypeString.LIST.getTypeString(), List.class);
stringClassMap.put(TypeString.LOCALDATE.getTypeString(), LocalDate.class);
stringClassMap.put(TypeString.LOCALTIME.getTypeString(), LocalTime.class);
stringClassMap.put(TypeString.LOCALDATETIME.getTypeString(), LocalDateTime.class);
stringClassMap.put(TypeString.SET.getTypeString(), Set.class);
stringClassMap.put(Type.NULL.toString(), null);
stringClassMap.put(Type.SHORT.toString(), Short.class);
stringClassMap.put(Type.INTEGER.toString(), Integer.class);
stringClassMap.put(Type.LONG.toString(), Long.class);
stringClassMap.put(Type.FLOAT.toString(), Float.class);
stringClassMap.put(Type.DOUBLE.toString(), Double.class);
stringClassMap.put(Type.BOOLEAN.toString(), Boolean.class);
stringClassMap.put(Type.STRING.toString(), String.class);
stringClassMap.put(Type.BIG_DECIMAL.toString(), BigDecimal.class);
stringClassMap.put(Type.GRADOOP_ID.toString(), GradoopId.class);
stringClassMap.put(Type.MAP.toString(), Map.class);
stringClassMap.put(Type.LIST.toString(), List.class);
stringClassMap.put(Type.DATE.toString(), LocalDate.class);
stringClassMap.put(Type.TIME.toString(), LocalTime.class);
stringClassMap.put(Type.DATE_TIME.toString(), LocalDateTime.class);
stringClassMap.put(Type.SET.toString(), Set.class);
return Collections.unmodifiableMap(stringClassMap);
}

@@ -172,143 +173,50 @@ protected MetaData(Map<String, List<PropertyMetaData>> graphMetaData,
*/
public static String getTypeString(PropertyValue propertyValue) {
if (propertyValue.isNull()) {
return TypeString.NULL.getTypeString();
return Type.NULL.toString();
} else if (propertyValue.isShort()) {
return TypeString.SHORT.getTypeString();
return Type.SHORT.toString();
} else if (propertyValue.isInt()) {
return TypeString.INTEGER.getTypeString();
return Type.INTEGER.toString();
} else if (propertyValue.isLong()) {
return TypeString.LONG.getTypeString();
return Type.LONG.toString();
} else if (propertyValue.isFloat()) {
return TypeString.FLOAT.getTypeString();
return Type.FLOAT.toString();
} else if (propertyValue.isDouble()) {
return TypeString.DOUBLE.getTypeString();
return Type.DOUBLE.toString();
} else if (propertyValue.isBoolean()) {
return TypeString.BOOLEAN.getTypeString();
return Type.BOOLEAN.toString();
} else if (propertyValue.isString()) {
return TypeString.STRING.getTypeString();
return Type.STRING.toString();
} else if (propertyValue.isBigDecimal()) {
return TypeString.BIGDECIMAL.getTypeString();
return Type.BIG_DECIMAL.toString();
} else if (propertyValue.isGradoopId()) {
return TypeString.GRADOOPID.getTypeString();
return Type.GRADOOP_ID.toString();
} else if (propertyValue.isMap()) {
// map type string is map:{keyType}:{valueType}
return TypeString.MAP.getTypeString() +
return Type.MAP.toString() +
PROPERTY_TOKEN_DELIMITER +
getTypeString(propertyValue.getMap().keySet().iterator().next()) +
PROPERTY_TOKEN_DELIMITER +
getTypeString(propertyValue.getMap().values().iterator().next());
} else if (propertyValue.isList()) {
// list type string is list:{itemType}
return TypeString.LIST.getTypeString() +
return Type.LIST.toString() +
PROPERTY_TOKEN_DELIMITER +
getTypeString(propertyValue.getList().get(0));
} else if (propertyValue.isDate()) {
return TypeString.LOCALDATE.getTypeString();
return Type.DATE.toString();
} else if (propertyValue.isTime()) {
return TypeString.LOCALTIME.getTypeString();
return Type.TIME.toString();
} else if (propertyValue.isDateTime()) {
return TypeString.LOCALDATETIME.getTypeString();
return Type.DATE_TIME.toString();
} else if (propertyValue.isSet()) {
// set type string is set:{itemType}
return TypeString.SET.getTypeString() +
return Type.SET.toString() +
PROPERTY_TOKEN_DELIMITER +
getTypeString(propertyValue.getSet().iterator().next());
} else {
throw new IllegalArgumentException("Type " + propertyValue.getType() + " is not supported");
}
}

/**
* Supported type strings for the CSV format.
*/
public enum TypeString {
/**
* Null type
*/
NULL("null"),
/**
* Boolean type
*/
BOOLEAN("boolean"),
/**
* Short type
*/
SHORT("short"),
/**
* Integer type
*/
INTEGER("int"),
/**
* Long type
*/
LONG("long"),
/**
* Float type
*/
FLOAT("float"),
/**
* Double type
*/
DOUBLE("double"),
/**
* String type
*/
STRING("string"),
/**
* BigDecimal type
*/
BIGDECIMAL("bigdecimal"),
/**
* GradoopId type
*/
GRADOOPID("gradoopid"),
/**
* Map type
*/
MAP("map"),
/**
* List type
*/
LIST("list"),
/**
* LocalDate type
*/
LOCALDATE("localdate"),
/**
* LocalTime type
*/
LOCALTIME("localtime"),
/**
* LocalDateTime type
*/
LOCALDATETIME("localdatetime"),
/**
* Set type
*/
SET("set");

/**
* String representation
*/
private String typeString;

/**
* Constructor
*
* @param typeString string representation
*/
TypeString(String typeString) {
this.typeString = typeString;
}

/**
* Returns the type string.
*
* @return type string
*/
public String getTypeString() {
return typeString;
}
}
}
@@ -46,70 +46,7 @@
* Represents a property value that is {@code null}.
*/
public static final PropertyValue NULL_VALUE = PropertyValue.create(null);
/**
* {@code <property-type>} for empty property value (i.e. {@code null})
*/
public static final transient byte TYPE_NULL = 0x00;
/**
* {@code <property-type>} for {@link java.lang.Boolean}
*/
public static final transient byte TYPE_BOOLEAN = 0x01;
/**
* {@code <property-type>} for {@link java.lang.Integer}
*/
public static final transient byte TYPE_INTEGER = 0x02;
/**
* {@code <property-type>} for {@link java.lang.Long}
*/
public static final transient byte TYPE_LONG = 0x03;
/**
* {@code <property-type>} for {@link java.lang.Float}
*/
public static final transient byte TYPE_FLOAT = 0x04;
/**
* {@code <property-type>} for {@link java.lang.Double}
*/
public static final transient byte TYPE_DOUBLE = 0x05;
/**
* {@code <property-type>} for {@link java.lang.String}
*/
public static final transient byte TYPE_STRING = 0x06;
/**
* {@code <property-type>} for {@link BigDecimal}
*/
public static final transient byte TYPE_BIG_DECIMAL = 0x07;
/**
* {@code <property-type>} for {@link org.gradoop.common.model.impl.id.GradoopId}
*/
public static final transient byte TYPE_GRADOOP_ID = 0x08;
/**
* {@code <property-type>} for {@link java.util.HashMap}
*/
public static final transient byte TYPE_MAP = 0x09;
/**
* {@code <property-type>} for {@link java.util.List}
*/
public static final transient byte TYPE_LIST = 0x0a;
/**
* {@code <property-type>} for {@link LocalDate}
*/
public static final transient byte TYPE_DATE = 0x0b;
/**
* {@code <property-type>} for {@link LocalTime}
*/
public static final transient byte TYPE_TIME = 0x0c;
/**
* {@code <property-type>} for {@link LocalDateTime}
*/
public static final transient byte TYPE_DATETIME = 0x0d;
/**
* {@code <property-type>} for {@link java.lang.Short}
*/
public static final transient byte TYPE_SHORT = 0x0e;
/**
* {@code <property-type>} for {@link java.util.Set}
*/
public static final transient byte TYPE_SET = 0x0f;

/**
* Value offset in byte
*/
@@ -220,7 +157,7 @@ public boolean is(Class clazz) {
* @return true, if {@code null} value
*/
public boolean isNull() {
return getRawBytes()[0] == PropertyValue.TYPE_NULL;
return getRawBytes()[0] == Type.NULL.getTypeByte();
}

/**
@@ -0,0 +1,94 @@
/*
* Copyright © 2014 - 2019 Leipzig University (Database Research Group)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gradoop.common.model.impl.properties;

/**
* Representations of types that are supported by
* {@link org.gradoop.common.model.impl.properties.PropertyValue}
*/
public enum Type {
/** Null type */
NULL(0x00, "null"),
/** Boolean type */
BOOLEAN(0x01, "boolean"),
/** Integer type */
INTEGER(0x02, "int"),
/** Long type */
LONG(0x03, "long"),
/** Float type */
FLOAT(0x04, "float"),
/** Double type */
DOUBLE(0x05, "double"),
/** String type */
STRING(0x06, "string"),
/** BigDecimal type */
BIG_DECIMAL(0x07, "bigdecimal"),
/** GradoopId type */
GRADOOP_ID(0x08, "gradoopid"),
/** Map type */
MAP(0x09, "map"),
/** List type */
LIST(0x0a, "list"),
/** Date type */
DATE(0x0b, "localdate"),
/** Time type */
TIME(0x0c, "localtime"),
/** DateTime type */
DATE_TIME(0x0d, "localdatetime"),
/** Short type */
SHORT(0x0e, "short"),
/** Set type */
SET(0x0f, "set");

/**
* Byte representation
*/
private final byte typeByte;
/**
* String representation
*/
private final String typeString;

/**
* Constructs an enum type that represents a supported type.
*
* @param typeByte byte representation as int, is casted to byte
* @param typeString string representation
*/
Type(int typeByte, String typeString) {
this.typeByte = (byte) typeByte;
this.typeString = typeString;
}

/**
* Returns the byte representation.
*
* @return type byte
*/
public byte getTypeByte() {
return typeByte;
}

/**
* Returns the string representation.
*
* @return type string
*/
@Override
public String toString() {
return typeString;
}
}
@@ -18,6 +18,7 @@
import org.apache.flink.core.memory.DataInputView;
import org.apache.hadoop.hbase.util.Bytes;
import org.gradoop.common.model.impl.properties.PropertyValue;
import org.gradoop.common.model.impl.properties.Type;

import java.io.IOException;
import java.math.BigDecimal;
@@ -61,7 +62,7 @@ public BigDecimal get(byte[] bytes) {

@Override
public byte getRawType() {
return PropertyValue.TYPE_BIG_DECIMAL;
return Type.BIG_DECIMAL.getTypeByte();
}

@Override
Oops, something went wrong.

0 comments on commit 591c9d9

Please sign in to comment.
You can’t perform that action at this time.