/** * Constructs a parameter group from the specified descriptor and list of parameters. * * @param descriptor The descriptor for this group. * @param values The list of parameter values. * @throws IllegalStateException if the number of {@linkplain ParameterValue parameter} * occurences doesn't matches the number declared in the {@linkplain * ParameterDescriptorGroup descriptor}. */ public ParameterGroup( final ParameterDescriptorGroup descriptor, final GeneralParameterValue[] values) { super(descriptor); ensureNonNull("values", values); this.values = new ArrayList<GeneralParameterValue>(values.length); for (int i = 0; i < values.length; i++) { this.values.add(values[i]); } final List<GeneralParameterDescriptor> parameters = descriptor.descriptors(); final Map<GeneralParameterDescriptor, int[]> occurences = new LinkedHashMap<GeneralParameterDescriptor, int[]>( Math.round(parameters.size() / 0.75f) + 1, 0.75f); for (final GeneralParameterDescriptor param : parameters) { ensureNonNull("parameters", param); occurences.put(param, new int[1]); // The value 'int[1]' will be used by 'ensureValidOccurs' } ensureValidOccurs(values, occurences); }
/** * Work around for RFE #4093999 in Sun's bug database ("Relax constraint on placement of * this()/super() call in constructors"). * * @throws IllegalStateException if the number of {@linkplain ParameterValue parameter} * occurences doesn't matches the number declared in the {@linkplain * ParameterDescriptorGroup descriptor}. */ private static ParameterDescriptorGroup createDescriptor( final Map<String, ?> properties, final GeneralParameterValue[] values) { ensureNonNull("values", values); final Map<GeneralParameterDescriptor, int[]> occurences = new LinkedHashMap<GeneralParameterDescriptor, int[]>( Math.round(values.length / 0.75f) + 1, 0.75f); for (int i = 0; i < values.length; i++) { ensureNonNull("values", values, i); occurences.put(values[i].getDescriptor(), new int[1]); // The value 'int[1]' will be used by 'ensureValidOccurs' } ensureValidOccurs(values, occurences); final Set<GeneralParameterDescriptor> descriptors = occurences.keySet(); return new DefaultParameterDescriptorGroup( properties, descriptors.toArray(new GeneralParameterDescriptor[descriptors.size()])); }