public Class<?> clazz() { Class<?> cls; switch (this.cardinality) { case SINGLE: cls = this.dataType().clazz(); break; // A set of values: Set<DataType> case SET: cls = LinkedHashSet.class; break; // A list of values: List<DataType> case LIST: cls = LinkedList.class; break; default: throw new AssertionError(String.format( "Unsupported cardinality: '%s'", this.cardinality)); } return cls; }
throw new AssertionError(String.format( "Number type only contains Byte, Integer, " + "Long, Float, Double, but got %s", this.clazz()));
/** * Check type of the value valid * @param value the property value to be checked data type * @return true if the value is or can convert to the data type, * otherwise false */ public <V> boolean checkDataType(V value) { if (value instanceof Number) { return this.dataType().valueToNumber(value) != null; } return this.dataType().clazz().isInstance(value); }
private static <V> V validPredicateValue(V value, PropertyKey pkey) { V validValue = pkey.convValue(value, false); E.checkArgumentNotNull(validValue, "Invalid data type of query value, " + "expect '%s', actual '%s'", pkey.dataType().clazz(), value.getClass()); return validValue; }
protected void parseProperty(Id key, String colValue, HugeElement owner) { // Get PropertyKey by PropertyKey name PropertyKey pkey = owner.graph().propertyKey(key); // Parse value Object value = JsonUtil.fromJson(colValue, pkey.clazz()); // Set properties of vertex/edge if (pkey.cardinality() == Cardinality.SINGLE) { owner.addProperty(pkey, value); } else { if (!(value instanceof Collection)) { throw new BackendException( "Invalid value of non-single property: %s", value); } for (Object v : (Collection<?>) value) { v = JsonUtil.castNumber(v, pkey.dataType().clazz()); owner.addProperty(pkey, v); } } }
private void parseProperty(String colName, String colValue, HugeElement owner) { String[] colParts = SplicingIdGenerator.split(colName); assert colParts.length == 2 : colName; // Get PropertyKey by PropertyKey id PropertyKey pkey = owner.graph().propertyKey(readId(colParts[1])); // Parse value Object value = JsonUtil.fromJson(colValue, pkey.clazz()); // Set properties of vertex/edge if (pkey.cardinality() == Cardinality.SINGLE) { owner.addProperty(pkey, value); } else { if (!(value instanceof Collection)) { throw new BackendException( "Invalid value of non-sigle property: %s", colValue); } for (Object v : (Collection<?>) value) { v = JsonUtil.castNumber(v, pkey.dataType().clazz()); owner.addProperty(pkey, v); } } }
public Class<?> clazz() { Class<?> cls; switch (this.cardinality) { case SINGLE: cls = this.dataType().clazz(); break; // A set of values: Set<DataType> case SET: cls = LinkedHashSet.class; break; // A list of values: List<DataType> case LIST: cls = LinkedList.class; break; default: throw new AssertionError(String.format( "Unsupported cardinality: '%s'", this.cardinality)); } return cls; }
throw new AssertionError(String.format( "Number type only contains Byte, Integer, " + "Long, Float, Double, but got %s", this.clazz()));
/** * Check type of the value valid * @param value the property value to be checked data type * @return true if the value is or can convert to the data type, * otherwise false */ public <V> boolean checkDataType(V value) { if (value instanceof Number) { return this.dataType().valueToNumber(value) != null; } return this.dataType().clazz().isInstance(value); }
private static <V> V validPredicateValue(V value, PropertyKey pkey) { V validValue = pkey.convValue(value, false); E.checkArgumentNotNull(validValue, "Invalid data type of query value, " + "expect '%s', actual '%s'", pkey.dataType().clazz(), value.getClass()); return validValue; }
protected void parseProperty(Id key, String colValue, HugeElement owner) { // Get PropertyKey by PropertyKey name PropertyKey pkey = owner.graph().propertyKey(key); // Parse value Object value = JsonUtil.fromJson(colValue, pkey.clazz()); // Set properties of vertex/edge if (pkey.cardinality() == Cardinality.SINGLE) { owner.addProperty(pkey, value); } else { if (!(value instanceof Collection)) { throw new BackendException( "Invalid value of non-single property: %s", value); } for (Object v : (Collection<?>) value) { v = JsonUtil.castNumber(v, pkey.dataType().clazz()); owner.addProperty(pkey, v); } } }
private void parseProperty(String colName, String colValue, HugeElement owner) { String[] colParts = SplicingIdGenerator.split(colName); assert colParts.length == 2 : colName; // Get PropertyKey by PropertyKey id PropertyKey pkey = owner.graph().propertyKey(readId(colParts[1])); // Parse value Object value = JsonUtil.fromJson(colValue, pkey.clazz()); // Set properties of vertex/edge if (pkey.cardinality() == Cardinality.SINGLE) { owner.addProperty(pkey, value); } else { if (!(value instanceof Collection)) { throw new BackendException( "Invalid value of non-sigle property: %s", colValue); } for (Object v : (Collection<?>) value) { v = JsonUtil.castNumber(v, pkey.dataType().clazz()); owner.addProperty(pkey, v); } } }