Coverage Report - org.codehaus.plexus.interpolation.multi.DelimiterSpecification
 
Classes in this File Line Coverage Branch Coverage Complexity
DelimiterSpecification
74 %
35/47
46 %
12/26
3
 
 1  
 package org.codehaus.plexus.interpolation.multi;
 2  
 
 3  
 /*
 4  
  * Copyright 2001-2009 Codehaus Foundation.
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License");
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  *      http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 public final class DelimiterSpecification
 20  
 {
 21  1
     public static final DelimiterSpecification DEFAULT_SPEC = DelimiterSpecification.parse( "${*}" );
 22  
     
 23  
     private String begin;
 24  
     
 25  
     private String end;
 26  
 
 27  
     private int nextStart;
 28  
     
 29  
     public DelimiterSpecification( String begin, String end )
 30  15
     {
 31  15
         this.begin = begin;
 32  15
         this.end = end;
 33  15
     }
 34  
     
 35  
     public int getNextStartIndex()
 36  
     {
 37  24
         return nextStart;
 38  
     }
 39  
     
 40  
     public void setNextStartIndex( int nextStart )
 41  
     {
 42  24
         this.nextStart = nextStart;
 43  24
     }
 44  
     
 45  
     public void clearNextStart()
 46  
     {
 47  128
         nextStart = -1;
 48  128
     }
 49  
 
 50  
     public static DelimiterSpecification parse( String delimiterSpec )
 51  
     {
 52  15
         final String[] spec = new String[2];
 53  
         
 54  15
         int splitIdx = delimiterSpec.indexOf( '*' );
 55  15
         if ( splitIdx < 0 )
 56  
         {
 57  2
             spec[0] = delimiterSpec;
 58  2
             spec[1] = spec[0];
 59  
         }
 60  13
         else if ( splitIdx == delimiterSpec.length() - 1 )
 61  
         {
 62  0
             spec[0] = delimiterSpec.substring( 0, delimiterSpec.length() - 1 );
 63  0
             spec[1] = spec[0];
 64  
         }
 65  
         else
 66  
         {
 67  13
             spec[0] = delimiterSpec.substring( 0, splitIdx );
 68  13
             spec[1] = delimiterSpec.substring( splitIdx + 1 );
 69  
         }
 70  
         
 71  15
         return new DelimiterSpecification( spec[0], spec[1] );
 72  
     }
 73  
 
 74  
     public String getBegin()
 75  
     {
 76  375
         return begin;
 77  
     }
 78  
 
 79  
     public String getEnd()
 80  
     {
 81  49
         return end;
 82  
     }
 83  
 
 84  
     public int hashCode()
 85  
     {
 86  34
         final int prime = 31;
 87  34
         int result = 1;
 88  34
         result = prime * result + ( ( begin == null ) ? 0 : begin.hashCode() );
 89  34
         result = prime * result + ( ( end == null ) ? 0 : end.hashCode() );
 90  34
         return result;
 91  
     }
 92  
 
 93  
     public boolean equals( Object obj )
 94  
     {
 95  5
         if ( this == obj )
 96  0
             return true;
 97  5
         if ( obj == null )
 98  0
             return false;
 99  5
         if ( getClass() != obj.getClass() )
 100  0
             return false;
 101  5
         DelimiterSpecification other = (DelimiterSpecification) obj;
 102  5
         if ( begin == null )
 103  
         {
 104  0
             if ( other.begin != null )
 105  0
                 return false;
 106  
         }
 107  5
         else if ( !begin.equals( other.begin ) )
 108  0
             return false;
 109  5
         if ( end == null )
 110  
         {
 111  0
             if ( other.end != null )
 112  0
                 return false;
 113  
         }
 114  5
         else if ( !end.equals( other.end ) )
 115  0
             return false;
 116  5
         return true;
 117  
     }
 118  
     
 119  
     public String toString()
 120  
     {
 121  0
         return "Interpolation delimiter [begin: '" + begin + "', end: '" + end + "']";
 122  
     }
 123  
     
 124  
 }