@Test public void testCustomLengthExpressions() { AttributeTypeBuilder builder = new AttributeTypeBuilder(); FilterFactory ff = CommonFactoryFinder.getFilterFactory(null); Function length = ff.function("LengthFunction", new Expression[] {ff.property(".")}); builder.addRestriction(ff.less(length, ff.literal(20))); builder.setBinding(String.class); AttributeDescriptor attribute = builder.buildDescriptor("attribute"); assertEquals(19, FeatureTypes.getFieldLength(attribute)); builder.addRestriction(ff.greater(ff.literal(20), length)); builder.setBinding(String.class); attribute = builder.buildDescriptor("attribute"); assertEquals(19, FeatureTypes.getFieldLength(attribute)); }
public static int getFieldLength(PropertyDescriptor descriptor) { PropertyType type = descriptor.getType(); Integer length = null; while (type != null) { for (Filter f : type.getRestrictions()) { Integer filterLength = null; try { if (f == null) { continue; } if (f instanceof PropertyIsLessThan) { BinaryComparisonOperator cf = (BinaryComparisonOperator) f; if (cf.getExpression1() instanceof LengthFunction) { filterLength = cf.getExpression2().evaluate(null, Integer.class) - 1; } } else if (f instanceof PropertyIsLessThanOrEqualTo) { BinaryComparisonOperator cf = (BinaryComparisonOperator) f; if (cf.getExpression1() instanceof LengthFunction) { filterLength = cf.getExpression2().evaluate(null, Integer.class); } } else if (f instanceof PropertyIsGreaterThan) { BinaryComparisonOperator cf = (BinaryComparisonOperator) f; if (cf.getExpression2() instanceof LengthFunction) { filterLength = cf.getExpression1().evaluate(null, Integer.class) - 1; } } else if (f instanceof PropertyIsGreaterThanOrEqualTo) { BinaryComparisonOperator cf = (BinaryComparisonOperator) f; if (cf.getExpression2() instanceof LengthFunction) { filterLength = cf.getExpression1().evaluate(null, Integer.class); } } } catch (NullPointerException e) { } if (filterLength != null) { if (length == null || filterLength < length) { length = filterLength; } } } type = type.getSuper(); } return length != null ? length : ANY_LENGTH; }
FeatureTypes { public static int getFieldLength(PropertyDescriptor descriptor) { PropertyType type = descriptor.getType(); Integer length = null; while (type != null) { for (Filter f : type.getRestrictions()) { Integer filterLength = null; try { if (f == null) { continue; } if (f instanceof PropertyIsLessThan) { BinaryComparisonOperator cf = (BinaryComparisonOperator) f; if (cf.getExpression1() instanceof LengthFunction) { filterLength = cf.getExpression2().evaluate(null, Integer.class) - 1; } } else if (f instanceof PropertyIsLessThanOrEqualTo) { BinaryComparisonOperator cf = (BinaryComparisonOperator) f; if (cf.getExpression1() instanceof LengthFunction) { filterLength = cf.getExpression2().evaluate(null, Integer.class); } } else if (f instanceof PropertyIsGreaterThan) { BinaryComparisonOperator cf = (BinaryComparisonOperator) f; if (cf.getExpression2() instanceof LengthFunction) { filterLength = cf.getExpression1().evaluate(null, Integer.class) - 1; } } else if (f instanceof PropertyIsGreaterThanOrEqualTo) { BinaryComparisonOperator cf = (BinaryComparisonOperator) f; if (cf.getExpression2() instanceof LengthFunction) { filterLength = cf.getExpression1().evaluate(null, Integer.class); } } } catch (NullPointerException e) { } if (filterLength != null) { if (length == null || filterLength < length) { length = filterLength; } } } type = type.getSuper(); } return length != null ? length : ANY_LENGTH; } }
FeatureTypes { public static int getFieldLength(PropertyDescriptor descriptor) { PropertyType type = descriptor.getType(); Integer length = null; while (type != null) { for (Filter f : type.getRestrictions()) { Integer filterLength = null; try { if (f == null) { continue; } if (f instanceof PropertyIsLessThan) { BinaryComparisonOperator cf = (BinaryComparisonOperator) f; if (cf.getExpression1() instanceof LengthFunction) { filterLength = cf.getExpression2().evaluate(null, Integer.class) - 1; } } else if (f instanceof PropertyIsLessThanOrEqualTo) { BinaryComparisonOperator cf = (BinaryComparisonOperator) f; if (cf.getExpression1() instanceof LengthFunction) { filterLength = cf.getExpression2().evaluate(null, Integer.class); } } else if (f instanceof PropertyIsGreaterThan) { BinaryComparisonOperator cf = (BinaryComparisonOperator) f; if (cf.getExpression2() instanceof LengthFunction) { filterLength = cf.getExpression1().evaluate(null, Integer.class) - 1; } } else if (f instanceof PropertyIsGreaterThanOrEqualTo) { BinaryComparisonOperator cf = (BinaryComparisonOperator) f; if (cf.getExpression2() instanceof LengthFunction) { filterLength = cf.getExpression1().evaluate(null, Integer.class); } } } catch (NullPointerException e) { } if (filterLength != null) { if (length == null || filterLength < length) { length = filterLength; } } } type = type.getSuper(); } return length != null ? length : ANY_LENGTH; }  }
FeatureTypes { public static int getFieldLength(PropertyDescriptor descriptor) { PropertyType type = descriptor.getType(); Integer length = null; while (type != null) { for (Filter f : type.getRestrictions()) { Integer filterLength = null; try { if (f == null) { continue; } if (f instanceof PropertyIsLessThan) { BinaryComparisonOperator cf = (BinaryComparisonOperator) f; if (cf.getExpression1() instanceof LengthFunction) { filterLength = cf.getExpression2().evaluate(null, Integer.class) - 1; } } else if (f instanceof PropertyIsLessThanOrEqualTo) { BinaryComparisonOperator cf = (BinaryComparisonOperator) f; if (cf.getExpression1() instanceof LengthFunction) { filterLength = cf.getExpression2().evaluate(null, Integer.class); } } else if (f instanceof PropertyIsGreaterThan) { BinaryComparisonOperator cf = (BinaryComparisonOperator) f; if (cf.getExpression2() instanceof LengthFunction) { filterLength = cf.getExpression1().evaluate(null, Integer.class) - 1; } } else if (f instanceof PropertyIsGreaterThanOrEqualTo) { BinaryComparisonOperator cf = (BinaryComparisonOperator) f; if (cf.getExpression2() instanceof LengthFunction) { filterLength = cf.getExpression1().evaluate(null, Integer.class); } } } catch (NullPointerException e) { } if (filterLength != null) { if (length == null || filterLength < length) { length = filterLength; } } } type = type.getSuper(); } return length != null ? length : ANY_LENGTH; }  static Filter createLengthRestriction(int length); static int getFieldLength(PropertyDescriptor descriptor); static List<?> getFieldOptions(PropertyDescriptor descriptor); static Filter createFieldOptions(Collection<?> options); static SimpleFeatureType transform(
            SimpleFeatureType schema, CoordinateReferenceSystem crs); static SimpleFeatureType transform(
            SimpleFeatureType schema, CoordinateReferenceSystem crs, boolean forceOnlyMissing); static SimpleFeature transform(
            SimpleFeature feature, SimpleFeatureType schema, MathTransform transform); static SimpleFeatureType newFeatureType(
            AttributeDescriptor[] types,
            String name,
            URI ns,
            boolean isAbstract,
            SimpleFeatureType[] superTypes); static SimpleFeatureType newFeatureType(
            AttributeDescriptor[] types,
            String name,
            URI ns,
            boolean isAbstract,
            SimpleFeatureType[] superTypes,
            AttributeDescriptor defaultGeometry); static SimpleFeatureType newFeatureType(
            AttributeDescriptor[] types,
            String name,
            URI ns,
            boolean isAbstract,
            SimpleFeatureType[] superTypes,
            GeometryDescriptor defaultGeometry); static SimpleFeatureType newFeatureType(
            AttributeDescriptor[] types, String name, URI ns, boolean isAbstract); static SimpleFeatureType newFeatureType(AttributeDescriptor[] types, String name, URI ns); static SimpleFeatureType newFeatureType(AttributeDescriptor[] types, String name); static List<FeatureType> getAncestors(FeatureType featureType); static boolean matches(FeatureType featureType, Name name); static boolean isDecendedFrom(FeatureType featureType, URI namespace, String typeName); static boolean isDecendedFrom(FeatureType featureType, FeatureType isParentType); static boolean equals(SimpleFeatureType typeA, SimpleFeatureType typeB); static boolean equalsExact(SimpleFeatureType typeA, SimpleFeatureType typeB); static boolean equals(List attributesA, List attributesB); static boolean equalsExact(List attributesA, List attributesB); static boolean equals(
            AttributeDescriptor attributesA[], AttributeDescriptor attributesB[]); static boolean equalsExact(
            AttributeDescriptor attributesA[], AttributeDescriptor attributesB[]); static boolean equalsAncestors(SimpleFeatureType typeA, SimpleFeatureType typeB); static Set ancestors(SimpleFeatureType featureType); static boolean equals(AttributeDescriptor a, AttributeDescriptor b); static boolean equalsExact(AttributeDescriptor a, AttributeDescriptor b); static boolean equalsId(SimpleFeatureType typeA, SimpleFeatureType typeB); }
FeatureTypes { public static int getFieldLength(PropertyDescriptor descriptor) { PropertyType type = descriptor.getType(); Integer length = null; while (type != null) { for (Filter f : type.getRestrictions()) { Integer filterLength = null; try { if (f == null) { continue; } if (f instanceof PropertyIsLessThan) { BinaryComparisonOperator cf = (BinaryComparisonOperator) f; if (cf.getExpression1() instanceof LengthFunction) { filterLength = cf.getExpression2().evaluate(null, Integer.class) - 1; } } else if (f instanceof PropertyIsLessThanOrEqualTo) { BinaryComparisonOperator cf = (BinaryComparisonOperator) f; if (cf.getExpression1() instanceof LengthFunction) { filterLength = cf.getExpression2().evaluate(null, Integer.class); } } else if (f instanceof PropertyIsGreaterThan) { BinaryComparisonOperator cf = (BinaryComparisonOperator) f; if (cf.getExpression2() instanceof LengthFunction) { filterLength = cf.getExpression1().evaluate(null, Integer.class) - 1; } } else if (f instanceof PropertyIsGreaterThanOrEqualTo) { BinaryComparisonOperator cf = (BinaryComparisonOperator) f; if (cf.getExpression2() instanceof LengthFunction) { filterLength = cf.getExpression1().evaluate(null, Integer.class); } } } catch (NullPointerException e) { } if (filterLength != null) { if (length == null || filterLength < length) { length = filterLength; } } } type = type.getSuper(); } return length != null ? length : ANY_LENGTH; }  static Filter createLengthRestriction(int length); static int getFieldLength(PropertyDescriptor descriptor); static List<?> getFieldOptions(PropertyDescriptor descriptor); static Filter createFieldOptions(Collection<?> options); static SimpleFeatureType transform(
            SimpleFeatureType schema, CoordinateReferenceSystem crs); static SimpleFeatureType transform(
            SimpleFeatureType schema, CoordinateReferenceSystem crs, boolean forceOnlyMissing); static SimpleFeature transform(
            SimpleFeature feature, SimpleFeatureType schema, MathTransform transform); static SimpleFeatureType newFeatureType(
            AttributeDescriptor[] types,
            String name,
            URI ns,
            boolean isAbstract,
            SimpleFeatureType[] superTypes); static SimpleFeatureType newFeatureType(
            AttributeDescriptor[] types,
            String name,
            URI ns,
            boolean isAbstract,
            SimpleFeatureType[] superTypes,
            AttributeDescriptor defaultGeometry); static SimpleFeatureType newFeatureType(
            AttributeDescriptor[] types,
            String name,
            URI ns,
            boolean isAbstract,
            SimpleFeatureType[] superTypes,
            GeometryDescriptor defaultGeometry); static SimpleFeatureType newFeatureType(
            AttributeDescriptor[] types, String name, URI ns, boolean isAbstract); static SimpleFeatureType newFeatureType(AttributeDescriptor[] types, String name, URI ns); static SimpleFeatureType newFeatureType(AttributeDescriptor[] types, String name); static List<FeatureType> getAncestors(FeatureType featureType); static boolean matches(FeatureType featureType, Name name); static boolean isDecendedFrom(FeatureType featureType, URI namespace, String typeName); static boolean isDecendedFrom(FeatureType featureType, FeatureType isParentType); static boolean equals(SimpleFeatureType typeA, SimpleFeatureType typeB); static boolean equalsExact(SimpleFeatureType typeA, SimpleFeatureType typeB); static boolean equals(List attributesA, List attributesB); static boolean equalsExact(List attributesA, List attributesB); static boolean equals(
            AttributeDescriptor attributesA[], AttributeDescriptor attributesB[]); static boolean equalsExact(
            AttributeDescriptor attributesA[], AttributeDescriptor attributesB[]); static boolean equalsAncestors(SimpleFeatureType typeA, SimpleFeatureType typeB); static Set ancestors(SimpleFeatureType featureType); static boolean equals(AttributeDescriptor a, AttributeDescriptor b); static boolean equalsExact(AttributeDescriptor a, AttributeDescriptor b); static boolean equalsId(SimpleFeatureType typeA, SimpleFeatureType typeB); static final URI DEFAULT_NAMESPACE; static final SimpleFeatureType ABSTRACT_FEATURE_TYPE; static final NameImpl DEFAULT_TYPENAME; static final int ANY_LENGTH; static final SimpleFeatureType EMPTY; }