View Javadoc

1   /*
2    * ObjectLab, http://www.objectlab.co.uk/open is supporting JTreeMap.
3    * 
4    * Based in London, we are world leaders in the design and development 
5    * of bespoke applications for the securities financing markets.
6    * 
7    * <a href="http://www.objectlab.co.uk/open">Click here to learn more</a>
8    *           ___  _     _           _   _          _
9    *          / _ \| |__ (_) ___  ___| |_| |    __ _| |__
10   *         | | | | '_ \| |/ _ \/ __| __| |   / _` | '_ \
11   *         | |_| | |_) | |  __/ (__| |_| |__| (_| | |_) |
12   *          \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
13   *                   |__/
14   *
15   *                     www.ObjectLab.co.uk
16   *
17   * $Id: Value.java 74 2006-10-24 22:19:05Z benoitx $
18   * 
19   * Copyright 2006 the original author or authors.
20   *
21   * Licensed under the Apache License, Version 2.0 (the "License"); you may not
22   * use this file except in compliance with the License. You may obtain a copy of
23   * the License at
24   *
25   * http://www.apache.org/licenses/LICENSE-2.0
26   *
27   * Unless required by applicable law or agreed to in writing, software
28   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
29   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
30   * License for the specific language governing permissions and limitations under
31   * the License.
32   */
33  package net.sf.jtreemap.swing;
34  
35  import java.io.Serializable;
36  
37  /**
38   * Class who permits to associate a double value to a label
39   * 
40   * @author Laurent DUTHEIL
41   */
42  
43  public abstract class Value implements Comparable, Serializable {
44      private static final int SHIFT = 32;
45      private static final int PRIME = 31;
46  
47      /**
48       * get the double value.
49       * 
50       * @return the double value
51       */
52      public abstract double getValue();
53  
54      /**
55       * get the formatedValue.
56       * 
57       * @return the label of the value
58       */
59      public abstract String getLabel();
60  
61      /**
62       * set the double value.
63       * 
64       * @param value
65       *            the new double value
66       */
67      public abstract void setValue(double value);
68  
69      /**
70       * set the new label.
71       * 
72       * @param newLabel
73       *            the new label
74       */
75      public abstract void setLabel(String newLabel);
76  
77      @Override
78      public int hashCode() {
79          int result = super.hashCode();
80          long temp;
81          temp = Double.doubleToLongBits(getValue());
82          result = PRIME * result + (int) (temp ^ (temp >>> SHIFT));
83          return result;
84      }
85  
86      @Override
87      public boolean equals(final Object obj) {
88          if (this == obj) {
89              return true;
90          }
91          if (!super.equals(obj)) {
92              return false;
93          }
94          if (getClass() != obj.getClass()) {
95              return false;
96          }
97          final Value other = (Value) obj;
98          if (Double.doubleToLongBits(getValue()) != Double.doubleToLongBits(other.getValue())) {
99              return false;
100         }
101         return true;
102     }
103 
104     /*
105      * (non-Javadoc)
106      * 
107      * @see java.lang.Comparable#compareTo(java.lang.Object)
108      */
109     public int compareTo(final Object value) {
110         if (value != null && value instanceof Value) {
111             final Value value2 = (Value) value;
112             if (this.getValue() < value2.getValue()) {
113                 return -1;
114             }
115             return this.getValue() > value2.getValue() ? 1 : 0;
116         }
117         throw new IllegalArgumentException();
118     }
119 }
120 /*
121  *                 ObjectLab is supporing JTreeMap
122  * 
123  * Based in London, we are world leaders in the design and development 
124  * of bespoke applications for the securities financing markets.
125  * 
126  * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a>
127  *           ___  _     _           _   _          _
128  *          / _ \| |__ (_) ___  ___| |_| |    __ _| |__
129  *         | | | | '_ \| |/ _ \/ __| __| |   / _` | '_ \
130  *         | |_| | |_) | |  __/ (__| |_| |__| (_| | |_) |
131  *          \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
132  *                   |__/
133  *
134  *                     www.ObjectLab.co.uk
135  */