Coverage Report - org.apache.commons.functor.core.composite.DoWhileProcedure
 
Classes in this File Line Coverage Branch Coverage Complexity
DoWhileProcedure
100%
6/6
100%
2/2
1.333
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.commons.functor.core.composite;
 18  
 
 19  
 import org.apache.commons.functor.Predicate;
 20  
 import org.apache.commons.functor.Procedure;
 21  
 
 22  
 
 23  
 /**
 24  
  * A {@link Procedure} implementation of a while loop. Given a {@link Predicate}
 25  
  * <i>c</i> and an {@link Procedure} <i>p</i>, {@link #run runs}
 26  
  * <code>do { p.run(); } while(c.test())</code>.
 27  
  * <p>
 28  
  * Note that although this class implements
 29  
  * {@link java.io.Serializable}, a given instance will
 30  
  * only be truly <code>Serializable</code> if all the
 31  
  * underlying functors are.  Attempts to serialize
 32  
  * an instance whose delegates are not all
 33  
  * <code>Serializable</code> will result in an exception.
 34  
  * </p>
 35  
  * @version $Revision: 1171154 $ $Date: 2011-09-15 17:58:38 +0200 (Thu, 15 Sep 2011) $
 36  
  * @author Herve Quiroz
 37  
  * @author Rodney Waldhoff
 38  
  */
 39  
 public class DoWhileProcedure extends AbstractLoopProcedure {
 40  
     /**
 41  
      * serialVersionUID declaration.
 42  
      */
 43  
     private static final long serialVersionUID = -6064417600588553892L;
 44  
 
 45  
     /**
 46  
      * Create a new DoWhileProcedure.
 47  
      * @param action to do
 48  
      * @param condition while true
 49  
      */
 50  
     public DoWhileProcedure(Procedure action, Predicate condition) {
 51  14
         super(condition, action);
 52  14
     }
 53  
 
 54  
     /**
 55  
      * {@inheritDoc}
 56  
      */
 57  
     public final void run() {
 58  
         do {
 59  16
             getAction().run();
 60  16
         } while (getCondition().test());
 61  6
     }
 62  
 
 63  
     /**
 64  
      * {@inheritDoc}
 65  
      */
 66  
     public String toString() {
 67  6
         return "DoWhileProcedure<do(" + getAction() + ") while(" + getCondition() + ")>";
 68  
     }
 69  
 }