View Javadoc
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      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      {
31          this.begin = begin;
32          this.end = end;
33      }
34      
35      public int getNextStartIndex()
36      {
37          return nextStart;
38      }
39      
40      public void setNextStartIndex( int nextStart )
41      {
42          this.nextStart = nextStart;
43      }
44      
45      public void clearNextStart()
46      {
47          nextStart = -1;
48      }
49  
50      public static DelimiterSpecification parse( String delimiterSpec )
51      {
52          final String[] spec = new String[2];
53          
54          int splitIdx = delimiterSpec.indexOf( '*' );
55          if ( splitIdx < 0 )
56          {
57              spec[0] = delimiterSpec;
58              spec[1] = spec[0];
59          }
60          else if ( splitIdx == delimiterSpec.length() - 1 )
61          {
62              spec[0] = delimiterSpec.substring( 0, delimiterSpec.length() - 1 );
63              spec[1] = spec[0];
64          }
65          else
66          {
67              spec[0] = delimiterSpec.substring( 0, splitIdx );
68              spec[1] = delimiterSpec.substring( splitIdx + 1 );
69          }
70          
71          return new DelimiterSpecification( spec[0], spec[1] );
72      }
73  
74      public String getBegin()
75      {
76          return begin;
77      }
78  
79      public String getEnd()
80      {
81          return end;
82      }
83  
84      public int hashCode()
85      {
86          final int prime = 31;
87          int result = 1;
88          result = prime * result + ( ( begin == null ) ? 0 : begin.hashCode() );
89          result = prime * result + ( ( end == null ) ? 0 : end.hashCode() );
90          return result;
91      }
92  
93      public boolean equals( Object obj )
94      {
95          if ( this == obj )
96              return true;
97          if ( obj == null )
98              return false;
99          if ( getClass() != obj.getClass() )
100             return false;
101         DelimiterSpecification other = (DelimiterSpecification) obj;
102         if ( begin == null )
103         {
104             if ( other.begin != null )
105                 return false;
106         }
107         else if ( !begin.equals( other.begin ) )
108             return false;
109         if ( end == null )
110         {
111             if ( other.end != null )
112                 return false;
113         }
114         else if ( !end.equals( other.end ) )
115             return false;
116         return true;
117     }
118     
119     public String toString()
120     {
121         return "Interpolation delimiter [begin: '" + begin + "', end: '" + end + "']";
122     }
123     
124 }