ElementImpl implements Element { void checkType(Column column, Object value) { if (value != null) { Class typeClass = column.getTypeClass(); if (TimestampMap.class.isAssignableFrom(typeClass)) { if ((value instanceof Double && (!typeClass.equals(TimestampDoubleMap.class))) || (value instanceof Float && !typeClass .equals(TimestampFloatMap.class)) || (value instanceof Boolean && !typeClass .equals(TimestampBooleanMap.class)) || (value instanceof Integer && !typeClass .equals(TimestampIntegerMap.class)) || (value instanceof Long && !typeClass .equals(TimestampLongMap.class)) || (value instanceof Short && !typeClass .equals(TimestampShortMap.class)) || (value instanceof Byte && !typeClass .equals(TimestampByteMap.class)) || (value instanceof String && !typeClass .equals(TimestampStringMap.class)) || (value instanceof Character && !typeClass .equals(TimestampCharMap.class))) { throw new IllegalArgumentException( "The object class does not match with the dynamic type (" + typeClass.getName() + ")"); } } else if (IntervalMap.class.isAssignableFrom(typeClass)) { if ((value instanceof Double && (!typeClass.equals(IntervalDoubleMap.class))) || (value instanceof Float && !typeClass .equals(IntervalFloatMap.class)) || (value instanceof Boolean && !typeClass .equals(IntervalBooleanMap.class)) || (value instanceof Integer && !typeClass .equals(IntervalIntegerMap.class)) || (value instanceof Long && !typeClass .equals(IntervalLongMap.class)) || (value instanceof Short && !typeClass .equals(IntervalShortMap.class)) || (value instanceof Byte && !typeClass .equals(IntervalByteMap.class)) || (value instanceof String && !typeClass .equals(IntervalStringMap.class)) || (value instanceof Character && !typeClass .equals(IntervalCharMap.class))) { throw new IllegalArgumentException( "The object class does not match with the dynamic type (" + typeClass.getName() + ")"); } } else if (List.class.isAssignableFrom(typeClass)) { if (!(value instanceof List)) { throw new IllegalArgumentException( "The object class does not match with the list type (" + typeClass.getName() + ")"); } } else if (Set.class.isAssignableFrom(typeClass)) { if (!(value instanceof Set)) { throw new IllegalArgumentException( "The object class does not match with the set type (" + typeClass.getName() + ")"); } } else if (Map.class.isAssignableFrom(typeClass)) { if (!(value instanceof Map)) { throw new IllegalArgumentException( "The object class does not match with the map type (" + typeClass.getName() + ")"); } } else if (!value.getClass().equals(typeClass)) { throw new IllegalArgumentException( "The object class does not match with the column type (" + typeClass.getName() + ")"); } } } ElementImpl(Object id, GraphStore graphStore); @Override Object getId(); @Override String getLabel(); @Override Object getAttribute(String key); @Override Object getAttribute(Column column); @Override Object getAttribute(String key, double timestamp); @Override Object getAttribute(Column column, double timestamp); @Override Object getAttribute(String key, Interval interval); @Override Object getAttribute(Column column, Interval interval); @Override Object getAttribute(String key, GraphView view); @Override Object getAttribute(Column column, GraphView view); @Override Object[] getAttributes(); @Override Set<String> getAttributeKeys(); @Override ColumnIterable getAttributeColumns(); @Override Object removeAttribute(String key); @Override Object removeAttribute(Column column); @Override Object removeAttribute(Column column, double timestamp); @Override Object removeAttribute(String key, double timestamp); @Override Object removeAttribute(Column column, Interval interval); @Override Object removeAttribute(String key, Interval interval); @Override void setLabel(String label); @Override void setAttribute(String key, Object value); @Override void setAttribute(Column column, Object value); @Override void setAttribute(String key, Object value, double timestamp); @Override void setAttribute(Column column, Object value, double timestamp); @Override void setAttribute(String key, Object value, Interval interval); @Override void setAttribute(Column column, Object value, Interval interval); @Override boolean addTimestamp(double timestamp); @Override boolean addInterval(Interval interval); @Override boolean removeTimestamp(double timestamp); @Override boolean removeInterval(Interval interval); @Override double[] getTimestamps(); @Override Interval[] getIntervals(); @Override boolean hasTimestamp(double timestamp); @Override boolean hasInterval(Interval interval); @Override Iterable<Map.Entry> getAttributes(Column column); @Override void clearAttributes(); @Override int hashCode(); @Override boolean equals(Object obj);  }
@Test public void testCheckType() { GraphStore store = new GraphStore(); NodeImpl node = new NodeImpl("0", store); node.checkType(new ColumnImpl("0", TimestampIntegerMap.class, null, null, Origin.DATA, false, false), 1); node.checkType(new ColumnImpl("0", TimestampDoubleMap.class, null, null, Origin.DATA, false, false), 1.0); node.checkType(new ColumnImpl("0", TimestampFloatMap.class, null, null, Origin.DATA, false, false), 1f); node.checkType(new ColumnImpl("0", TimestampByteMap.class, null, null, Origin.DATA, false, false), (byte) 1); node.checkType(new ColumnImpl("0", TimestampShortMap.class, null, null, Origin.DATA, false, false), (short) 1); node.checkType(new ColumnImpl("0", TimestampLongMap.class, null, null, Origin.DATA, false, false), 1l); node.checkType(new ColumnImpl("0", TimestampCharMap.class, null, null, Origin.DATA, false, false), 'a'); node.checkType(new ColumnImpl("0", TimestampBooleanMap.class, null, null, Origin.DATA, false, false), true); node.checkType(new ColumnImpl("0", TimestampStringMap.class, null, null, Origin.DATA, false, false), "foo"); node.checkType(new ColumnImpl("0", IntervalIntegerMap.class, null, null, Origin.DATA, false, false), 1); node.checkType(new ColumnImpl("0", IntervalDoubleMap.class, null, null, Origin.DATA, false, false), 1.0); node.checkType(new ColumnImpl("0", IntervalFloatMap.class, null, null, Origin.DATA, false, false), 1f); node.checkType(new ColumnImpl("0", IntervalByteMap.class, null, null, Origin.DATA, false, false), (byte) 1); node.checkType(new ColumnImpl("0", IntervalShortMap.class, null, null, Origin.DATA, false, false), (short) 1); node.checkType(new ColumnImpl("0", IntervalLongMap.class, null, null, Origin.DATA, false, false), 1l); node.checkType(new ColumnImpl("0", IntervalCharMap.class, null, null, Origin.DATA, false, false), 'a'); node.checkType(new ColumnImpl("0", IntervalBooleanMap.class, null, null, Origin.DATA, false, false), true); node.checkType(new ColumnImpl("0", IntervalStringMap.class, null, null, Origin.DATA, false, false), "foo"); }