/** * {@inheritDoc} */ public ValueFactory<?> getValueFactory( Object prototype ) { CheckArg.isNotNull(prototype, "prototype"); PropertyType inferredType = PropertyType.discoverType(prototype); assert inferredType != null; return getValueFactory(inferredType); }
protected Factory( ValueFactory<T> valueFactory ) { this.valueFactory = valueFactory; this.type = this.valueFactory.getPropertyType(); this.typeName = type.getName().toUpperCase(); }
if (o1 == null) return -1; if (o2 == null) return 1; PropertyType type1 = PropertyType.discoverType(o1); PropertyType type2 = PropertyType.discoverType(o2); o1 = type1.getCanonicalValue(o1); o2 = type2.getCanonicalValue(o2); if (type1 == type2) return ((Comparator<Object>)type1.getComparator()).compare(o1, o2); if (type1.getValueClass().isAssignableFrom(type2.getValueClass())) { return ((Comparator<Object>)type1.getComparator()).compare(o1, o2); if (type2.getValueClass().isAssignableFrom(type1.getValueClass())) { return ((Comparator<Object>)type2.getComparator()).compare(o1, o2);
public static PropertyType discoverType( Object value ) { if (value == null) { throw new IllegalArgumentException(GraphI18n.unableToDiscoverPropertyTypeForNullValue.text()); } for (PropertyType type : PropertyType.values()) { if (type == OBJECT) continue; if (type.isTypeFor(value)) return type; } return OBJECT; }
/** * {@inheritDoc} * * @see org.modeshape.graph.query.model.TypeSystem.TypeFactory#getComparator() */ @SuppressWarnings( "unchecked" ) public Comparator<T> getComparator() { return (Comparator<T>)type.getComparator(); }
public final boolean isTypeForEach( Iterable<?> values ) { for (Object value : values) { if (!isTypeFor(value)) return false; } return true; }
/** * {@inheritDoc} * * @see org.modeshape.graph.query.model.TypeSystem.TypeFactory#getType() */ @SuppressWarnings( "unchecked" ) public Class<T> getType() { return (Class<T>)type.getValueClass(); }
/** * {@inheritDoc} * * @see org.modeshape.graph.query.model.TypeSystem#getDefaultComparator() */ @SuppressWarnings( "unchecked" ) public Comparator<Object> getDefaultComparator() { return (Comparator<Object>)PropertyType.OBJECT.getComparator(); }
public final boolean isTypeForEach( Iterator<?> values ) { while (values.hasNext()) { Object value = values.next(); if (!isTypeFor(value)) return false; } return true; }
@SuppressWarnings( "unchecked" ) protected final <T> T convert( String name, Class<T> type, T defaultValue, Map<String, Serializable> values, ExecutionContext context ) { Object value = values.get(name); if (value == null) return defaultValue; PropertyType propertyType = PropertyType.discoverType(type); if (propertyType != null) { ValueFactory<?> factory = context.getValueFactories().getValueFactory(propertyType); return (T)factory.create(value); } if (type.isInstance(value)) { return (T)value; } String msg = GraphI18n.errorConvertingType.text(value.getClass().getSimpleName(), type.getSimpleName(), value); throw new ValueFormatException(value, PropertyType.OBJECT, msg); }
protected List<String> typesFor( List<Column> columns ) { List<String> types = new ArrayList<String>(); for (int i = 0; i != columns.size(); ++i) { types.add(PropertyType.STRING.getName()); } return types; }
@Test public void shouldDiscoverPropertyTypeGivenArrayOfArrayOfPrimitiveArrayClass() throws Exception { assertThat(PropertyType.discoverType(new int[][][] {}.getClass()), is(PropertyType.LONG)); assertThat(PropertyType.discoverType(new long[][][] {}.getClass()), is(PropertyType.LONG)); assertThat(PropertyType.discoverType(new short[][][] {}.getClass()), is(PropertyType.LONG)); assertThat(PropertyType.discoverType(new boolean[][][] {}.getClass()), is(PropertyType.BOOLEAN)); assertThat(PropertyType.discoverType(new double[][][] {}.getClass()), is(PropertyType.DOUBLE)); assertThat(PropertyType.discoverType(new float[][][] {}.getClass()), is(PropertyType.DOUBLE)); }
protected List<String> typesFor( List<Column> columns ) { List<String> types = new ArrayList<String>(); for (int i = 0; i != columns.size(); ++i) { types.add(PropertyType.STRING.getName()); } return types; }
@Test public void shouldDiscoverPropertyTypeGivenNumberArrayClass() throws Exception { assertThat(PropertyType.discoverType(new Integer[] {}.getClass()), is(PropertyType.LONG)); assertThat(PropertyType.discoverType(new Long[] {}.getClass()), is(PropertyType.LONG)); assertThat(PropertyType.discoverType(new Short[] {}.getClass()), is(PropertyType.LONG)); assertThat(PropertyType.discoverType(new Boolean[] {}.getClass()), is(PropertyType.BOOLEAN)); assertThat(PropertyType.discoverType(new Double[] {}.getClass()), is(PropertyType.DOUBLE)); assertThat(PropertyType.discoverType(new Float[] {}.getClass()), is(PropertyType.DOUBLE)); }
/** * {@inheritDoc} */ public UUID create( Calendar value ) { throw new ValueFormatException(value, PropertyType.UUID, GraphI18n.unableToCreateValue.text(getPropertyType().getName(), Calendar.class.getSimpleName(), value)); }
@Test public void shouldDiscoverPropertyTypeGivenArrayOfPrimitiveArrayClass() throws Exception { assertThat(PropertyType.discoverType(new int[][] {}.getClass()), is(PropertyType.LONG)); assertThat(PropertyType.discoverType(new long[][] {}.getClass()), is(PropertyType.LONG)); assertThat(PropertyType.discoverType(new short[][] {}.getClass()), is(PropertyType.LONG)); assertThat(PropertyType.discoverType(new boolean[][] {}.getClass()), is(PropertyType.BOOLEAN)); assertThat(PropertyType.discoverType(new double[][] {}.getClass()), is(PropertyType.DOUBLE)); assertThat(PropertyType.discoverType(new float[][] {}.getClass()), is(PropertyType.DOUBLE)); }
/** * {@inheritDoc} */ public UUID create( Date value ) { throw new ValueFormatException(value, PropertyType.UUID, GraphI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value)); }
@Test public void shouldDiscoverPropertyTypeGivenArrayOfArrayOfNumberArrayClass() throws Exception { assertThat(PropertyType.discoverType(new Integer[][][] {}.getClass()), is(PropertyType.LONG)); assertThat(PropertyType.discoverType(new Long[][][] {}.getClass()), is(PropertyType.LONG)); assertThat(PropertyType.discoverType(new Short[][][] {}.getClass()), is(PropertyType.LONG)); assertThat(PropertyType.discoverType(new Boolean[][][] {}.getClass()), is(PropertyType.BOOLEAN)); assertThat(PropertyType.discoverType(new Double[][][] {}.getClass()), is(PropertyType.DOUBLE)); assertThat(PropertyType.discoverType(new Float[][][] {}.getClass()), is(PropertyType.DOUBLE)); }
/** * {@inheritDoc} * * @see org.modeshape.graph.property.ValueFactory#create(org.modeshape.graph.property.DateTime) */ public UUID create( DateTime value ) throws ValueFormatException { throw new ValueFormatException(value, PropertyType.UUID, GraphI18n.unableToCreateValue.text(getPropertyType().getName(), DateTime.class.getSimpleName(), value)); }