Debian Codegraph @

freehep-graphicsbase/src/main/java/org/freehep/graphicsbase/util/DoubleWithError.java

raw
1 package org.freehep.graphicsbase.util;
2
3 /**
4 * A class that encapsulates a value and its error.
5 * Primarily for use with ScientificFormat
6 *
7 * @see ScientificFormat
8 *
9 * @author Tony Johnson
10 * @author Mark Donszelmann
11 * @version $Id: DoubleWithError.java 8584 2006-08-10 23:06:37Z duns $
12 */
13 public class DoubleWithError
14 {
15 public DoubleWithError(double value, double error)
16 {
17 this.value = value;
18 this.error = error;
19 this.asymmetricError = false;
20 }
21
22 public DoubleWithError(double value, double plusError, double minError)
23 {
24 this.value = value;
25 this.error = plusError;
26 this.minError = minError;
27 this.asymmetricError = true;
28 }
29
30 public void setError(double error)
31 {
32 this.error = error;
33 this.asymmetricError = false;
34 }
35
36 public void setError(double plusError, double minError)
37 {
38 this.error = plusError;
39 this.minError = minError;
40 this.asymmetricError = true;
41 }
42
43 public double getError()
44 {
45 // FIXME: what do we return here if this has an asymmetric error
46 return error;
47 }
48
49 public double getPlusError()
50 {
51 return error;
52 }
53
54 public double getMinError()
55 {
56 return (asymmetricError) ? minError : error;
57 }
58
59 public boolean hasAsymmetricError()
60 {
61 return asymmetricError;
62 }
63
64 public void setValue(double value)
65 {
66 this.value = value;
67 }
68
69 public double getValue()
70 {
71 return value;
72 }
73
74 public String toString()
75 {
76 if (asymmetricError)
77 {
78 return String.valueOf(value)+plus+error+minus+minError;
79 }
80 else
81 {
82 return String.valueOf(value)+plusorminus+error;
83 }
84 }
85 // Not private because used by scientific format
86 final static char plusorminus = '\u00b1';
87 final static char plus = '+';
88 final static char minus = '-';
89 private double value;
90
91 private double error;
92 private boolean asymmetricError;
93 private double minError;
94 }