View Javadoc

1   package org.lsst.ccs.config;
2   
3   
4   import org.hibernate.annotations.Immutable;
5   
6   import javax.persistence.Embeddable;
7   import java.io.Serializable;
8   
9   /**
10   * Unique Path in a SubSystem. Objects of this class are immutable.
11   * (no public mutator).
12   */
13  @Embeddable
14  @Immutable
15  public class ParameterPath implements PathObject , Serializable {
16      private static final long serialVersionUID = -1012785409109930223L;
17      /**
18       * unique name of Module/component in subsystem context
19       */
20      //****@Id
21      String /*@NotNull*/ componentName;
22      /**
23       *  constructor or method. null or empty value means constructor
24       */
25      //****@Id
26      String /*@Nullable*/ codeName ;
27      /**
28       * name of parameter (may be the number of a positionnal parameter starting at 0)
29       */
30      //****@Id
31      String /*@NotNull*/ parameterName ;
32      
33      //////////////////////////////////// CONSTRUCTORS
34  
35      /**
36       * non public constructor (for POJO-aware tools)
37       */
38       ParameterPath() {
39      }
40  
41      /**
42       * "real" constructor
43       * @param componentName should not be null
44       * @param codeName null of empty means constructor
45       * @param parameterName should not be null
46       */
47      public ParameterPath(String componentName, String codeName, String parameterName) {
48          if(componentName == null || parameterName == null) {
49              throw new IllegalArgumentException("null argument in ParameterPath");
50          }
51          if(codeName == null) {
52              codeName = "" ;
53          }
54          this.componentName = componentName;
55          this.codeName = codeName;
56          this.parameterName = parameterName;
57      }
58      
59      ////////////////////////////////// ACCESSORS/MUTATORS
60  
61      public String getComponentName() {
62          return componentName;
63      }
64  
65       void setComponentName(String componentName) {
66          this.componentName = componentName;
67      }
68  
69      public String getCodeName() {
70          return codeName;
71      }
72  
73       void setCodeName(String codeName) {
74          this.codeName = codeName;
75      }
76  
77      public String getParameterName() {
78          return parameterName;
79      }
80  
81       void setParameterName(String parameterName) {
82          this.parameterName = parameterName;
83      }
84      
85      ////////////////////////////// IDENT METHODS
86  
87      @Override
88      public boolean equals(Object o) {
89          if (this == o) return true;
90          if (o == null || getClass() != o.getClass()) return false;
91  
92          ParameterPath that = (ParameterPath) o;
93  
94          if (codeName != null ? !codeName.equals(that.codeName) : that.codeName != null) return false;
95          if (!componentName.equals(that.componentName)) return false;
96          if (!parameterName.equals(that.parameterName)) return false;
97  
98          return true;
99      }
100 
101 
102     @Override
103     public int hashCode() {
104         int result = componentName.hashCode();
105         result = 31 * result + (codeName != null ? codeName.hashCode() : 0);
106         result = 31 * result + parameterName.hashCode();
107         return result;
108     }
109     
110     @Override
111     public String toString() {
112         String codeName = this.getCodeName() ;
113         if(codeName == null) {
114             codeName ="" ;
115         }
116         return this.componentName + '/'
117                 + this.codeName + '/'
118                 +this.parameterName ;
119     }
120 
121     /**
122      * reverse operation from toString(): creates a ParameterPath from a String.
123      * @param pathString should be of the form "componentName/codeName/parameterName" (example: "carousel//tickMillis")
124      * @return
125      * @throws  IllegalArgumentException if format is not correct
126      */
127     public static ParameterPath valueOf(String pathString) {
128         ParameterPath path ;
129         String[] elements = pathString.split("/") ;
130         if(elements.length != 3) {
131             throw new IllegalArgumentException("PathString should be componentName/codeName/parameterName");
132         }
133         path = new ParameterPath(elements[0], elements[1], elements[2]) ;
134         return path ;
135     }
136 
137     @Override
138     public ParameterPath getPath() {
139         return this ;
140     }
141 }