Coverage Report - org.jtheque.primary.utils.web.analyzers.generic.value.IteratorValue
 
Classes in this File Line Coverage Branch Coverage Complexity
IteratorValue
0 %
0/25
0 %
0/8
1.571
 
 1  
 package org.jtheque.primary.utils.web.analyzers.generic.value;
 2  
 
 3  
 /*
 4  
  * This file is part of JTheque.
 5  
  *            
 6  
  * JTheque is free software: you can redistribute it and/or modify
 7  
  * it under the terms of the GNU General Public License as published by
 8  
  * the Free Software Foundation, either version 3 of the License. 
 9  
  *
 10  
  * JTheque is distributed in the hope that it will be useful,
 11  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  
  * GNU General Public License for more details.
 14  
  *
 15  
  * You should have received a copy of the GNU General Public License
 16  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 17  
  */
 18  
 
 19  
 import org.jtheque.primary.utils.web.analyzers.generic.condition.Condition;
 20  
 import org.jtheque.primary.utils.web.analyzers.generic.operation.ScannerPossessor;
 21  
 import org.jtheque.primary.utils.web.analyzers.generic.operation.iterator.IteratorOperation;
 22  
 
 23  
 import java.util.ArrayList;
 24  
 import java.util.Collection;
 25  
 
 26  
 /**
 27  
  * A value getter who iterate on different lines.
 28  
  *
 29  
  * @author Baptiste Wicht
 30  
  */
 31  
 public final class IteratorValue implements ValueGetter, BuilderPossessor {
 32  
         private final StringBuilder builder;
 33  
         private final Collection<IteratorOperation> operationsBefore;
 34  
         private final Collection<IteratorOperation> operationsAfter;
 35  
         private final Collection<IteratorOperation> operations;
 36  
         private Condition condition;
 37  
 
 38  
         private final ScannerPossessor analyzer;
 39  
 
 40  
         /**
 41  
          * Construct a new IteratorValue.
 42  
          *
 43  
          * @param analyzer The film analyzer.
 44  
          */
 45  
         IteratorValue(ScannerPossessor analyzer){
 46  0
                 super();
 47  
 
 48  0
                 this.analyzer = analyzer;
 49  
 
 50  0
                 builder = new StringBuilder(100);
 51  0
                 operationsBefore = new ArrayList<IteratorOperation>(5);
 52  0
                 operationsAfter = new ArrayList<IteratorOperation>(5);
 53  0
                 operations = new ArrayList<IteratorOperation>(5);
 54  0
         }
 55  
 
 56  
         @Override
 57  
         public String getValue(String line){
 58  0
                 String current = line;
 59  
 
 60  0
                 for (IteratorOperation operation : operationsBefore){
 61  0
                         current = operation.perform(current, analyzer, this);
 62  
                 }
 63  
 
 64  0
                 while (condition.match(current)){
 65  0
                         for (IteratorOperation operation : operations){
 66  0
                                 current = operation.perform(current, analyzer, this);
 67  
                         }
 68  
                 }
 69  
 
 70  0
                 for (IteratorOperation operation : operationsAfter){
 71  0
                         current = operation.perform(current, analyzer, this);
 72  
                 }
 73  
 
 74  0
                 return builder.toString();
 75  
         }
 76  
 
 77  
         /**
 78  
          * Add an operation to do before the iteration.
 79  
          *
 80  
          * @param operation The operation to add.
 81  
          */
 82  
         public void addOperationsBefore(IteratorOperation operation){
 83  0
                 operationsBefore.add(operation);
 84  0
         }
 85  
 
 86  
         /**
 87  
          * Add an operation to do after the iteration.
 88  
          *
 89  
          * @param operation The operation to add.
 90  
          */
 91  
         public void addOperationsAfter(IteratorOperation operation){
 92  0
                 operationsAfter.add(operation);
 93  0
         }
 94  
 
 95  
         /**
 96  
          * Add an operation to do during the iteration.
 97  
          *
 98  
          * @param operation The operation to add.
 99  
          */
 100  
         public void addOperations(IteratorOperation operation){
 101  0
                 operations.add(operation);
 102  0
         }
 103  
 
 104  
         /**
 105  
          * Set the condition of the iteration.
 106  
          *
 107  
          * @param condition The condition to set.
 108  
          */
 109  
         public void setCondition(Condition condition){
 110  0
                 this.condition = condition;
 111  0
         }
 112  
 
 113  
         @Override
 114  
         public StringBuilder getBuilder(){
 115  0
                 return builder;
 116  
         }
 117  
 }