javadoc polish; added errors() to BindingResults

This commit is contained in:
Keith Donald 2009-07-26 20:57:22 +00:00
parent e6b6743c44
commit 4ed3924e6f
6 changed files with 32 additions and 30 deletions

View File

@ -21,7 +21,6 @@ import java.util.Map;
* Bind to fields of a model object. * Bind to fields of a model object.
* @author Keith Donald * @author Keith Donald
* @since 3.0 * @since 3.0
* @see #bind(Map)
* @param <M> The type of model this binder binds to * @param <M> The type of model this binder binds to
*/ */
public interface Binder<M> { public interface Binder<M> {

View File

@ -21,7 +21,7 @@ import org.springframework.model.alert.Alert;
* The result of a bind operation. * The result of a bind operation.
* @author Keith Donald * @author Keith Donald
* @since 3.0 * @since 3.0
* @see Binder#bind(java.util.Map) * @see Binder#bind(java.util.Map, Object)
*/ */
public interface BindingResult { public interface BindingResult {

View File

@ -15,13 +15,13 @@
*/ */
package org.springframework.model.binder; package org.springframework.model.binder;
import java.util.List; import org.springframework.model.alert.Severity;
/** /**
* The results of a bind operation. * The results of a bind operation.
* @author Keith Donald * @author Keith Donald
* @since 3.0 * @since 3.0
* @see Binder#bind(UserValues) * @see Binder#bind(java.util.Map, Object)
*/ */
public interface BindingResults extends Iterable<BindingResult> { public interface BindingResults extends Iterable<BindingResult> {
@ -30,17 +30,22 @@ public interface BindingResults extends Iterable<BindingResult> {
*/ */
BindingResults successes(); BindingResults successes();
/**
* If there is at least one failed BindingResult.
* @see BindingResult#isFailure()
*/
boolean hasFailures();
/** /**
* The subset of BindingResults that failed. * The subset of BindingResults that failed.
*/ */
BindingResults failures(); BindingResults failures();
/**
* If there is at least one failure with a Severity equal to or greater than {@link Severity#ERROR}.
* @see BindingResults#failures()
*/
boolean hasErrors();
/**
* The subset of BindingResults that failed with {@link Severity#ERROR} or greater.
*/
BindingResults errors();
/** /**
* The total number of results. * The total number of results.
*/ */
@ -52,9 +57,4 @@ public interface BindingResults extends Iterable<BindingResult> {
*/ */
BindingResult get(int index); BindingResult get(int index);
/**
* The ordered list of properties for which a {@link BindingResult} was returned.
*/
List<String> properties();
} }

View File

@ -23,7 +23,7 @@ import java.util.Map;
* Indicates a client configuration error. * Indicates a client configuration error.
* @author Keith Donald * @author Keith Donald
* @since 3.0 * @since 3.0
* @see Binder#bind(java.util.Map) * @see Binder#bind(Map, Object)
*/ */
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class MissingFieldException extends RuntimeException { public class MissingFieldException extends RuntimeException {

View File

@ -31,8 +31,8 @@ import org.springframework.util.Assert;
* @since 3.0 * @since 3.0
* @see #setRequiredFields(String[]) * @see #setRequiredFields(String[])
* @see #setMessageSource(MessageSource) * @see #setMessageSource(MessageSource)
* @see #bind(Map, Object)
* @see #createBindTemplate() * @see #createBindTemplate()
* @see #bind(Map, Object)
*/ */
public abstract class AbstractBinder<M> implements Binder<M> { public abstract class AbstractBinder<M> implements Binder<M> {

View File

@ -19,6 +19,7 @@ import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import org.springframework.model.alert.Severity;
import org.springframework.model.binder.BindingResult; import org.springframework.model.binder.BindingResult;
import org.springframework.model.binder.BindingResults; import org.springframework.model.binder.BindingResults;
@ -56,10 +57,6 @@ class ArrayListBindingResults implements BindingResults {
return results; return results;
} }
public boolean hasFailures() {
return failures().size() > 0;
}
public BindingResults failures() { public BindingResults failures() {
ArrayListBindingResults results = new ArrayListBindingResults(); ArrayListBindingResults results = new ArrayListBindingResults();
for (BindingResult result : this) { for (BindingResult result : this) {
@ -70,16 +67,22 @@ class ArrayListBindingResults implements BindingResults {
return results; return results;
} }
public BindingResult get(int index) { public boolean hasErrors() {
return results.get(index); return errors().size() > 0;
}
public BindingResults errors() {
ArrayListBindingResults results = new ArrayListBindingResults();
for (BindingResult result : this) {
if (result.isFailure() && result.getAlert().getSeverity().compareTo(Severity.ERROR) >= 0) {
results.add(result);
}
}
return results;
} }
public List<String> properties() { public BindingResult get(int index) {
List<String> properties = new ArrayList<String>(results.size()); return results.get(index);
for (BindingResult result : this) {
properties.add(result.getFieldName());
}
return properties;
} }
public int size() { public int size() {