View Javadoc
1   /*
2    * Copyright 2007, 2008 Ange Optimization ApS
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  /**
17   * @author kim
18   */
19  package eu.simuline.octave.type;
20  
21  /**
22   * Represents an octave string. 
23   */
24  public final class OctaveString implements OctaveObject {
25  
26      private static final int PRIME = 31;
27  
28      private String value;
29  
30      /**
31       * @param string
32       */
33      public OctaveString(final String string) {
34          this.value = string;
35      }
36  
37      /**
38       * Returns the string represented by this object. 
39       *
40       * @return
41       *    the string represented by this object. 
42       */
43      public String getString() {
44          return this.value;
45      }
46  
47      /**
48       * @param string
49       *    the string to set
50       */
51      public void setString(final String string) {
52          this.value = string;
53      }
54  
55      @Override
56      public int hashCode() {
57          return (this.value == null) ? PRIME : this.value.hashCode();
58      }
59  
60      @Override
61      public boolean equals(final Object obj) {
62          if (this == obj) {
63              return true;
64          }
65          if (obj == null || getClass() != obj.getClass()) {
66              return false;
67          }
68          final OctaveString/../../eu/simuline/octave/type/OctaveString.html#OctaveString">OctaveString other = (OctaveString) obj;
69          if (this.value == null) {
70  	    return other.value == null;
71  	}
72  	return this.value.equals(other.value);
73      }
74  
75      @Override
76      public OctaveString shallowCopy() {
77          return new OctaveString(this.value);
78      }
79  
80      @Override
81      public String toString() {
82          return "OctaveString[" + this.value + "]";
83      }
84  
85  }