use of org.opengis.parameter.ParameterDescriptorGroup in project sis by apache.
the class CC_OperationParameterGroupTest method testMerge.
/**
* Tests the merge of unmarshalled descriptors with more complete descriptors.
* This operation is expected to create new descriptor instances as a result of the merges.
*
* @throws JAXBException if this method failed to create test data.
*/
@Test
@DependsOnMethod("testSubtitution")
public void testMerge() throws JAXBException {
final ParameterDescriptorGroup fromXML = unmarshal();
final ParameterDescriptor<?>[] fromValues = create(null);
final Map<GeneralParameterDescriptor, GeneralParameterDescriptor> replacements = new IdentityHashMap<>(4);
final GeneralParameterDescriptor[] merged = CC_OperationParameterGroup.merge(fromXML.descriptors(), fromValues.clone(), replacements);
assertNotSame(fromValues, merged);
/*
* "Longitude of natural origin" parameter should be the same.
*/
assertEquals("Number of parameters", 2, merged.length);
assertSame("Longitude of natural origin", fromValues[1], merged[1]);
/*
* "Latitude of natural origin" should be a new parameter, because we merged the remarks from the
* 'fromXML' descriptor with value class, unit and default value from the 'fromValue' descriptor.
*/
final GeneralParameterDescriptor incomplete = fromXML.descriptors().get(0);
final DefaultParameterDescriptor<?> fromValue = (DefaultParameterDescriptor<?>) fromValues[0];
final DefaultParameterDescriptor<?> complete = (DefaultParameterDescriptor<?>) merged[0];
assertNotSame("Latitude of natural origin", incomplete, complete);
assertNotSame("Latitude of natural origin", fromValue, complete);
assertSame("name", fromValue.getName(), complete.getName());
assertSame("remarks", incomplete.getRemarks(), complete.getRemarks());
assertEquals("valueClass", Double.class, complete.getValueClass());
assertSame("valueDomain", fromValue.getValueDomain(), complete.getValueDomain());
/*
* All references to 'fromValue' will need to be replaced by references to 'complete'.
*/
assertEquals("replacements", Collections.singletonMap(fromValue, complete), replacements);
}
use of org.opengis.parameter.ParameterDescriptorGroup in project sis by apache.
the class CC_OperationParameterGroupTest method testGroup.
/**
* Tests {@link CC_OperationMethod#group(Identifier, GeneralParameterDescriptor[])}.
*
* @throws JAXBException if this method failed to create test data.
*/
@Test
@DependsOnMethod("testMerge")
public void testGroup() throws JAXBException {
// From XML
ParameterDescriptorGroup group = unmarshal();
List<GeneralParameterDescriptor> descriptors = group.descriptors();
// Merge with the parameters defined in Mercator1SP class
group = CC_OperationMethod.group(group.getName(), descriptors.toArray(new GeneralParameterDescriptor[descriptors.size()]));
descriptors = group.descriptors();
assertSame("name", group.getName(), group.getName());
assertEquals("descriptors.size", 2, descriptors.size());
verifyMethodParameter(Mercator1SP.LATITUDE_OF_ORIGIN, REMARK, (ParameterDescriptor<?>) descriptors.get(0));
verifyMethodParameter(Mercator1SP.LONGITUDE_OF_ORIGIN, null, (ParameterDescriptor<?>) descriptors.get(1));
}
use of org.opengis.parameter.ParameterDescriptorGroup in project sis by apache.
the class AbstractParameterDescriptor method formatTo.
/**
* Formats this descriptor as a pseudo-<cite>Well Known Text</cite> element. The WKT specification
* does not define any representation of parameter descriptors. Apache SIS fallback on a list of
* {@linkplain DefaultParameterDescriptor#formatTo(Formatter) descriptors}.
* The text formatted by this method is {@linkplain Formatter#setInvalidWKT flagged as invalid WKT}.
*
* @param formatter the formatter where to format the inner content of this WKT element.
* @return {@code "Parameter"} or {@code "ParameterGroup"}.
*/
@Override
protected String formatTo(final Formatter formatter) {
super.formatTo(formatter);
formatter.setInvalidWKT(this, null);
if (this instanceof ParameterDescriptorGroup) {
for (GeneralParameterDescriptor parameter : ((ParameterDescriptorGroup) this).descriptors()) {
if (!(parameter instanceof FormattableObject)) {
if (parameter instanceof ParameterDescriptor<?>) {
parameter = new DefaultParameterDescriptor<>((ParameterDescriptor<?>) parameter);
} else if (parameter instanceof ParameterDescriptorGroup) {
parameter = new DefaultParameterDescriptorGroup((ParameterDescriptorGroup) parameter);
} else {
continue;
}
}
formatter.newLine();
formatter.append((FormattableObject) parameter);
}
return WKTKeywords.ParameterGroup;
} else if (this instanceof ParameterDescriptor<?>) {
final Object defaultValue = ((ParameterDescriptor<?>) this).getDefaultValue();
if (defaultValue != null) {
formatter.appendAny(defaultValue);
}
formatter.append(((ParameterDescriptor<?>) this).getUnit());
}
return WKTKeywords.Parameter;
}
use of org.opengis.parameter.ParameterDescriptorGroup in project sis by apache.
the class ParameterBuilder method createGroupWithSameParameters.
/**
* Creates a descriptor group with the same parameters than another group. This is a convenience constructor
* for operations that expect the same parameters than another operation, but perform a different process.
*
* <div class="note"><b>Example:</b>
* the various <cite>"Coordinate Frame Rotation"</cite> variants (EPSG codes 1032, 1038 and 9607)
* expect the same parameters than their <cite>"Position Vector transformation"</cite> counterpart
* (EPSG codes 1033, 1037 and 9606) but perform the rotation in the opposite direction.</div>
*
* @param parameters the existing group from which to copy the parameters.
* @return the parameter descriptor group.
*
* @since 0.7
*/
public ParameterDescriptorGroup createGroupWithSameParameters(final ParameterDescriptorGroup parameters) {
final ParameterDescriptorGroup group;
onCreate(false);
try {
group = new DefaultParameterDescriptorGroup(properties, parameters);
} finally {
onCreate(true);
}
return group;
}
use of org.opengis.parameter.ParameterDescriptorGroup in project sis by apache.
the class ParameterBuilder method createGroup.
/**
* Creates a descriptor group for the given cardinality and parameters.
*
* @param minimumOccurs the {@linkplain DefaultParameterDescriptorGroup#getMinimumOccurs() minimum}
* number of times that values for this parameter group are required.
* @param maximumOccurs the {@linkplain DefaultParameterDescriptorGroup#getMaximumOccurs() maximum}
* number of times that values for this parameter group are required.
* @param parameters the {@linkplain DefaultParameterDescriptorGroup#descriptors() parameter descriptors}
* for the group to create.
* @return the parameter descriptor group.
*/
public ParameterDescriptorGroup createGroup(final int minimumOccurs, final int maximumOccurs, final GeneralParameterDescriptor... parameters) {
final ParameterDescriptorGroup group;
onCreate(false);
try {
group = new DefaultParameterDescriptorGroup(properties, minimumOccurs, maximumOccurs, parameters);
} finally {
onCreate(true);
}
return group;
}
Aggregations