1 /*** UnitValue.java - part of the MirkE (say murky) application for colormetric analysis emphesizing
2 kinetics.
3
4 Created by: Scott Menor on 21 July, 2004.
5 Last modified by: Scott Menor on 9 January, 2005
6
7 Copyright (c) 2004 Arizona State University - Cancer Research Institute. All rights reserved.
8
9 MirkE is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 MirkE is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with MirkE; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US
22 */
23
24
25
26
27
28
29
30
31
32 package edu.asu.cri.MirkE.dataStructures;
33
34 /*** storage for a scalar (double) value and an associated Unit
35
36 TODO - replace the scalar with an arbitrary Object (will take too much time to develope with hibernate for now)
37
38 */
39 public class UnitValue {
40 private long id;
41
42 /***
43
44 @return id
45 */
46 public long getId() {
47 return id;
48 }
49
50 /***
51 @param id
52 */
53 public void setId(long id) {
54 this.id = id;
55 }
56
57 private boolean editable = false;
58 /***
59 * @return editable
60 */
61 public boolean isEditable() {
62 return editable;
63 }
64
65 /***
66 * @param editable
67 *
68 */
69 public void setEditable(boolean editable) {
70 this.editable = editable;
71 }
72
73 private Unit units;
74
75 /***
76 * @return Returns the unit.
77 */
78 public Unit getUnits() {
79 return this.units;
80 }
81
82 /***
83 * @param unit The unit to set.
84 */
85 public void setUnits(Unit unit) {
86 this.units = unit;
87 }
88
89 private double value;
90
91 /***
92 @param value
93 */
94 public void setValue(double value) {
95 this.value = value;
96 }
97
98 /***
99 @return value
100 */
101 public double getValue() {
102 return this.value;
103 }
104
105 /***
106 *
107 * @return string representation
108 */
109 public String toString() {
110 String string = "" + value + " ("+this.units.toString()+")";
111
112 return string;
113 }
114
115 /*** default constructor
116 */
117 public UnitValue() {}
118
119 /*** constructor
120 @param value
121 @param units
122 */
123 public UnitValue(
124 double value,
125 Unit units) {
126 this.value = value;
127 this.units = units;
128 }
129
130 /***
131 * @see java.lang.Object#equals(java.lang.Object)
132 */
133 public boolean equals(Object object) {
134 if (object.getClass().getName().equals(this.getClass().getName())) {
135 UnitValue comparisonUnitValue = (UnitValue)object;
136
137 if (comparisonUnitValue.getUnits().isCompatible(this.getUnits())) {
138 double comparisonUnitValueInThisUnits = this.getUnits().convertTo(comparisonUnitValue.getValue(), this.units);
139
140 if (comparisonUnitValueInThisUnits == this.getValue()) {
141 return true;
142 }
143 }
144 }
145
146 return false;
147 }
148 }