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
Revision

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 XAxis.addBin(), and Bin.compareTo().

00101                            {
00102         return _localId;
00103     }

Bin setId ( Integer  binId  ) 

Set bin ID.

Definition at line 105 of file Bin.java.

Referenced by XAxis.addBin().

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.

Referenced by Bin.equals().

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(), and Bin.equals().

00202                             {
00203         return _xAxis;
00204     }

Bin setXAxis ( XAxis  xAxis  ) 

Set containing x-axis.

Definition at line 206 of file Bin.java.

References XAxis.getBins().

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

00206                                      {
00207         _xAxis = xAxis;
00208         if (getXAxis() != null) getXAxis().getBins().add(this);
00209         return this;
00210     }

SortedSet<Bin> getBins (  ) 

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

Definition at line 217 of file Bin.java.

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

00217                                     {
00218         SortedSet<Bin> matchingBins = null;
00219         XAxis x = getXAxis();
00220         if (x != null) {
00221             Dataset d = x.getDataset();
00222             if (d != null) {
00223                 matchingBins = d.getBins(getId());
00224             }
00225         }
00226         return matchingBins;
00227     }

SortedSet<Point> getPoints (  ) 

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

Definition at line 230 of file Bin.java.

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

00230                                         {
00231         SortedSet<Point> matchingPoints = null;
00232         XAxis x = getXAxis();
00233         if (x != null) {
00234             Dataset d = x.getDataset();
00235             if (d != null) {
00236                 matchingPoints = d.getPoints(getId());
00237             }
00238         }
00239         return matchingPoints;
00240     }

String toString (  ) 

String representation.

Reimplemented from Storeable.

Definition at line 247 of file Bin.java.

00247                              {
00248         return toString(0);
00249     }

String toString ( Integer  indentBy  ) 

String representation with indent.

Definition at line 252 of file Bin.java.

00252                                              {
00253         log().debug("Writing out x-axis as a string");
00254         StringBuffer s = new StringBuffer();
00255         String indent = "";
00256         for (int i  = 0; i < indentBy; ++i) indent += " ";
00257 
00258         s.append(indent + "Bin " + getId() + ": ");
00259         if (getLowValue() != null && getHighValue() != null) {
00260             s.append(getLowValue() + " - " + getHighValue());
00261         } else if (getFocus() != null) {
00262             s.append(getFocus());
00263             if (getWidth() != null) {
00264                 s.append(" (width = " + getWidth() + ")");
00265             }
00266         }
00267         return s.toString();
00268     }

boolean equals ( Object  other  ) 

Override equals method with business key equality.

Todo:
Check that value comparison tolerances work

Definition at line 275 of file Bin.java.

References XAxis.equals(), Bin.getFocus(), and Bin.getXAxis().

00275                                         {
00276         if (this == other) return true;
00277         if (! (other instanceof Bin)) return false;
00278 
00279         final Bin test = (Bin) other;
00280         if (test.getXAxis() != null && !test.getXAxis().equals(getXAxis()) ) return false;
00282         if (test.getFocus() != null && getFocus() != null &&
00283             (test.getFocus() - getFocus())/getFocus() > 1e-6 ) return false;
00284 
00285         // If not proven guilty...
00286         return true;
00287     }

int hashCode (  ) 

Override hashcode method.

Definition at line 291 of file Bin.java.

00291                           {
00292         int code = 0;
00293         if (getXAxis() != null) code += 100000 * getXAxis().hashCode();
00294         if (getFocus() != null) code += (int) (1000 * getFocus());
00295         code *= 2; ++code; // ensure this is odd
00296         return code;
00297     }

int compareTo ( Bin  other  ) 

Compare bins by comparing Ids.

Todo:
Throw exception when bin has a null ID?

Definition at line 304 of file Bin.java.

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

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

Logger log (  )  [package, inherited]

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

Definition at line 14 of file Storeable.java.

Referenced by Uncertainty.compareTo(), Reference.compareTo(), PointError.compareTo(), Modification.compareTo(), Experiment.compareTo(), DatasetError.compareTo(), AxisError.compareTo(), Data.makeExample(), Data.makeExampleDataset(), Data.makeExampleExperiment(), Data.makeExamplePaper(), Data.makeExampleXAxes(), Data.makeExampleYAxes(), DatasetError.setNormType(), and Uncertainty.toString().

00014                  {
00015         return Logger.getLogger(this.getClass());
00016     }


The documentation for this class was generated from the following file:
Generated on Thu Sep 20 11:41:38 2007 by  doxygen 1.5.3