- final String name = createSetterName(aName);
- List<Pair<Method, ParameterValues>> setters = new ArrayList<Pair<Method, ParameterValues>>();
- CollectionFilter.filter(_setters, setters,
- new Condition<Pair<Method, ParameterValues>>() {
+ for (Method method : setters.keySet()) {
+ if (method.getName().equals(aName)) {
+ setters.remove(method);
+ return this;
+ }
+ }
+ throw new IllegalArgumentException(
+ "No method configured by the name of '" + aName + "'");
+ }
+
+ /**
+ * Removes the method from the set of methods.
+ * @param aMethod Method to remove.
+ * @return
+ */
+ public SetterConfiguration remove(Method aMethod) {
+ if ( !aMethod.getDeclaringClass().isAssignableFrom(_class) ) {
+ throw new RuntimeException("Method " + aMethod + " not found in class " + _class + " or its superclasses");
+ }
+ for (Method method : setters.keySet()) {
+ if (method.equals(aMethod)) {
+ setters.remove(method);
+ return this;
+ }
+ }
+ throw new IllegalArgumentException(
+ "Method '" + aMethod + "' was not configured. ");
+ }
+
+ /**
+ * Adds a given setter name to the setters.
+ *
+ * @param aName Name of a setter method.
+ * @return Reference to the current object to allow call chaining.
+ */
+ public SetterConfiguration add(final String aName) {
+ int oldlen = setters.size();
+ List<Method> methods = new ArrayList<Method>();
+ CollectionFilter.filter(getAllSetters(_class, publicOnly), methods,
+ new Condition<Method>() {