//# 0 errors, 76 messages
//#
/*
    //#validationcontext.java:1:1: class: net.sourceforge.pebble.web.validation.ValidationContext
    //#validationcontext.java:1:1: method: net.sourceforge.pebble.web.validation.ValidationContext.net.sourceforge.pebble.web.validation.ValidationContext__static_init
 * Copyright (c) 2003-2006, Simon Brown
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *   - Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *
 *   - Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in
 *     the documentation and/or other materials provided with the
 *     distribution.
 *
 *   - Neither the name of Pebble nor the names of its contributors may
 *     be used to endorse or promote products derived from this software
 *     without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
package net.sourceforge.pebble.web.validation;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * A context within which to perform validation and raise errors against.
 *
 * @author    Simon Brown
 */
public class ValidationContext {
    //#validationcontext.java:43: method: void net.sourceforge.pebble.web.validation.ValidationContext.net.sourceforge.pebble.web.validation.ValidationContext()
    //#input(void net.sourceforge.pebble.web.validation.ValidationContext()): this
    //#output(void net.sourceforge.pebble.web.validation.ValidationContext()): new ArrayList(ValidationContext#1) num objects
    //#output(void net.sourceforge.pebble.web.validation.ValidationContext()): this.errors
    //#new obj(void net.sourceforge.pebble.web.validation.ValidationContext()): new ArrayList(ValidationContext#1)
    //#post(void net.sourceforge.pebble.web.validation.ValidationContext()): this.errors == &new ArrayList(ValidationContext#1)
    //#post(void net.sourceforge.pebble.web.validation.ValidationContext()): new ArrayList(ValidationContext#1) num objects == 1

  /** the list of errors */
  private List errors = new ArrayList();
    //#validationcontext.java:46: end of method: void net.sourceforge.pebble.web.validation.ValidationContext.net.sourceforge.pebble.web.validation.ValidationContext()

  /**
   * Adds a new error to this context.
   *
   * @param message   the error message as a String
   */
  public void addError(String message) {
    addError(new ValidationError(message));
    //#validationcontext.java:54: method: void net.sourceforge.pebble.web.validation.ValidationContext.addError(String)
    //#input(void addError(String)): __Descendant_Table[net/sourceforge/pebble/web/validation/ValidationContext]
    //#input(void addError(String)): __Descendant_Table[others]
    //#input(void addError(String)): __Dispatch_Table.addError(Lnet/sourceforge/pebble/web/validation/ValidationError;)V
    //#input(void addError(String)): message
    //#input(void addError(String)): this
    //#input(void addError(String)): this.__Tag
    //#input(void addError(String)): this.errors
    //#pre[3] (void addError(String)): this.__Tag == net/sourceforge/pebble/web/validation/ValidationContext
    //#pre[4] (void addError(String)): this.errors != null
    //#unanalyzed(void addError(String)): Effects-of-calling:java.util.List:add
  }
    //#validationcontext.java:55: end of method: void net.sourceforge.pebble.web.validation.ValidationContext.addError(String)

  /**
   * Adds a new error to this context.
   *
   * @param error   a ValidationError instance
   */
  public void addError(ValidationError error) {
    errors.add(error);
    //#validationcontext.java:63: method: void net.sourceforge.pebble.web.validation.ValidationContext.addError(ValidationError)
    //#input(void addError(ValidationError)): error
    //#input(void addError(ValidationError)): this
    //#input(void addError(ValidationError)): this.errors
    //#pre[3] (void addError(ValidationError)): this.errors != null
  }
    //#validationcontext.java:64: end of method: void net.sourceforge.pebble.web.validation.ValidationContext.addError(ValidationError)

  /**
   * Determines whether this context has errors rasied against it.
   *
   * @return  true if this context has errors, false otherwise
   */
  public boolean hasErrors() {
    return !errors.isEmpty();
    //#validationcontext.java:72: method: bool net.sourceforge.pebble.web.validation.ValidationContext.hasErrors()
    //#input(bool hasErrors()): this
    //#input(bool hasErrors()): this.errors
    //#output(bool hasErrors()): return_value
    //#pre[2] (bool hasErrors()): this.errors != null
    //#post(bool hasErrors()): init'ed(return_value)
    //#validationcontext.java:72: end of method: bool net.sourceforge.pebble.web.validation.ValidationContext.hasErrors()
  }

  /**
   * Gets a list of all errors raised against this context.
   *
   * @return  a List of ValidationError instances
   */
  public List getErrors() {
    return Collections.unmodifiableList(errors);
    //#validationcontext.java:81: method: List net.sourceforge.pebble.web.validation.ValidationContext.getErrors()
    //#input(List getErrors()): this
    //#input(List getErrors()): this.errors
    //#output(List getErrors()): return_value
    //#pre[2] (List getErrors()): init'ed(this.errors)
    //#post(List getErrors()): init'ed(return_value)
    //#validationcontext.java:81: end of method: List net.sourceforge.pebble.web.validation.ValidationContext.getErrors()
  }

  /**
   * Gets the number of errors.
   *
   * @return  the number of errors as in int
   */
  public int getNumberOfErrors() {
    return errors.size();
    //#validationcontext.java:90: method: int net.sourceforge.pebble.web.validation.ValidationContext.getNumberOfErrors()
    //#input(int getNumberOfErrors()): this
    //#input(int getNumberOfErrors()): this.errors
    //#output(int getNumberOfErrors()): return_value
    //#pre[2] (int getNumberOfErrors()): this.errors != null
    //#post(int getNumberOfErrors()): init'ed(return_value)
    //#validationcontext.java:90: end of method: int net.sourceforge.pebble.web.validation.ValidationContext.getNumberOfErrors()
  }

  /**
   * Gets the specified ValidationError.
   *
   * @param index   the index of the error to get
   * @return  the ValidationError at the specified index
   */
  public ValidationError getError(int index) {
    return (ValidationError)errors.get(index);
    //#validationcontext.java:100: method: ValidationError net.sourceforge.pebble.web.validation.ValidationContext.getError(int)
    //#input(ValidationError getError(int)): index
    //#input(ValidationError getError(int)): net/sourceforge/pebble/web/validation/ValidationError.__Descendant_Table[net/sourceforge/pebble/web/validation/ValidationError]
    //#input(ValidationError getError(int)): net/sourceforge/pebble/web/validation/ValidationError.__Descendant_Table[others]
    //#input(ValidationError getError(int)): this
    //#input(ValidationError getError(int)): this.errors
    //#output(ValidationError getError(int)): return_value
    //#pre[3] (ValidationError getError(int)): this.errors != null
    //#presumption(ValidationError getError(int)): java.util.List:get(...).__Tag@100 == net/sourceforge/pebble/web/validation/ValidationError
    //#post(ValidationError getError(int)): init'ed(return_value)
    //#validationcontext.java:100: end of method: ValidationError net.sourceforge.pebble.web.validation.ValidationContext.getError(int)
  }

}    //#output(net.sourceforge.pebble.web.validation.ValidationContext__static_init): __Descendant_Table[net/sourceforge/pebble/web/validation/ValidationContext]
    //#output(net.sourceforge.pebble.web.validation.ValidationContext__static_init): __Dispatch_Table.addError(Ljava/lang/String;)V
    //#output(net.sourceforge.pebble.web.validation.ValidationContext__static_init): __Dispatch_Table.addError(Lnet/sourceforge/pebble/web/validation/ValidationError;)V
    //#output(net.sourceforge.pebble.web.validation.ValidationContext__static_init): __Dispatch_Table.getError(I)Lnet/sourceforge/pebble/web/validation/ValidationError;
    //#output(net.sourceforge.pebble.web.validation.ValidationContext__static_init): __Dispatch_Table.getErrors()Ljava/util/List;
    //#output(net.sourceforge.pebble.web.validation.ValidationContext__static_init): __Dispatch_Table.getNumberOfErrors()I
    //#output(net.sourceforge.pebble.web.validation.ValidationContext__static_init): __Dispatch_Table.hasErrors()Z
    //#post(net.sourceforge.pebble.web.validation.ValidationContext__static_init): __Descendant_Table[net/sourceforge/pebble/web/validation/ValidationContext] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.web.validation.ValidationContext__static_init): __Dispatch_Table.addError(Ljava/lang/String;)V == &addError
    //#post(net.sourceforge.pebble.web.validation.ValidationContext__static_init): __Dispatch_Table.addError(Lnet/sourceforge/pebble/web/validation/ValidationError;)V == &addError
    //#post(net.sourceforge.pebble.web.validation.ValidationContext__static_init): __Dispatch_Table.getError(I)Lnet/sourceforge/pebble/web/validation/ValidationError; == &getError
    //#post(net.sourceforge.pebble.web.validation.ValidationContext__static_init): __Dispatch_Table.getErrors()Ljava/util/List; == &getErrors
    //#post(net.sourceforge.pebble.web.validation.ValidationContext__static_init): __Dispatch_Table.getNumberOfErrors()I == &getNumberOfErrors
    //#post(net.sourceforge.pebble.web.validation.ValidationContext__static_init): __Dispatch_Table.hasErrors()Z == &hasErrors
    //#validationcontext.java:: end of method: net.sourceforge.pebble.web.validation.ValidationContext.net.sourceforge.pebble.web.validation.ValidationContext__static_init
    //#validationcontext.java:: end of class: net.sourceforge.pebble.web.validation.ValidationContext
