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$
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  import lombok.EqualsAndHashCode;
38  
39  /**
40   * Class who permits to associate a double value to a label
41   *
42   * @author Laurent DUTHEIL
43   */
44  @EqualsAndHashCode
45  public abstract class Value implements Comparable, Serializable {
46      private static final long serialVersionUID = 1L;
47  
48      /**
49       * get the double value.
50       *
51       * @return the double value
52       */
53      public abstract double getValue();
54  
55      /**
56       * get the formatedValue.
57       *
58       * @return the label of the value
59       */
60      public abstract String getLabel();
61  
62      /**
63       * set the double value.
64       *
65       * @param value
66       *            the new double value
67       */
68      public abstract void setValue(double value);
69  
70      /**
71       * set the new label.
72       *
73       * @param newLabel
74       *            the new label
75       */
76      public abstract void setLabel(String newLabel);
77  
78      @Override
79      public int compareTo(final Object value) {
80          if (value instanceof Value) {
81              final Value value2 = (Value) value;
82              if (this.getValue() < value2.getValue()) {
83                  return -1;
84              }
85              return this.getValue() > value2.getValue() ? 1 : 0;
86          }
87          throw new IllegalArgumentException();
88      }
89  
90      @Override
91      public String toString() {
92          final StringBuilder b = new StringBuilder();
93          b.append(getLabel()).append(" - ").append(getValue());
94          return b.toString();
95      }
96  
97  }
98  /*
99   *                 ObjectLab is supporing JTreeMap
100  *
101  * Based in London, we are world leaders in the design and development
102  * of bespoke applications for the securities financing markets.
103  *
104  * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a>
105  *           ___  _     _           _   _          _
106  *          / _ \| |__ (_) ___  ___| |_| |    __ _| |__
107  *         | | | | '_ \| |/ _ \/ __| __| |   / _` | '_ \
108  *         | |_| | |_) | |  __/ (__| |_| |__| (_| | |_) |
109  *          \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
110  *                   |__/
111  *
112  *                     www.ObjectLab.co.uk
113  */