All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.spun.util.servlets.ValidationTracker Maven / Gradle / Ivy

There is a newer version: 24.9.0
Show newest version
package com.spun.util.servlets;

import com.spun.util.StringUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;

public class ValidationTracker implements Serializable
{
  private static final long serialVersionUID = -5910435589128935375L;
  private ArrayList errors           = null;
  private ValidationError   validationError  = null;
  public ValidationTracker(ValidationError validationError)
  {
    this.validationError = validationError;
    errors = new ArrayList();
    errors.addAll(Arrays.asList(validationError.getAllErrorTitles()));
  }
  public boolean isValid(Enum assertion)
  {
    return isValid(assertion.toString());
  }
  public boolean isValid(String assertion)
  {
    errors.remove(assertion);
    return validationError.isValid(assertion);
  }
  public boolean isValidForIndex(String prefix, int index, String assertion)
  {
    return isValid(ValidationError.getPrefixForIndex(prefix, index) + "." + assertion);
  }
  public String[] getRemainingErrors()
  {
    return StringUtils.toArray(errors);
  }
  public boolean hasRemainingErrors()
  {
    boolean hasRemainingErrors = !errors.isEmpty();
    if (hasRemainingErrors)
    { throw new Error("HTML did not catch following errors: " + errors.toString()); }
    return hasRemainingErrors;
  }
  public ValidationError getValidationError()
  {
    return validationError;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy