Package uk.ac.rdg.resc.edal.grid
Class ReferenceableAxisImpl
- java.lang.Object
-
- uk.ac.rdg.resc.edal.grid.AbstractReferenceableAxis<T>
-
- uk.ac.rdg.resc.edal.grid.AbstractIrregularAxis<Double>
-
- uk.ac.rdg.resc.edal.grid.ReferenceableAxisImpl
-
- All Implemented Interfaces:
Serializable,DiscreteDomain<Double,Extent<Double>>,Domain<Double>,ReferenceableAxis<Double>
- Direct Known Subclasses:
DefinedBoundsAxis,VerticalAxisImpl
public class ReferenceableAxisImpl extends AbstractIrregularAxis<Double>
Immutable implementation of aReferenceableAxis, whose values are not necessarily regularly spaced along the axis.- Author:
- Guy, Jon
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class uk.ac.rdg.resc.edal.grid.AbstractIrregularAxis
axisValues, reversed
-
-
Constructor Summary
Constructors Constructor Description ReferenceableAxisImpl(String name, List<Double> axisValues, boolean isLongitude)Creates a ReferenceableAxis from the given array of axis values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected doubledifference(Double pos1, Double pos2)Returns the difference between the supplied values.booleanequals(Object obj)protected DoubleextendFirstValue(Double firstVal, Double nextVal)This should return the lower bound of the first value of the axis, based on the first and second values.protected DoubleextendLastValue(Double lastVal, Double secondLastVal)This should return the upper bound of the last value of the axis, based on the last two values.intfindIndexOf(Double position)Finds the index along this axis that corresponds with the given position.protected DoublegetMidpoint(Double pos1, Double pos2)Returns the midpoint of the supplied values.inthashCode()booleanwraps()Returns true if the values on the axis wrap around (e.g.-
Methods inherited from class uk.ac.rdg.resc.edal.grid.AbstractIrregularAxis
checkAscending, getCoordinateBounds, getCoordinateValue, isAscending, size
-
Methods inherited from class uk.ac.rdg.resc.edal.grid.AbstractReferenceableAxis
contains, getCoordinateExtent, getCoordinateValues, getDomainObjects, getFirstValue, getLastValue, getMaximumValue, getMinimumValue, getName
-
-
-
-
Constructor Detail
-
ReferenceableAxisImpl
public ReferenceableAxisImpl(String name, List<Double> axisValues, boolean isLongitude)
Creates a ReferenceableAxis from the given array of axis values. The axis values are copied to internal data structures, therefore subsequent modifications to the array of axis values have no effect on this object.- Parameters:
name- The name of the axisaxisValues- List of axis values; must ascend or descend monotonicallyisLongitude- True if this is a longitude axis in degrees (hence values of 0 and 360 are equivalent).- Throws:
NullPointerException- ifaxisValuesis nullIllegalArgumentException- if the axis values are not in strictly ascending numerical order, or if the array of axis values is empty
-
-
Method Detail
-
wraps
public boolean wraps()
Description copied from interface:ReferenceableAxisReturns true if the values on the axis wrap around (e.g. longitude)
-
findIndexOf
public int findIndexOf(Double position)
Description copied from interface:ReferenceableAxisFinds the index along this axis that corresponds with the given position. Formally, this returns an index such that getCoordinateBounds(index).contains(position) returns true. Returns -1 if the given position is not associated with any axis index.
If this is a longitude axis, this method will handle the case of longitude values wrapping, therefore values of -180 and +180 are treated as equivalent by this method, irrespective of the values in
ReferenceableAxis.getCoordinateValue(int).- Specified by:
findIndexOfin interfaceReferenceableAxis<Double>- Overrides:
findIndexOfin classAbstractIrregularAxis<Double>- Returns:
- the index of the given coordinate value, or -1 if not found.
-
extendFirstValue
protected Double extendFirstValue(Double firstVal, Double nextVal)
Description copied from class:AbstractReferenceableAxisThis should return the lower bound of the first value of the axis, based on the first and second values. This will generally be equivalent to:firstVal - (nextVal-firstVal)/2
- Specified by:
extendFirstValuein classAbstractReferenceableAxis<Double>- Parameters:
firstVal- The first value of the axisnextVal- The second value of the axis- Returns:
- The lower bound of the first axis value
-
extendLastValue
protected Double extendLastValue(Double lastVal, Double secondLastVal)
Description copied from class:AbstractReferenceableAxisThis should return the upper bound of the last value of the axis, based on the last two values. This will generally be equivalent to:lastVal + (lastVal-secondLastVal)/2
- Specified by:
extendLastValuein classAbstractReferenceableAxis<Double>- Parameters:
lastVal- The last value of the axissecondLastVal- The next-to-last value of the axis- Returns:
- The upper bound of the the final axis value
-
difference
protected double difference(Double pos1, Double pos2)
Description copied from class:AbstractIrregularAxisReturns the difference between the supplied values. This is so that certain methods can be abstracted without worrying about non-trivial difference calculation (e.g.DateTimes)- Specified by:
differencein classAbstractIrregularAxis<Double>- Parameters:
pos1- the first valuepos2- the second value- Returns:
- the value corresponding to pos1 - pos2
-
getMidpoint
protected Double getMidpoint(Double pos1, Double pos2)
Description copied from class:AbstractIrregularAxisReturns the midpoint of the supplied values. This is so that certain methods can be abstracted without worrying about non-trivial midpoint calculation (e.g.DateTimes)- Specified by:
getMidpointin classAbstractIrregularAxis<Double>- Parameters:
pos1- the first valuepos2- the second value- Returns:
- the midpoint of the values
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfaceReferenceableAxis<Double>- Overrides:
hashCodein classAbstractIrregularAxis<Double>
-
equals
public boolean equals(Object obj)
- Specified by:
equalsin interfaceReferenceableAxis<Double>- Overrides:
equalsin classAbstractIrregularAxis<Double>
-
-