/** * Copies all parameter values from {@code source} to {@code target}. A typical usage of this * method is for transfering values from an arbitrary implementation to some specific * implementation (e.g. a parameter group implementation backed by a {@link * java.awt.image.renderable.ParameterBlock} for image processing operations). * * @param source The parameters to copy. * @param target Where to copy the source parameters. * @since 2.2 */ public static void copy(final ParameterValueGroup source, final ParameterValueGroup target) { for (final GeneralParameterValue param : source.values()) { final String name = param.getDescriptor().getName().getCode(); if (param instanceof ParameterValueGroup) { copy((ParameterValueGroup) param, target.addGroup(name)); } else { target.parameter(name).setValue(((ParameterValue) param).getValue()); } } }
/** * Returns a deep copy of this group of parameter values. Included parameter values and * subgroups are cloned recursively. * * @return A copy of this group of parameter values. */ @Override public ParameterGroup clone() { final ParameterGroup copy = (ParameterGroup) super.clone(); copy.values = (ArrayList<GeneralParameterValue>) copy.values.clone(); for (int i = copy.values.size(); --i >= 0; ) { // TODO: remove cast with J2SE 1.5 copy.values.set(i, copy.values.get(i).clone()); } copy.asList = null; return copy; } }
if (oldParameterGroup instanceof ParameterValueGroup) { ParameterValueGroup oldParameters = (ParameterValueGroup) oldParameterGroup; List<GeneralParameterDescriptor> generalParameterDescriptors = newParameters.getDescriptor().descriptors(); List<GeneralParameterValue> oldValues = oldParameters.values(); for (GeneralParameterDescriptor newDescriptor : generalParameterDescriptors) { String parameterName = newDescriptor.getName().getCode(); for (GeneralParameterValue oldParameterValue : oldValues) { if (AbstractIdentifiedObject.nameMatches(oldParameterValue.getDescriptor(), newDescriptor)) { Object old = ((ParameterValue)oldParameterValue).getValue(); newParameters.parameter(parameterName).setValue(old); Ellipsoid ellipsoid = model.datum.getEllipsoid(); ParameterValue<?> semiMajorParam = newParameters.parameter(SEMI_MAJOR_PARAM_NAME); if (semiMajorParam.getValue() == null) { semiMajorParam.setValue(ellipsoid.getSemiMajorAxis());
final ParameterValue numRowParam = parameters.parameter(numRow.getName().toString()); final ParameterValue numColParam = parameters.parameter(numCol.getName().toString()); final int numRow = numRowParam.intValue(); final int numCol = numColParam.intValue(); final Matrix matrix = MatrixFactory.create(numRow, numCol); final List<GeneralParameterValue> params = parameters.values(); if (params != null) { for (final GeneralParameterValue param : params) { final String name = param.getDescriptor().getName().toString(); if (name.regionMatches(true, 0, prefix, 0, prefix.length())) { final int split = name.indexOf(separator, prefix.length()); Integer.parseInt(name.substring(prefix.length(), split)); final int col = Integer.parseInt(name.substring(split + 1)); matrix.setElement(row, col, ((ParameterValue) param).doubleValue()); continue; } catch (NumberFormatException exception) {
/** * Adds into the keySet any read parameter key that's missing (due to reader growing new * parameters over time/releases */ private void addMissingParameters(TreeSet<String> keySet, CoverageInfo coverage) { AbstractGridFormat format = coverage.getStore().getFormat(); ParameterValueGroup readParameters = format.getReadParameters(); List<GeneralParameterValue> parameterValues = readParameters.values(); List<String> paramNames = parameterValues .stream() .map(p -> p.getDescriptor()) .filter(p -> p instanceof DefaultParameterDescriptor) .map(p -> p.getName().getCode()) .collect(Collectors.toList()); keySet.addAll(paramNames); }
if (param.getDescriptor().equals(lparam.getDescriptor())) { it.remove(); break; ParameterValueGroup readParameters = format.getReadParameters(); List<GeneralParameterDescriptor> descriptors = readParameters.getDescriptor().descriptors(); String pdCode = pv.getDescriptor().getName().getCode(); if ("FILTER".equals(pdCode) || "Filter".equals(pdCode)) { replacedOriginalFilter = true; ParameterValue pvalue = (ParameterValue) pv; Filter originalFilter = (Filter) pvalue.getValue(); if (originalFilter == null || Filter.INCLUDE.equals(originalFilter)) { pvalue.setValue(readFilter); } else { Filter combined = Predicates.and(originalFilter, readFilter); pvalue.setValue(combined); JTS.toGeometry((Envelope) new ReferencedEnvelope(grid.getEnvelope2D())); if (coverageBounds.intersects(rasterFilter)) { final ParameterValueGroup param = cropParams.clone(); param.parameter("source").setValue(grid); param.parameter("ROI").setValue(rasterFilter); grid = (GridCoverage2D) coverageCropFactory.doOperation(param, null);
/** Replace or add the provided parameter in the read parameters */ public static <T> GeneralParameterValue[] replaceParameter( GeneralParameterValue[] readParameters, Object value, ParameterDescriptor<T> pd) { // scan all the params looking for the one we want to add for (GeneralParameterValue gpv : readParameters) { // in case of match of any alias add a param value to the lot if (gpv.getDescriptor().getName().equals(pd.getName())) { ((ParameterValue) gpv).setValue(value); // leave return readParameters; } } // add it to the array // add to the list GeneralParameterValue[] readParametersClone = new GeneralParameterValue[readParameters.length + 1]; System.arraycopy(readParameters, 0, readParametersClone, 0, readParameters.length); final ParameterValue<T> pv = pd.createValue(); pv.setValue(value); readParametersClone[readParameters.length] = pv; return readParametersClone; } }
for (final GeneralParameterValue value : values.values()) { final String name = value.getDescriptor().getName().getCode(); if (value instanceof ParameterValueGroup) { descriptor = copy.getDescriptor().descriptor(name); if (descriptor instanceof ParameterDescriptorGroup) { final ParameterValueGroup groups = (ParameterValueGroup) descriptor.createValue(); copy((ParameterValueGroup) value, groups); values.groups(name).add(groups); continue; } else { throw exception; final Object v = source.getValue(); final Unit<?> unit = source.getUnit(); if (unit == null) { target.setValue(v); } else if (v instanceof Number) { target.setValue(((Number) v).doubleValue(), unit);
parameter -> parameter .getDescriptor() .getName() .equals( AbstractGridFormat.READ_GRIDGEOMETRY2D requestedGridGeometry.getGridToCRS(), requestedGridGeometry.getCoordinateReferenceSystem()); value.setValue(expandedGG); for (int i = 0; i < parameters.length; i++) { final ParameterValue param = (ParameterValue) parameters[i]; if (AbstractGridFormat.BANDS.getName().equals(param.getDescriptor().getName())) { parameter -> !parameter .getDescriptor() .getName() .equals( AbstractGridFormat.BANDS param.parameter("sources").setValue(coverages); localHints.put( JAI.KEY_COLOR_MODEL_FACTORY,
return; final ParameterDescriptorGroup descriptors = object.getDescriptor(); mandatory("ParameterValueGroup: must have a descriptor.", descriptors); validate(descriptors); final List<GeneralParameterValue> values = object.values(); mandatory("ParameterValueGroup: values() should not return null.", values); if (values == null) { assertNotNull("ParameterValueGroup: values() can not contain null element.", value); dispatch(value); final GeneralParameterDescriptor descriptor = value.getDescriptor(); mandatory("GeneralParameterValue: expected a descriptor.", descriptor); if (descriptor == null) { continue; final String name = descriptor.getName().getCode(); mandatory("GeneralParameterDescriptor: expected a name.", name); if (name == null) { final ParameterValue<?> byName = object.parameter(name); mandatory("ParameterValueGroup: parameter(String) should returns a value.", byName); if (byName != null) {
final Collection<?> elements = (values != null) ? values.values() : group.descriptors(); final Map<GeneralParameterDescriptor, ParameterTableRow> descriptorValues = new LinkedHashMap<>(hashMapCapacity(elements.size())); if (values != null) { parameter = (GeneralParameterValue) element; descriptor = parameter.getDescriptor(); } else { parameter = null; final Class<?> valueClass = descriptor.getValueClass(); if (valueClass != null) { // Should never be null, but let be safe. table.append(getFormat(Class.class).format(valueClass, buffer, dummyFP).toString()); if (element instanceof ParameterValueGroup) { value = (ParameterValueGroup) element; descriptor = value.getDescriptor(); } else { value = null; format(name + '/' + descriptor.getName().getCode(), descriptor, value, out);
public boolean add(final GeneralParameterValue parameter) { modCount++; final GeneralParameterDescriptor type = parameter.getDescriptor(); final List<GeneralParameterDescriptor> descriptors = descriptor.descriptors(); final String name = type.getName().getCode(); if (!descriptors.contains(type)) { value = ((ParameterValue) parameter).getValue(); } else { value = "(group)"; Errors.format(ErrorKeys.ILLEGAL_ARGUMENT_$2, name, value), name); final int max = type.getMaximumOccurs(); if (max == 1) { final GeneralParameterDescriptor oldDescriptor = oldValue.getDescriptor(); if (type.equals(oldDescriptor)) { assert AbstractIdentifiedObject.nameMatches(oldDescriptor, name) : parameter; if (AbstractIdentifiedObject.nameMatches(value.getDescriptor(), name)) { count++;
String name = getName(param, group.getDescriptor().getName().getAuthority()); if (name == null) { name = param.getName().getCode(); if (param.getMinimumOccurs() != 0) { return Parameters.cast(group.parameter(name), param.getValueClass()); search = group.getDescriptor().descriptor(name); if (search instanceof ParameterDescriptor) { for (final GeneralParameterValue candidate : group.values()) { if (search.equals(candidate.getDescriptor())) { return Parameters.cast((ParameterValue) candidate, param.getValueClass());
final Collection<?> elements = (values != null) ? values.values() : group.descriptors(); for (final Object element : elements) { final GeneralParameterValue generalValue; if (values != null) { generalValue = (GeneralParameterValue) element; generalDescriptor = generalValue.getDescriptor(); } else { generalValue = null; final Identifier identifier = generalDescriptor.getName(); table.write(identifier.getCode()); alias = generalDescriptor.getAlias(); if (alias != null) { for (final GenericName a : alias) { value = descriptor.getMaximumValue(); if (value != null) { table.write(formatValue(value)); value = ((ParameterValue) generalValue).getValue(); format(name + '/' + descriptor.getName().getCode(), descriptor, value);
for (final GeneralParameterValue value : values.values()) { if (name.equals(value.getDescriptor().getName().getCode())) { if (--n < 0) { return value; final GeneralParameterValue value = values.getDescriptor().descriptor(name).createValue(); values.values().add(value); return value; } else {
/** * Tests creation of an {@link UnmodifiableParameterValueGroup} and verify the values. */ @Test public void testCreate() { ParameterValueGroup group = DefaultParameterDescriptorGroupTest.M1_M1_O1_O2.createValue(); group.parameter("Mandatory 1").setValue(5); group.parameter("Optional 3") .setValue(8); group = UnmodifiableParameterValueGroup.create(group); assertEquals("values.size()", 3, group.values().size()); assertEquals("values[0].name", "Mandatory 1", group.values().get(0).getDescriptor().getName().toString()); assertEquals("values[1].name", "Mandatory 2", group.values().get(1).getDescriptor().getName().toString()); assertEquals("values[2].name", "Optional 3", group.values().get(2).getDescriptor().getName().toString()); assertEquals("values[0].value", 5, group.parameter("Mandatory 1").getValue()); assertEquals("values[1].value", 10, group.parameter("Mandatory 2").getValue()); assertEquals("values[2].value", 8, group.parameter("Optional 3") .getValue()); try { group.groups("dummy"); fail("Shall not return non-existent groups."); } catch (ParameterNotFoundException e) { assertTrue(e.getMessage().contains("Test group")); assertTrue(e.getMessage().contains("dummy")); } }
private static PropertyContainer createValueContainer(ParameterValueGroup valueGroup) { final PropertyContainer vc = new PropertyContainer(); final List<GeneralParameterValue> values = valueGroup.values(); for (GeneralParameterValue value : values) { final GeneralParameterDescriptor descriptor = value.getDescriptor(); final Class valueType; Set validValues = null; if (descriptor instanceof ParameterDescriptor) { ParameterDescriptor parameterDescriptor = (ParameterDescriptor) descriptor; valueType = parameterDescriptor.getValueClass(); validValues = parameterDescriptor.getValidValues(); } else { valueType = Double.TYPE; final String paramName = descriptor.getName().getCode(); final PropertyDescriptor vd = new PropertyDescriptor(paramName, valueType); final ParameterValue<?> parameterValue = valueGroup.parameter(paramName); if (parameterValue.getUnit() != null) { vd.setUnit(String.valueOf(parameterValue.getUnit()));
parameters.parameter("central_meridian").doubleValue()); metadata.addGeoDoubleParam( GeoTiffPCSCodes.ProjNatOriginLatGeoKey, parameters.parameter("latitude_of_origin").doubleValue()); metadata.addGeoDoubleParam( GeoTiffPCSCodes.ProjScaleAtNatOriginGeoKey, parameters.parameter("scale_factor").doubleValue()); metadata.addGeoDoubleParam( GeoTiffPCSCodes.ProjFalseEastingGeoKey, ParameterValue<?> paramValue = (ParameterValue<?>) value; if (AbstractIdentifiedObject.nameMatches( value.getDescriptor(), "latitude_of_origin")) { value.getDescriptor(), "central_meridian")) { metadata.addGeoDoubleParam( value.getDescriptor(), "scale_factor")) { metadata.addGeoDoubleParam( value.getDescriptor(), "standard_parallel_1")) { value.getDescriptor(), "false_easting")) { value.getDescriptor(), "false_northing")) { metadata.addGeoDoubleParam( GeoTiffPCSCodes.ProjFalseNorthingGeoKey,
readParametersDescriptor.getDescriptor().descriptors()); Set<ParameterDescriptor<List>> dynamicParameters = reader.getDynamicParameters(); parameterDescriptors.addAll(dynamicParameters); GeneralParameterDescriptor pd = param.getDescriptor(); if (pd.getName().getCode().equalsIgnoreCase("FILTER")) { final ParameterValue pv = (ParameterValue) pd.createValue(); pv.setValue(layerFilter); readParameters[i] = pv; GeneralParameterDescriptor pd = param.getDescriptor(); if (pd.getName().getCode().equalsIgnoreCase("SORTING")) { final ParameterValue pv = (ParameterValue) pd.createValue(); if (pd instanceof ParameterDescriptor && String.class.equals(((ParameterDescriptor) pd).getValueClass())) { .charAt(0)) .collect(Collectors.joining(",")); pv.setValue(sortBySpec); } else { pv.setValue(sortBy);
final GeneralParameterDescriptor replacement = replacements.get(p.getDescriptor()); if (replacement != null) { if (p instanceof ParameterValue<?>) { final ParameterValue<?> source = (ParameterValue<?>) p; final ParameterValue<?> target = new DefaultParameterValue<>((ParameterDescriptor<?>) replacement); final Object value = source.getValue(); final Unit<?> unit = source.getUnit(); if (unit == null) { target.setValue(value); } else if (value instanceof double[]) { target.setValue((double[]) value, unit); final ParameterValueGroup source = (ParameterValueGroup) p; final ParameterValueGroup target = new DefaultParameterValueGroup((ParameterDescriptorGroup) replacement); final Collection<GeneralParameterValue> values = source.values(); store(values.toArray(new GeneralParameterValue[values.size()]), target.values(), replacements); p = target;