avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/validity AggregatedValidity.java
Date Mon, 17 Dec 2001 13:55:03 GMT
cziegeler    01/12/17 05:55:03

  Added:       src/scratchpad/org/apache/avalon/excalibur/source/validity
                        AggregatedValidity.java
  Log:
  Added Aggregated Validity
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/validity/AggregatedValidity.java
  
  Index: AggregatedValidity.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.excalibur.source.validity;
  
  import org.apache.avalon.excalibur.source.SourceValidity;
  
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  
  /**
   * A validation object using a List.
   *
   * @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/12/17 13:55:03 $
   */
  public final class AggregatedValidity
  implements SourceValidity {
  
      private List a;
  
      public AggregatedValidity() {
          this.a = new ArrayList();
      }
  
      public void add(SourceValidity validity) {
          this.a.add(validity);
      }
  
      public boolean isValid() {
          for(Iterator i = a.iterator(); i.hasNext();) {
              if(!((SourceValidity )i.next()).isValid())
                  return false;
          }
          return true;
      }
  
      public boolean isValid(SourceValidity validity) {
          if (validity instanceof AggregatedValidity) {
              List b = ((AggregatedValidity)validity).a;
              if(a.size() != b.size())
                  return false;
              for(Iterator i = a.iterator(), j = b.iterator(); i.hasNext();) {
                  final SourceValidity srcA = ( SourceValidity )i.next();
                  final SourceValidity srcB = ( SourceValidity )j.next();
                  if (!srcA.isValid() && !srcA.isValid(srcB))
                      return false;
              }
              return true;
          }
          return false;
      }
  
      public String toString() {
          StringBuffer b = new StringBuffer("SourceValidity ");
          for(Iterator i = a.iterator(); i.hasNext();) {
              b.append(i.next());
              if(i.hasNext()) b.append(':');
          }
          return b.toString();
      }
  }
  
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message