use of org.apache.sis.feature.builder.FeatureTypeBuilder in project sis by apache.
the class RegistryTestCase method createFeatureWithGeometry.
/**
* Creates a feature with a single property named {@value #P_NAME}.
* The current {@link #geometry} value is assigned to that feature.
*
* @param type the type of value in the property.
* @return a feature with a property of the given type.
*/
private AbstractFeature createFeatureWithGeometry(final Class<?> type) {
final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
ftb.addAttribute(type).setName(P_NAME);
final DefaultFeatureType mockType = ftb.setName("Test").build();
final AbstractFeature feature = mockType.newInstance();
feature.setPropertyValue(P_NAME, geometry);
return feature;
}
use of org.apache.sis.feature.builder.FeatureTypeBuilder in project sis by apache.
the class LeafExpressionTest method testReferenceEvaluation.
/**
* Tests evaluation of "ValueReference", including with type conversion.
*/
@Test
public void testReferenceEvaluation() {
final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
ftb.addAttribute(String.class).setName("some_property");
final AbstractFeature f = ftb.setName("Test").build().newInstance();
Expression<AbstractFeature, ?> ref = factory.property("some_property");
assertNull(ref.apply(f));
assertNull(ref.apply(null));
f.setPropertyValue("some_property", "road");
assertEquals("road", ref.apply(f));
ref = factory.property("some_property", String.class);
assertEquals("road", ref.apply(f));
f.setPropertyValue("some_property", "45.1");
assertEquals("45.1", ref.apply(f));
ref = factory.property("some_property", Double.class);
assertEquals(45.1, ref.apply(f));
}
use of org.apache.sis.feature.builder.FeatureTypeBuilder in project sis by apache.
the class LogicalFilterTest method testFeatureOptimization.
/**
* Tests {@link Optimization} applied on logical filters when the {@link DefaultFeatureType} is known.
*/
@Test
public void testFeatureOptimization() {
final String attribute = "population";
final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
ftb.addAttribute(String.class).setName(attribute);
final DefaultFeatureType type = ftb.setName("Test").build();
final AbstractFeature instance = type.newInstance();
instance.setPropertyValue("population", "1000");
/*
* Prepare an expression which divide the population value by 5.
*/
final Expression<AbstractFeature, Number> e = factory.divide(factory.property(attribute, Integer.class), factory.literal(5));
final Optimization optimization = new Optimization();
// No optimization.
assertSame(e, optimization.apply(e));
assertEquals(200, e.apply(instance).intValue());
/*
* Notify the optimizer that property values will be of `String` type.
* The optimizer should compute an `ObjectConverter` in advance.
*/
optimization.setFeatureType(type);
final Expression<? super AbstractFeature, ? extends Number> opt = optimization.apply(e);
assertEquals(200, e.apply(instance).intValue());
assertNotSame(e, opt);
final PropertyValue<?> p = (PropertyValue<?>) opt.getParameters().get(0);
assertEquals(String.class, p.getSourceClass());
assertEquals(Number.class, p.getValueClass());
}
use of org.apache.sis.feature.builder.FeatureTypeBuilder in project sis by apache.
the class IdentifierFilterTest method testEvaluateCombined.
/**
* Tests evaluation of two identifiers combined by a OR logical operator.
*/
@Test
public void testEvaluateCombined() {
final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
ftb.addAttribute(String.class).setName("att").addRole(AttributeRole.IDENTIFIER_COMPONENT);
final DefaultFeatureType type = ftb.setName("Test").build();
final AbstractFeature f1 = type.newInstance();
f1.setPropertyValue("att", "123");
final AbstractFeature f2 = type.newInstance();
f2.setPropertyValue("att", "abc");
final AbstractFeature f3 = type.newInstance();
f3.setPropertyValue("att", "abc123");
final Filter<AbstractFeature> id = factory.or(factory.resourceId("abc"), factory.resourceId("123"));
assertTrue(id.test(f1));
assertTrue(id.test(f2));
assertFalse(id.test(f3));
}
use of org.apache.sis.feature.builder.FeatureTypeBuilder in project sis by apache.
the class ConcatenatedFeatureSetTest method lackOfInput.
/**
* Tests that no concatenated transform is created from less than 2 types.
*
* @throws DataStoreException if an error occurred while invoking the create method.
*/
@Test
public void lackOfInput() throws DataStoreException {
try {
final FeatureSet set = ConcatenatedFeatureSet.create();
fail("An empty concatenation has been created:\n" + set);
} catch (IllegalArgumentException e) {
// This is the expected exception.
}
final FeatureTypeBuilder builder = new FeatureTypeBuilder().setName("mock");
final DefaultFeatureType mockType = builder.build();
final FeatureSet fs1 = new MemoryFeatureSet(null, mockType, Collections.emptyList());
final FeatureSet set = ConcatenatedFeatureSet.create(fs1);
assertSame("A concatenation has been created from a single type.", fs1, set);
}
Aggregations