use of org.opengis.util.GenericName in project sis by apache.
the class ProvidersTest method ensureParameterUniqueness.
/**
* Ensures that every parameter instance is unique. Actually this test is not strong requirement.
* This is only for sharing existing resources by avoiding unnecessary objects duplication.
*
* @throws ReflectiveOperationException if the instantiation of a service provider failed.
*/
@Test
public void ensureParameterUniqueness() throws ReflectiveOperationException {
final Map<GeneralParameterDescriptor, String> groupNames = new IdentityHashMap<>();
final Map<GeneralParameterDescriptor, GeneralParameterDescriptor> parameters = new HashMap<>();
final Map<Object, Object> namesAndIdentifiers = new HashMap<>();
for (final Class<?> c : methods()) {
final OperationMethod method = (OperationMethod) c.newInstance();
final ParameterDescriptorGroup group = method.getParameters();
final String operationName = group.getName().getCode();
for (final GeneralParameterDescriptor param : group.descriptors()) {
assertFalse("Parameter declared twice in the same group.", operationName.equals(groupNames.put(param, operationName)));
/*
* Ensure uniqueness of the parameter descriptor as a whole.
*/
final Identifier name = param.getName();
Object existing = parameters.put(param, param);
if (existing != null && existing != param) {
fail("Parameter “" + name.getCode() + "” defined in “" + operationName + '”' + " was already defined in “" + groupNames.get(existing) + "”." + " The same instance could be shared.");
}
/*
* Ensure uniqueness of each name and identifier.
*/
existing = namesAndIdentifiers.put(name, name);
if (existing != null && existing != name) {
fail("The name of parameter “" + name.getCode() + "” defined in “" + operationName + '”' + " was already defined elsewhere. The same instance could be shared.");
}
for (final GenericName alias : param.getAlias()) {
existing = namesAndIdentifiers.put(alias, alias);
if (existing != null && existing != alias) {
fail("Alias “" + alias + "” of parameter “" + name.getCode() + "” defined in “" + operationName + '”' + " was already defined elsewhere. The same instance could be shared.");
}
}
for (final Identifier id : param.getIdentifiers()) {
existing = namesAndIdentifiers.put(id, id);
if (existing != null && existing != id) {
fail("Identifier “" + id + "” of parameter “" + name.getCode() + "” defined in “" + operationName + '”' + " was already defined elsewhere. The same instance could be shared.");
}
}
}
}
}
use of org.opengis.util.GenericName in project sis by apache.
the class IdentifiedObjectsTest method testIsHeuristicMatchForName.
/**
* Tests {@link IdentifiedObjects#isHeuristicMatchForName(IdentifiedObject, String)}.
*/
@Test
public void testIsHeuristicMatchForName() {
final NameFactory factory = DefaultFactories.forBuildin(NameFactory.class);
final GenericName name = factory.createGenericName(null, "myScope", "myName");
// Intentional trailing space.
IdentifiedObjectMock object = new IdentifiedObjectMock("myCode ", name);
// Test the code.
assertFalse(isHeuristicMatchForName(object, "other"));
assertTrue(isHeuristicMatchForName(object, "myCode"));
assertTrue(isHeuristicMatchForName(object, " my_code "));
assertFalse(isHeuristicMatchForName(object, "testmyCode"));
assertFalse(isHeuristicMatchForName(object, "other:myCode"));
assertFalse(isHeuristicMatchForName(object, "test"));
assertFalse(isHeuristicMatchForName(null, "myCode"));
// Test the alias.
assertTrue(isHeuristicMatchForName(object, "myName"));
assertTrue(isHeuristicMatchForName(object, " My_name "));
assertFalse(isHeuristicMatchForName(object, "myScope"));
assertFalse(isHeuristicMatchForName(object, "other:myName"));
assertFalse(isHeuristicMatchForName(object, "myScope:other"));
assertFalse(isHeuristicMatchForName(object, "other:myScope:myName"));
// Test non-letter and non-digits characters.
object = new IdentifiedObjectMock("Mercator (1SP)", name);
assertTrue(isHeuristicMatchForName(object, "Mercator (1SP)"));
assertTrue(isHeuristicMatchForName(object, "Mercator_1SP"));
assertFalse(isHeuristicMatchForName(object, "Mercator_2SP"));
// Test diacritical signs
object = new IdentifiedObjectMock("Réunion", name);
assertTrue(isHeuristicMatchForName(object, "Réunion"));
assertTrue(isHeuristicMatchForName(object, "Reunion"));
}
use of org.opengis.util.GenericName in project sis by apache.
the class ParameterBuilderTest method testMercatorProjection.
/**
* Tests the <cite>"Mercator (variant A)"</cite> example given in Javadoc.
*/
@Test
@DependsOnMethod("testCreate")
@SuppressWarnings("UnnecessaryBoxing")
public void testMercatorProjection() {
final ParameterBuilder builder = new ParameterBuilder();
builder.setCodeSpace(Citations.EPSG, "EPSG").setRequired(true);
final ParameterDescriptor<?>[] parameters = { builder.addName("Longitude of natural origin").addName(Citations.OGC, "central_meridian").addName(Citations.GEOTIFF, "NatOriginLong").setRemarks("Some remarks.").createBounded(-180, +180, 0, Units.DEGREE), builder.addName("Latitude of natural origin").createBounded(-80, +84, 0, Units.DEGREE), builder.addName("Scale factor at natural origin").createStrictlyPositive(1, Units.UNITY), builder.addName("False easting").create(0, Units.METRE), builder.addName("False northing").create(0, Units.METRE) };
// Tests random properties.
assertEquals("EPSG", parameters[1].getName().getCodeSpace());
assertEquals("False easting", parameters[3].getName().getCode());
assertEquals("Some remarks.", parameters[0].getRemarks().toString());
assertEquals(Double.valueOf(84), parameters[1].getMaximumValue());
assertEquals(Units.METRE, parameters[4].getUnit());
assertTrue(parameters[1].getAlias().isEmpty());
final GenericName alias = parameters[0].getAlias().iterator().next();
assertEquals("central_meridian", alias.tip().toString());
assertEquals("OGC", alias.head().toString());
assertEquals("OGC:central_meridian", alias.toString());
}
use of org.opengis.util.GenericName in project sis by apache.
the class TypesTest method testResources.
/**
* Verifies that all designations and definitions can be read from the resources.
*/
private static void testResources(final DefaultFeatureType type) {
for (final AbstractIdentifiedType p : type.getProperties(false)) {
final GenericName name = p.getName();
if (!AttributeConvention.contains(name)) {
final String label = name.toString();
assertNonEmpty(label, p.getDesignation());
assertNonEmpty(label, p.getDefinition());
}
}
}
use of org.opengis.util.GenericName in project sis by apache.
the class AbstractName method toFullyQualifiedName.
/**
* Returns a view of this name as a fully-qualified name. The {@linkplain #scope() scope}
* of a fully qualified name is {@linkplain DefaultNameSpace#isGlobal() global}.
* If the scope of this name is already global, then this method returns {@code this}.
*
* @return the fully-qualified name (never {@code null}).
*/
@Override
public synchronized GenericName toFullyQualifiedName() {
if (fullyQualified == null) {
final NameSpace scope = scope();
if (scope.isGlobal()) {
fullyQualified = this;
} else {
final GenericName prefix = scope.name();
assert prefix.scope().isGlobal() : prefix;
fullyQualified = new DefaultScopedName(prefix, this);
}
}
return fullyQualified;
}
Aggregations