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      public static final DelimiterSpecification DEFAULT_SPEC = DelimiterSpecification.parse("${*}");
21  
22      private String begin;
23  
24      private String end;
25  
26      private int nextStart;
27  
28      public DelimiterSpecification(String begin, String end) {
29          this.begin = begin;
30          this.end = end;
31      }
32  
33      public int getNextStartIndex() {
34          return nextStart;
35      }
36  
37      public void setNextStartIndex(int nextStart) {
38          this.nextStart = nextStart;
39      }
40  
41      public void clearNextStart() {
42          nextStart = -1;
43      }
44  
45      public static DelimiterSpecification parse(String delimiterSpec) {
46          final String[] spec = new String[2];
47  
48          int splitIdx = delimiterSpec.indexOf('*');
49          if (splitIdx < 0) {
50              spec[0] = delimiterSpec;
51              spec[1] = spec[0];
52          } else if (splitIdx == delimiterSpec.length() - 1) {
53              spec[0] = delimiterSpec.substring(0, delimiterSpec.length() - 1);
54              spec[1] = spec[0];
55          } else {
56              spec[0] = delimiterSpec.substring(0, splitIdx);
57              spec[1] = delimiterSpec.substring(splitIdx + 1);
58          }
59  
60          return new DelimiterSpecification(spec[0], spec[1]);
61      }
62  
63      public String getBegin() {
64          return begin;
65      }
66  
67      public String getEnd() {
68          return end;
69      }
70  
71      public int hashCode() {
72          final int prime = 31;
73          int result = 1;
74          result = prime * result + ((begin == null) ? 0 : begin.hashCode());
75          result = prime * result + ((end == null) ? 0 : end.hashCode());
76          return result;
77      }
78  
79      public boolean equals(Object obj) {
80          if (this == obj) return true;
81          if (obj == null) return false;
82          if (getClass() != obj.getClass()) return false;
83          DelimiterSpecification other = (DelimiterSpecification) obj;
84          if (begin == null) {
85              if (other.begin != null) return false;
86          } else if (!begin.equals(other.begin)) return false;
87          if (end == null) {
88              if (other.end != null) return false;
89          } else if (!end.equals(other.end)) return false;
90          return true;
91      }
92  
93      public String toString() {
94          return "Interpolation delimiter [begin: '" + begin + "', end: '" + end + "']";
95      }
96  }