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);
if (aliases.contains(pd.getName().getCode())) { final ParameterValue pv = (ParameterValue) pd.createValue(); pv.setValue(value);
/** * Forward the call to the {@linkplain MatrixParameterDescriptors matrix parameter descriptors} * specified at construction time. */ public Collection<GenericName> getAlias() { return descriptor.getAlias(); }
/** * Constructs a parameter group from the specified descriptor. All {@linkplain #values parameter * values} will be initialized to their default value. * * @param descriptor The descriptor for this group. */ public ParameterGroup(final ParameterDescriptorGroup descriptor) { super(descriptor); final List<GeneralParameterDescriptor> parameters = descriptor.descriptors(); values = new ArrayList<GeneralParameterValue>(parameters.size()); for (final GeneralParameterDescriptor element : parameters) { for (int count = element.getMinimumOccurs(); --count >= 0; ) { final GeneralParameterValue value = element.createValue(); ensureNonNull("createValue", value); values.add(value); } } }
/** * Remove the value at the specified index. * * @param type The descriptor of the value to remove. * @param index The index of the value to remove. */ private GeneralParameterValue remove(final GeneralParameterDescriptor type, final int index) { modCount++; int count = 0; final String name = type.getName().getCode(); for (final GeneralParameterValue value : values) { if (AbstractIdentifiedObject.nameMatches(value.getDescriptor(), name)) { count++; } } final int min = type.getMinimumOccurs(); if (count <= min) { final int max = type.getMaximumOccurs(); throw new InvalidParameterCardinalityException( Errors.format( ErrorKeys.ILLEGAL_OCCURS_FOR_PARAMETER_$4, name, count - 1, min, max), name); } final GeneralParameterValue value = values.remove(index); assert value != null && type.equals(value.getDescriptor()) : value; return value; } }
/** 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; } }
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(); 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) {
private static PropertyContainer createValueContainer(ParameterValueGroup valueGroup) { final PropertyContainer vc = new PropertyContainer(); List<GeneralParameterDescriptor> descriptors = valueGroup.getDescriptor().descriptors(); for (GeneralParameterDescriptor descriptor : descriptors) { final Class valueType; if (descriptor instanceof ParameterDescriptor) { ParameterDescriptor parameterDescriptor = (ParameterDescriptor) descriptor; valueType = parameterDescriptor.getValueClass(); validValues = parameterDescriptor.getValidValues(); minValue = parameterDescriptor.getMinimumValue(); maxValue = parameterDescriptor.getMaximumValue(); } else { 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())); Double max = (Double) maxValue; vd.setValueRange(new ValueRange(min, max)); if(parameterValue.getValue() == null) { parameterValue.setValue((min + max) / 2);
parameter -> parameter .getDescriptor() .getName() .equals( AbstractGridFormat.READ_GRIDGEOMETRY2D if (ggParameter.isPresent()) { ParameterValue value = (ParameterValue) ggParameter.get(); requestedGridGeometry = (GridGeometry2D) value.getValue(); ReferencedEnvelope requestedEnvelope = ReferencedEnvelope.reference(requestedGridGeometry.getEnvelope()); requestedGridGeometry.getGridToCRS(), requestedGridGeometry.getCoordinateReferenceSystem()); value.setValue(expandedGG); parameter -> !parameter .getDescriptor() .getName() .equals( AbstractGridFormat.BANDS
out.write(name); out.write(lineSeparator); Collection<GenericName> alias = group.getAlias(); if (alias != null) { boolean first = true; final Collection<?> elements = (values != null) ? values.values() : group.descriptors(); for (final Object element : elements) { final GeneralParameterValue generalValue; 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);
throws InvalidParameterNameException, InvalidParameterValueException { 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); 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);
/** * Convenience method returning the name of the specified descriptor. This method is used mostly * for output to be read by human, not for processing. Consequently, we may consider to returns * a localized name in a future version. */ static String getName(final GeneralParameterDescriptor descriptor) { return descriptor.getName().getCode(); }
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;
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);
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++;
@Override public GridCoverage2D read(GeneralParameterValue[] parameters) throws IllegalArgumentException, IOException { assertTrue( Arrays.stream(parameters) .anyMatch( p -> "Bands".equals(p.getDescriptor().getName().toString()) && Arrays.equals( expectedBands, (int[]) ((ParameterValue) p) .getValue()))); // Create a solid color single band coverage BufferedImage bi = new BufferedImage(100, 100, BufferedImage.TYPE_BYTE_GRAY); Graphics2D graphics = bi.createGraphics(); graphics.setColor(Color.WHITE); graphics.fillRect(0, 0, bi.getWidth(), bi.getHeight()); graphics.dispose(); GridCoverage2D coverage = CoverageFactoryFinder.getGridCoverageFactory(null) .create("test", bi, getOriginalEnvelope()); return coverage; } }
if (parameters != null) { for (GeneralParameterValue param : parameters) { final ReferenceIdentifier name = param.getDescriptor().getName(); if (name.equals(AbstractGridFormat.READ_GRIDGEOMETRY2D.getName())) { final GridGeometry2D gg = (GridGeometry2D) ((ParameterValue) param).getValue(); requestedEnvelope = gg.getEnvelope(); } else if (name.equals(AbstractGridFormat.BACKGROUND_COLOR.getName())) { backgroundColor = (Color) ((ParameterValue) param).getValue();
/** * 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); }
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()));
/** * Tests {@code DefaultParameterValueGroup.values().set(…)}. */ @Test @DependsOnMethod("testValuesGet") public void testValuesSet() { final DefaultParameterValueGroup group = new DefaultParameterValueGroup(descriptor); final List<GeneralParameterValue> values = group.values(); assertEquals("Initial size", 2, values.size()); final ParameterValue<?> p0 = (ParameterValue<?>) descriptor.descriptors().get(0).createValue(); final ParameterValue<?> p1 = (ParameterValue<?>) descriptor.descriptors().get(1).createValue(); p0.setValue(4); p1.setValue(5); assertEquals("Mandatory 1", values.set(0, p0).getDescriptor().getName().toString()); assertEquals("Mandatory 2", values.set(1, p1).getDescriptor().getName().toString()); try { values.set(2, p1); fail("Index 2 shall be out of bounds."); } catch (IndexOutOfBoundsException e) { assertNotNull(e.getMessage()); } assertEquals("size", 2, values.size()); // Size should be unchanged. assertEquals(4, ((ParameterValue<?>) values.get(0)).intValue()); assertEquals(5, ((ParameterValue<?>) values.get(1)).intValue()); }