View Javadoc

1   /*
2   Karma core - Core of the Karma application
3   Copyright (C) 2004  Toolforge <www.toolforge.nl>
4   
5   This library is free software; you can redistribute it and/or
6   modify it under the terms of the GNU Lesser General Public
7   License as published by the Free Software Foundation; either
8   version 2.1 of the License, or (at your option) any later version.
9   
10  This library 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 GNU
13  Lesser General Public License for more details.
14  
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19  package nl.toolforge.karma.core.vc;
20  
21  import nl.toolforge.karma.core.KarmaRuntimeException;
22  
23  import java.util.regex.PatternSyntaxException;
24  
25  /***
26   * A development line is a separate line of development for a module, generally implemented by a version control
27   * system through a branch.
28   *
29   * @author D.A. Smedes
30   * @version $Id: DevelopmentLine.java,v 1.8 2004/08/29 18:00:38 hippe Exp $
31   */
32  public class DevelopmentLine {
33  
34    public static final String DEVELOPMENT_LINE_PATTERN_STRING = "[A-Za-z-]+[A-Z0-9a-z-]*";
35  
36    private String lineName = null;
37  
38    /***
39     * Constructor for a development line. <code>lineName</code> should match {@link DEVELOPMENT_LINE_PATTERN_STRING}.
40     *
41     * @param lineName The name for a development line
42     */
43    public DevelopmentLine(String lineName) {
44  
45      if (lineName == null || !lineName.matches(getPatternString())) {
46        throw new PatternSyntaxException("Pattern mismatch for version. Should match " + getPatternString(), lineName, -1);
47      }
48      this.lineName = lineName;
49    }
50  
51    public String getName() {
52  
53      if (lineName == null) {
54        throw new KarmaRuntimeException("Line name has not been set.");
55      }
56      return lineName;
57    }
58  
59    public int hashCode() {
60      return lineName.hashCode();
61    }
62  
63    public String getPatternString() {
64      return DEVELOPMENT_LINE_PATTERN_STRING;
65    }
66  
67    /***
68     * Compares two DevelopmentLine instance for equality. Two instances are equal when their names are the same.
69     *
70     * @param o Object (of type DevelopmentLine)
71     */
72    public boolean equals(Object o) {
73      if (!(o instanceof DevelopmentLine)) {
74        return false;
75      }
76      return ((DevelopmentLine) o).lineName.equals(this.lineName);
77    }
78  
79  }