Coverage Report - org.jtheque.primary.utils.web.analyzers.generic.transform.LastFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
LastFactory
0 %
0/4
N/A
1
LastFactory$1
N/A
N/A
1
LastFactory$Last
0 %
0/6
N/A
1
 
 1  
 package org.jtheque.primary.utils.web.analyzers.generic.transform;
 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.jdom.Element;
 20  
 import org.jtheque.core.utils.file.XMLReader;
 21  
 import org.jtheque.primary.utils.web.analyzers.generic.Factory;
 22  
 
 23  
 /**
 24  
  * @author Baptiste Wicht
 25  
  */
 26  0
 final class LastFactory implements Factory<Transformer> {
 27  
         @Override
 28  
         public boolean canFactor(Element element, XMLReader reader){
 29  0
                 return "last".equals(element.getName());
 30  
         }
 31  
 
 32  
         @Override
 33  
         public Transformer factor(Element element, XMLReader reader){
 34  0
                 return new Last(Integer.parseInt(element.getText()));
 35  
         }
 36  
 
 37  
         /**
 38  
          * A Transformer who takes only the X last chars or the value.
 39  
          *
 40  
          * @author Baptiste Wicht
 41  
          */
 42  0
         private static final class Last implements Transformer {
 43  
                 private final int last;
 44  
 
 45  
                 /**
 46  
                  * Construct a new Last object.
 47  
                  *
 48  
                  * @param cut The number of chars to get.
 49  
                  */
 50  
                 private Last(int cut){
 51  0
                         super();
 52  
 
 53  0
                         last = cut;
 54  0
                 }
 55  
 
 56  
                 @Override
 57  
                 public String transform(String value){
 58  0
                         return value.substring(value.length() - last);
 59  
                 }
 60  
 
 61  
                 @Override
 62  
                 public String toString(){
 63  0
                         return "Last{" +
 64  
                                         "last=" + last +
 65  
                                         '}';
 66  
                 }
 67  
         }
 68  
 }