PointError Class Reference

An Uncertainty which applies to one point only, i.e. More...

Inheritance diagram for PointError:

Inheritance graph
[legend]

Collaboration diagram for PointError:

Collaboration graph
[legend]

List of all members.


Public Member Functions

 PointError ()
 Default constructor.
 PointError (Double plusminus, ErrorSource sourcetype, ErrorNorm normtype)
 Constructor for symmetric error.
 PointError (Double plus, Double minus, ErrorSource sourcetype, ErrorNorm normtype)
 Constructor for asymmetric errors.
 PointError (Point parent, Double plusminus, ErrorSource sourcetype, ErrorNorm normtype)
 Constructor for symmetric error, with parent point.
 PointError (Point parent, Double plus, Double minus, ErrorSource sourcetype, ErrorNorm normtype)
 Constructor for asymmetric errors, with parent point.
Uncertainty getAbsoluteError () throws HDException
 Get the absolute error corresponding to this error and its point's value.
Uncertainty getAbsoluteError (Point p) throws HDException
 Get the absolute error corresponding to this error and a given point (which must be this error's parent point).
Integer getId ()
 Get the point error ID.
PointError setId (Integer pointErrorId)
 Set the point error ID.
.hibernate.annotations.Parent Point getPoint ()
 Get the parent point.
PointError setPoint (Point parentPoint)
 Set the parent point.
int compareTo (PointError other)
boolean equals (Object other)
 Override equals method with business key equality.
int hashCode ()
 Override hashcode method.
boolean isSymmetric ()
 Are the plus and minus errors symmetric?
boolean hasZeroSize ()
 Are the plus and minus errors both zero?
Double getPlus ()
 Get the upward error.
Uncertainty setPlus (Double plus)
 Set the upward error.
Double getMinus ()
 Get the downward error.
Uncertainty setMinus (Double minus)
 Set the downward error.
ErrorSource getSourceType ()
 Get the error source type (stat, sys, etc.
Uncertainty setSourceType (ErrorSource sourcetype)
 Set the error source type (stat, sys, etc.
ErrorNorm getNormType ()
 Get the error normalization type (abs, frac, pct, etc.
Uncertainty setNormType (ErrorNorm normtype)
 Set the error normalization type (abs, frac, pct, etc.
String getComment ()
 Get the modification comment string.
Uncertainty setComment (String comment)
 Set the modification comment string.
int compareTo (Uncertainty other)
String toString ()
 String representation.
String toString (Integer indentBy)
 Indented string representation.

Package Functions

Logger log ()
 Neat method to allow every class to get hold of a custom-named Logger.

Detailed Description

An Uncertainty which applies to one point only, i.e.

as stored by a Value.

Author:
Andy Buckley
Version:
Date
2006-04-05 17:16:08 +0100 (Wed, 05 Apr 2006)
Revision
554

Definition at line 14 of file PointError.java.


Constructor & Destructor Documentation

PointError (  ) 

Default constructor.

Definition at line 30 of file PointError.java.

00030 { super(); }

PointError ( Double  plusminus,
ErrorSource  sourcetype,
ErrorNorm  normtype 
)

Constructor for symmetric error.

Parameters:
plusminus : size of symmetric error
sourcetype : origin of error, i.e. systematic, statistical, etc.
normtype : normalisation of error, i.e. absolute, fractional, percentage, etc.

Definition at line 38 of file PointError.java.

00038                                                                                     {
00039         super(plusminus, sourcetype, normtype);
00040     }

PointError ( Double  plus,
Double  minus,
ErrorSource  sourcetype,
ErrorNorm  normtype 
)

Constructor for asymmetric errors.

Parameters:
plus input <0 gives -err1
minus input <0 gives +err2
sourcetype : origin of error, i.e. systematic, statistical, etc.
normtype : normalisation of error, i.e. absolute, fractional, percentage, etc.

Definition at line 49 of file PointError.java.

00049                                                                                              {
00050         super(plus, minus, sourcetype, normtype);
00051     }

PointError ( Point  parent,
Double  plusminus,
ErrorSource  sourcetype,
ErrorNorm  normtype 
)

Constructor for symmetric error, with parent point.

Definition at line 56 of file PointError.java.

References PointError.setPoint().

00056                                                                                                   {
00057         super(plusminus, sourcetype, normtype);
00058         setPoint(parent);
00059     }

PointError ( Point  parent,
Double  plus,
Double  minus,
ErrorSource  sourcetype,
ErrorNorm  normtype 
)

Constructor for asymmetric errors, with parent point.

Definition at line 64 of file PointError.java.

References PointError.setPoint().

00064                                                                                                            {
00065         super(plus, minus, sourcetype, normtype);
00066         setPoint(parent);
00067     }


Member Function Documentation

Uncertainty getAbsoluteError (  )  throws HDException

Get the absolute error corresponding to this error and its point's value.

Definition at line 74 of file PointError.java.

References Uncertainty.getAbsoluteError(), and PointError.getPoint().

00074                                                              {
00075         return super.getAbsoluteError(getPoint());
00076     }

Uncertainty getAbsoluteError ( Point  p  )  throws HDException

Get the absolute error corresponding to this error and a given point (which must be this error's parent point).

Reimplemented from Uncertainty.

Definition at line 80 of file PointError.java.

References PointError.getPoint().

00080                                                                     {
00081         if (! p.equals(getPoint())) {
00082             throw new HDException("Tried to apply a point error to a point other than its owner.");
00083         }
00084         return super.getAbsoluteError(p);
00085     }

Integer getId (  ) 

Get the point error ID.

Definition at line 92 of file PointError.java.

Referenced by PointError.compareTo(), PointError.hashCode(), and PointError.setPoint().

00092                            {
00093         return _localId;
00094     }

PointError setId ( Integer  pointErrorId  ) 

Set the point error ID.

Definition at line 96 of file PointError.java.

Referenced by PointError.setPoint().

00096                                                   {
00097         _localId = pointErrorId;
00098         return this;
00099     }

.hibernate.annotations.Parent Point getPoint (  ) 

Get the parent point.

Definition at line 107 of file PointError.java.

Referenced by PointError.getAbsoluteError(), and PointError.hashCode().

00107                             {
00108         return _point;
00109     }

PointError setPoint ( Point  parentPoint  ) 

Set the parent point.

Definition at line 112 of file PointError.java.

References Point.getErrors(), PointError.getId(), Storeable.log(), and PointError.setId().

Referenced by Point.addError(), and PointError.PointError().

00112                                                   {
00113         log().debug("Calling setPoint()");
00114         _point = parentPoint;
00115         if (parentPoint != null) {
00116             if (getId() == null) {
00117                 int highestId = 0;
00118                 if (parentPoint.getErrors().size() > 0) {
00119                     highestId = parentPoint.getErrors().last().getId();
00120                 }
00121                 log().debug("Incrementing point error ID: " + (highestId + 1));
00122                 setId(highestId + 1);
00123             }
00124             parentPoint.getErrors().add(this);
00125         } else {
00126             log().warn("Tried to attach a PointError to a null Point");
00127         }
00128         return this;
00129     }

int compareTo ( PointError  other  ) 

Definition at line 135 of file PointError.java.

References PointError.getId(), and Storeable.log().

Referenced by Uncertainty.compareTo().

00135                                            {
00136         log().debug("Comparing point errors...");
00137         if (getId() == null) {
00138             log().warn("Null point error ID");
00139             return 1; // Sort null point errors at the end
00140         } else if (getId() > other.getId()) {
00141             log().debug("Greater than");
00142             return 1;
00143         } else if (getId() < other.getId()) {
00144             log().debug("Less than");
00145             return -1;
00146         } else {
00147             log().debug("Equal to");
00148             return 0;
00149         }
00150     }

boolean equals ( Object  other  ) 

Override equals method with business key equality.

Definition at line 157 of file PointError.java.

References PointError.hashCode().

00157                                         {
00158         if (this == other) return true;
00159         if (! (other instanceof PointError)) return false;
00160         return hashCode() == other.hashCode();
00161     }

int hashCode (  ) 

Override hashcode method.

Definition at line 164 of file PointError.java.

References PointError.getId(), Uncertainty.getMinus(), Uncertainty.getNormType(), Uncertainty.getPlus(), PointError.getPoint(), Uncertainty.getSourceType(), and Point.hashCode().

Referenced by PointError.equals().

00164                           {
00165         int code = 23;
00166         if (getPoint() != null)      code ^= getPoint().hashCode();
00167         if (getSourceType() != null) code ^= getSourceType().hashCode();
00168         if (getNormType() != null)   code ^= getNormType().hashCode();
00169         if (getId() != null)         code ^= getId().hashCode();
00170         if (getPlus() != null)       code ^= 2 * getPlus().hashCode(); // ensure this is even
00171         if (getMinus() != null)      code ^= 2 * getMinus().hashCode() + 1; // ensure this is odd
00172         return code;
00173     }

boolean isSymmetric (  )  [inherited]

Are the plus and minus errors symmetric?

Definition at line 81 of file Uncertainty.java.

References Uncertainty.getMinus(), and Uncertainty.getPlus().

Referenced by Uncertainty.toString().

00081                                  {
00082         return (getPlus().equals(getMinus()));
00083     }

boolean hasZeroSize (  )  [inherited]

Are the plus and minus errors both zero?

Definition at line 87 of file Uncertainty.java.

References Uncertainty.getMinus(), and Uncertainty.getPlus().

00087                                  {
00088         return (getPlus().equals(0.0) && getMinus().equals(0.0));
00089     }

Double getPlus (  )  [inherited]

Uncertainty setPlus ( Double  plus  )  [inherited]

Set the upward error.

Definition at line 130 of file Uncertainty.java.

Referenced by Uncertainty.Uncertainty().

00130                                             {
00131         _plus = plus;
00132         return this;
00133     }

Double getMinus (  )  [inherited]

Get the downward error.

Definition at line 138 of file Uncertainty.java.

Referenced by Uncertainty.getAbsoluteError(), PointError.hashCode(), DatasetError.hashCode(), AxisError.hashCode(), Uncertainty.hasZeroSize(), Uncertainty.isSymmetric(), and Uncertainty.toString().

00138                              {
00139         return _minus;
00140     }

Uncertainty setMinus ( Double  minus  )  [inherited]

Set the downward error.

Definition at line 143 of file Uncertainty.java.

Referenced by Uncertainty.Uncertainty().

00143                                               {
00144         _minus = minus;
00145         return this;
00146     }

ErrorSource getSourceType (  )  [inherited]

Get the error source type (stat, sys, etc.

) as an enum.

Definition at line 151 of file Uncertainty.java.

Referenced by Uncertainty.getAbsoluteError(), PointError.hashCode(), DatasetError.hashCode(), AxisError.hashCode(), and Uncertainty.toString().

00151                                        {
00152         return _sourcetype;
00153     }

Uncertainty setSourceType ( ErrorSource  sourcetype  )  [inherited]

Set the error source type (stat, sys, etc.

) from the enum.

Definition at line 156 of file Uncertainty.java.

Referenced by Uncertainty.Uncertainty().

00156                                                              {
00157         _sourcetype = sourcetype;
00158         return this;
00159     }

ErrorNorm getNormType (  )  [inherited]

Get the error normalization type (abs, frac, pct, etc.

) as an enum.

Definition at line 163 of file Uncertainty.java.

Referenced by Uncertainty.getAbsoluteError(), PointError.hashCode(), DatasetError.hashCode(), AxisError.hashCode(), and Uncertainty.toString().

00163                                    {
00164         return _normtype;
00165     }

Uncertainty setNormType ( ErrorNorm  normtype  )  [inherited]

Set the error normalization type (abs, frac, pct, etc.

) from the enum.

Reimplemented in DatasetError.

Definition at line 167 of file Uncertainty.java.

Referenced by Uncertainty.Uncertainty().

00167                                                        {
00168         _normtype = normtype;
00169         return this;
00170     }

String getComment (  )  [inherited]

Get the modification comment string.

Definition at line 174 of file Uncertainty.java.

Referenced by Uncertainty.toString().

00174                                {
00175         return _comment;
00176     }

Uncertainty setComment ( String  comment  )  [inherited]

Set the modification comment string.

Definition at line 178 of file Uncertainty.java.

00178                                                   {
00179         _comment = comment;
00180         return this;
00181     }

int compareTo ( Uncertainty  other  )  [inherited]

Todo:
Compare otherwise-equals based on stat vs sys

Definition at line 187 of file Uncertainty.java.

References DatasetError.compareTo(), AxisError.compareTo(), PointError.compareTo(), and Storeable.log().

00187                                             {
00188         log().debug("Comparing errors...");
00189 
00190         // For point errors
00191         if (this instanceof PointError) {
00192             if (other instanceof PointError) {
00193                 PointError test = (PointError) this;
00194                 int result = test.compareTo((PointError) other);
00195                 if (result != 0) return result;
00196             } else return 1;
00197         }
00198 
00199         // For axis errors
00200         if (this instanceof AxisError) {
00201             if (other instanceof AxisError) {
00202                 AxisError test = (AxisError) this;
00203                 int result = test.compareTo((AxisError) other);
00204                 if (result != 0) return result;
00205             } else return (other instanceof PointError) ? -1 : 1;
00206         }
00207 
00208         // For dataset errors
00209         if (this instanceof DatasetError) {
00210             if (other instanceof DatasetError) {
00211                 DatasetError test = (DatasetError) this;
00212                 int result = test.compareTo((DatasetError) other);
00213                 if (result != 0) return result;
00214             } else return 1;
00215         }
00216 
00218         return 0;
00219     }

String toString (  )  [inherited]

String representation.

Reimplemented from Storeable.

Definition at line 227 of file Uncertainty.java.

Referenced by Uncertainty.toString().

00227                              {
00228         return toString(0);
00229     }

String toString ( Integer  indentBy  )  [inherited]

Indented string representation.

Definition at line 233 of file Uncertainty.java.

References Uncertainty.getComment(), Uncertainty.getMinus(), Uncertainty.getNormType(), Uncertainty.getPlus(), Uncertainty.getSourceType(), Uncertainty.isSymmetric(), Storeable.log(), and Uncertainty.toString().

00233                                              {
00234         log().debug("Writing out error as a string");
00235         StringBuffer s = new StringBuffer();
00236         String indent = "";
00237         for (int i  = 0; i < indentBy; ++i) indent += " ";
00238 
00239         //if (! hasZeroSize()) {
00240         s.append(indent);
00241         Double plusval = getPlus();
00242         Double minusval = getMinus();
00243 
00244         String numFormat = "###.##";
00245         // Use the number formatter to recalculate and display everything as a percentage
00246         if (getNormType() == ErrorNorm.PCT) {
00247             plusval /= 100;
00248             minusval /= 100;
00249         }
00250         if (getNormType() == ErrorNorm.FRAC || getNormType() == ErrorNorm.PCT) {
00251             numFormat += "%"; // multiplies by 100 and sticks "%" on the end
00252         }
00253         DecimalFormat numFormatter = new DecimalFormat(numFormat);
00254         if (isSymmetric()) {
00255             s.append("+- " + numFormatter.format(plusval));
00256         } else {
00257             s.append("+ " + numFormatter.format(plusval));
00258             s.append(" - " + numFormatter.format(minusval));
00259         }
00260         s.append(" (");
00261         //s.append(getNormType().toString());
00262         //s.append(", ");
00263         s.append(getSourceType().toString());
00264         s.append(")");
00265         if (getComment() != null && getComment().length() != 0) {
00266             s.append(" [" + getComment() + "]");
00267         }
00268         //}
00269         return s.toString();
00270     }

Logger log (  )  [package, inherited]


The documentation for this class was generated from the following file:


Generated on Tue Apr 21 15:54:48 2009 for HepData object model by  doxygen 1.5.5