Bin Class Reference

A Bin contains binning information, such as (weighted) central value, upper and lower limits and width An XAxis has one or more Bins. More...

Inheritance diagram for Bin:

Inheritance graph
[legend]

Collaboration diagram for Bin:

Collaboration graph
[legend]

List of all members.


Public Member Functions

 Bin ()
 Default constructor.
 Bin (Double centralValue)
 Bin (Double lowValue, Double highValue)
 Bin (Double lowValue, Double highValue, Double focus)
 Bin (XAxis xAxis)
 Bin (XAxis xAxis, Double centralValue)
 Bin (XAxis xAxis, Double lowValue, Double highValue)
 Bin (XAxis xAxis, Double lowValue, Double highValue, Double focus)
Integer getId ()
 Get bin ID.
Bin setId (Integer binId)
 Set bin ID.
Double getFocus ()
 Get the nominal central value, not necessarily the gemetric centre.
Bin setFocus (Double focus)
 Set the nominal "central point" of the bin - not necessarily the geometric centre.
Relation getRelation ()
 Get bin-edge Relation.
Bin setRelation (Relation relation)
 Set the bin relation - see the get method for details.
Double getLowValue ()
 Get low edge value.
Bin setLowValue (Double lowValue)
 Set low edge value.
Double getHighValue ()
 Get high edge value.
Bin setHighValue (Double highValue)
 Set high edge value.
Double getWidth ()
 Get bin width.
Bin setWidth (Double width)
 Set bin width.
XAxis getXAxis ()
 Get containing x-axis.
Bin setXAxis (XAxis xAxis)
 Set containing x-axis.
SortedSet< BingetBins ()
 Get all the x-axis Bins which are in the same row as this one (inclusive).
SortedSet< PointgetPoints ()
 Get the corresponding Points from the y-axes in this Dataset.
String toString ()
 String representation.
String toString (Integer indentBy)
 String representation with indent.
boolean equals (Object other)
 Override equals method with business key equality.
int hashCode ()
 Override hashcode method.
int compareTo (Bin other)
 Compare bins by comparing Ids.

Package Functions

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

Detailed Description

A Bin contains binning information, such as (weighted) central value, upper and lower limits and width An XAxis has one or more Bins.

Author:
Andy Buckley
Version:
Date
2006-05-11 16:07:00 +0100 (Thu, 11 May 2006)
Revision
601

Definition at line 18 of file Bin.java.


Constructor & Destructor Documentation

Bin (  ) 

Default constructor.

Definition at line 59 of file Bin.java.

00059                  {
00060         super();
00061     }

Bin ( Double  centralValue  ) 

Definition at line 63 of file Bin.java.

00063                                     {
00064         setFocus(centralValue);
00065     }

Bin ( Double  lowValue,
Double  highValue 
)

Definition at line 67 of file Bin.java.

00067                                                   {
00068         setLowValue(lowValue);
00069         setHighValue(highValue);
00070     }

Bin ( Double  lowValue,
Double  highValue,
Double  focus 
)

Definition at line 72 of file Bin.java.

00072                                                                 {
00073         this(lowValue, highValue);
00074         setFocus(focus);
00075     }

Bin ( XAxis  xAxis  ) 

Definition at line 77 of file Bin.java.

00077                             {
00078         setXAxis(xAxis);
00079     }

Bin ( XAxis  xAxis,
Double  centralValue 
)

Definition at line 81 of file Bin.java.

00081                                                  {
00082         this(centralValue);
00083         setXAxis(xAxis);
00084     }

Bin ( XAxis  xAxis,
Double  lowValue,
Double  highValue 
)

Definition at line 86 of file Bin.java.

00086                                                                {
00087         this(lowValue, highValue);
00088         setXAxis(xAxis);
00089     }

Bin ( XAxis  xAxis,
Double  lowValue,
Double  highValue,
Double  focus 
)

Definition at line 91 of file Bin.java.

00091                                                                              {
00092         this(lowValue, highValue, focus);
00093         setXAxis(xAxis);
00094     }


Member Function Documentation

Integer getId (  ) 

Get bin ID.

Definition at line 101 of file Bin.java.

Referenced by Bin.compareTo().

00101                            {
00102         return _localId;
00103     }

Bin setId ( Integer  binId  ) 

Set bin ID.

Definition at line 105 of file Bin.java.

00105                                     {
00106         _localId = binId;
00107         return this;
00108     }

Double getFocus (  ) 

Get the nominal central value, not necessarily the gemetric centre.

If the focus has not been defined, the geometric centre will be calculated.

Definition at line 113 of file Bin.java.

00113                              {
00114         if (_focus != null) return _focus;
00115 
00116         // Fall back to calculating the geometric centre
00117         log().debug("Asked for focus, but focus is null.");
00118         if (getLowValue() != null && getHighValue() != null) {
00119             log().info("Calculating central value from high and low edges");
00120             return (getLowValue() + getHighValue()) / 2.0;
00121         } else {
00122             log().warn("Could neither retrieve nor calculate bin focus.");
00123             return null;
00124         }
00125     }

Bin setFocus ( Double  focus  ) 

Set the nominal "central point" of the bin - not necessarily the geometric centre.

Definition at line 128 of file Bin.java.

00128                                       {
00129         _focus = focus;
00130         return this;
00131     }

Relation getRelation (  ) 

Get bin-edge Relation.

The relation can give different meanings to the bin edge values: the normal EQUALS relation means the bin edges should be taken as low and high limits as normal.

A "greater-type" relation means that the bin extends from its low edge upwards to infinity and a "less-type" relation will extend the bin from the high edge down to the negative limit. The "unused" edges can be used in these cases to specify a realistic upper or lower limit as appropriate.

Obviously, use of non-EQUALS relations should be restricted to the lowest and highest bins on the axis.

Definition at line 147 of file Bin.java.

00147                                   {
00148         return _relation;
00149     }

Bin setRelation ( Relation  relation  ) 

Set the bin relation - see the get method for details.

Definition at line 152 of file Bin.java.

00152                                               {
00153         _relation = relation;
00154         return this;
00155     }

Double getLowValue (  ) 

Get low edge value.

Definition at line 159 of file Bin.java.

00159                                 {
00160         return _lowValue;
00161     }

Bin setLowValue ( Double  lowValue  ) 

Set low edge value.

Definition at line 163 of file Bin.java.

00163                                             {
00164         _lowValue = lowValue;
00165         return this;
00166     }

Double getHighValue (  ) 

Get high edge value.

Definition at line 170 of file Bin.java.

00170                                  {
00171         return _highValue;
00172     }

Bin setHighValue ( Double  highValue  ) 

Set high edge value.

Definition at line 174 of file Bin.java.

00174                                               {
00175         _highValue = highValue;
00176         return this;
00177     }

Double getWidth (  ) 

Get bin width.

Todo:
Remove if we can!

Definition at line 182 of file Bin.java.

00182                              {
00183         if (_width == null) {
00184             log().info("Asked for width, but Width is null.");
00185             if (getHighValue() != null && getLowValue() != null) {
00186                 log().info("Calculating width from high and low edges");
00187                 return Math.abs(getHighValue() - getLowValue());
00188             }
00189         }
00190         return _width;
00191     }

Bin setWidth ( Double  width  ) 

Set bin width.

Todo:
Remove if we can!

Definition at line 195 of file Bin.java.

00195                                       {
00196         _width = width;
00197         return this;
00198     }

XAxis getXAxis (  ) 

Get containing x-axis.

Definition at line 202 of file Bin.java.

Referenced by Bin.compareTo().

00202                             {
00203         return _xAxis;
00204     }

Bin setXAxis ( XAxis  xAxis  ) 

Set containing x-axis.

Definition at line 206 of file Bin.java.

References XAxis.getBins(), and XAxis.getId().

Referenced by XAxis.addBin(), and XAxis.removeBin().

00206                                      {
00207         _xAxis = xAxis;
00208         if (getXAxis() != null) {
00209             if (getId() == null) {
00210                 int highestId = 0;
00211                 if (xAxis.getBins().size() > 0) {
00212                     highestId = xAxis.getBins().last().getId();
00213                 }
00214                 log().debug("Incrementing bin ID: " + (highestId + 1));
00215                 setId(highestId + 1);
00216             }
00217             log().debug("Adding bin to x-axis " + xAxis.getId() + ": ID = " + getId());
00218             getXAxis().getBins().add(this);
00219         }
00220         return this;
00221     }

SortedSet<Bin> getBins (  ) 

Get all the x-axis Bins which are in the same row as this one (inclusive).

Definition at line 228 of file Bin.java.

References Dataset.getBins(), and XAxis.getDataset().

00228                                     {
00229         SortedSet<Bin> matchingBins = null;
00230         XAxis x = getXAxis();
00231         if (x != null) {
00232             Dataset d = x.getDataset();
00233             if (d != null) {
00234                 matchingBins = d.getBins(getId());
00235             }
00236         }
00237         return matchingBins;
00238     }

SortedSet<Point> getPoints (  ) 

Get the corresponding Points from the y-axes in this Dataset.

Definition at line 241 of file Bin.java.

References XAxis.getDataset(), and Dataset.getPoints().

00241                                         {
00242         SortedSet<Point> matchingPoints = null;
00243         XAxis x = getXAxis();
00244         if (x != null) {
00245             Dataset d = x.getDataset();
00246             if (d != null) {
00247                 matchingPoints = d.getPoints(getId());
00248             }
00249         }
00250         return matchingPoints;
00251     }

String toString (  ) 

String representation.

Reimplemented from Storeable.

Definition at line 258 of file Bin.java.

00258                              {
00259         return toString(0);
00260     }

String toString ( Integer  indentBy  ) 

String representation with indent.

Definition at line 263 of file Bin.java.

00263                                              {
00264         log().debug("Writing out x-axis as a string");
00265         StringBuffer s = new StringBuffer();
00266         String indent = "";
00267         for (int i  = 0; i < indentBy; ++i) indent += " ";
00268 
00269         s.append(indent + "Bin " + getId() + ": ");
00270         if (getLowValue() != null && getHighValue() != null) {
00271             s.append(getLowValue() + " - " + getHighValue());
00272         } else if (getFocus() != null) {
00273             s.append(getFocus());
00274             if (getWidth() != null) {
00275                 s.append(" (width = " + getWidth() + ")");
00276             }
00277         }
00278         return s.toString();
00279     }

boolean equals ( Object  other  ) 

Override equals method with business key equality.

Definition at line 286 of file Bin.java.

00286                                         {
00287         if (this == other) return true;
00288         if (! (other instanceof Bin)) return false;
00289         return hashCode() == other.hashCode();
00290     }

int hashCode (  ) 

Override hashcode method.

Definition at line 294 of file Bin.java.

00294                           {
00295         int code = 79;
00296         if (getXAxis() != null) code ^= getXAxis().hashCode();
00297         if (getFocus() != null) code ^= getFocus().hashCode();
00298         code = 2*code + 1; // ensure this is even
00299         return code;
00300     }

int compareTo ( Bin  other  ) 

Compare bins by comparing Ids.

Todo:
Throw exception when bin has a null ID?

Definition at line 307 of file Bin.java.

References Bin.getId(), and Bin.getXAxis().

00307                                     {
00308         log().debug("Comparing bins...");
00309         if (getId() == null) {
00310             log().warn("Null Bin ID");
00312             return 1; // Sort null bins at the end
00313         } else if (getId() > other.getId()) {
00314             log().debug("Greater than");
00315             return 1;
00316         } else if (getId() < other.getId()) {
00317             log().debug("Less than");
00318             return -1;
00319         } else {
00320             log().debug("Bin IDs are equal");
00321             if (getXAxis() != null && other.getXAxis() != null) {
00322                 return getXAxis().compareTo(other.getXAxis());
00323             } else {
00324                 return 0;
00325             }
00326         }
00327     }

Logger log (  )  [package, inherited]


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


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