Package uk.ac.rdg.resc.edal.grid
Class RegularAxisImpl
- java.lang.Object
-
- uk.ac.rdg.resc.edal.grid.AbstractReferenceableAxis<Double>
-
- uk.ac.rdg.resc.edal.grid.RegularAxisImpl
-
- All Implemented Interfaces:
Serializable
,DiscreteDomain<Double,Extent<Double>>
,Domain<Double>
,ReferenceableAxis<Double>
,RegularAxis
public final class RegularAxisImpl extends AbstractReferenceableAxis<Double> implements RegularAxis, Serializable
Immutable implementation of aRegularAxis
, whose values are regularly spaced along the axis.- Author:
- Jon, Guy Griffiths
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description RegularAxisImpl(String name, double firstValue, double spacing, int size, boolean isLongitude)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
protected Double
extendFirstValue(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 Double
extendLastValue(Double lastVal, Double secondLastVal)
This should return the upper bound of the last value of the axis, based on the last two values.int
findIndexOf(Double position)
Finds the index along this axis that corresponds with the given position.int
findIndexOfUnconstrained(Double position)
Finds the apparent index of a given position, even if this is beyond the bounds of the axis.Extent<Double>
getCoordinateBounds(int index)
Gets the coordinate bounds associated with the point at the given index.Extent<Double>
getCoordinateExtent()
Gets the extent encompassing all the positions on this axis.double
getCoordinateSpacing()
Gets the spacing between coordinate values, might be negative.Double
getCoordinateValue(int index)
Gets the coordinate value at the given indexint
hashCode()
boolean
isAscending()
Returns true if the values on the axis are in ascending order according to their natural ordering.int
size()
String
toString()
boolean
wraps()
Returns true if the values on the axis wrap around (e.g.-
Methods inherited from class uk.ac.rdg.resc.edal.grid.AbstractReferenceableAxis
contains, getCoordinateValues, getDomainObjects, getFirstValue, getLastValue, getMaximumValue, getMinimumValue, getName
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface uk.ac.rdg.resc.edal.domain.DiscreteDomain
getDomainObjects
-
Methods inherited from interface uk.ac.rdg.resc.edal.grid.ReferenceableAxis
getCoordinateValues, getName
-
-
-
-
Constructor Detail
-
RegularAxisImpl
public RegularAxisImpl(String name, double firstValue, double spacing, int size, boolean isLongitude)
-
-
Method Detail
-
wraps
public boolean wraps()
Description copied from interface:ReferenceableAxis
Returns true if the values on the axis wrap around (e.g. longitude)- Specified by:
wraps
in interfaceReferenceableAxis<Double>
-
getCoordinateSpacing
public double getCoordinateSpacing()
Description copied from interface:RegularAxis
Gets the spacing between coordinate values, might be negative.- Specified by:
getCoordinateSpacing
in interfaceRegularAxis
-
getCoordinateValue
public Double getCoordinateValue(int index)
Description copied from interface:ReferenceableAxis
Gets the coordinate value at the given index- Specified by:
getCoordinateValue
in interfaceReferenceableAxis<Double>
- Parameters:
index
- The index of the required position on the axis. Must be within the axis'extent
.- Returns:
- the coordinate value at the given index
-
size
public int size()
- Specified by:
size
in interfaceReferenceableAxis<Double>
- Returns:
- The extent of this axis. Indices within this axis will run from 0
to
ReferenceableAxis.size()
- 1
-
isAscending
public boolean isAscending()
Description copied from interface:ReferenceableAxis
Returns true if the values on the axis are in ascending order according to their natural ordering.- Specified by:
isAscending
in interfaceReferenceableAxis<Double>
-
getCoordinateBounds
public Extent<Double> getCoordinateBounds(int index)
Description copied from interface:ReferenceableAxis
Gets the coordinate bounds associated with the point at the given index. In some types of ReferenceableAxis, each point along the axis is associated with a range of positions, rather than a single infinitesimal position. This method returns this range.- Specified by:
getCoordinateBounds
in interfaceReferenceableAxis<Double>
- Returns:
- the coordinate bounds associated with the point at the given index. Returns an Extent with low=high if the bounds are infinitesimal. Never returns null.
-
getCoordinateExtent
public Extent<Double> getCoordinateExtent()
Description copied from interface:ReferenceableAxis
Gets the extent encompassing all the positions on this axis. This will usually be given by the low value of the first set ofcoordinate bounds
and the high value of the last set of coordinate bounds (but beware that values along the axis might decrease, not increase).- Specified by:
getCoordinateExtent
in interfaceReferenceableAxis<Double>
- Overrides:
getCoordinateExtent
in classAbstractReferenceableAxis<Double>
-
findIndexOf
public int findIndexOf(Double position)
Description copied from interface:ReferenceableAxis
Finds 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:
findIndexOf
in interfaceReferenceableAxis<Double>
- Returns:
- the index of the given coordinate value, or -1 if not found.
-
findIndexOfUnconstrained
public int findIndexOfUnconstrained(Double position)
Description copied from interface:RegularAxis
Finds the apparent index of a given position, even if this is beyond the bounds of the axis.- Specified by:
findIndexOfUnconstrained
in interfaceRegularAxis
- Parameters:
position
- The position to test.- Returns:
- The index where the position would appear, even if outside the bounds of this axis
-
extendFirstValue
protected Double extendFirstValue(Double firstVal, Double nextVal)
Description copied from class:AbstractReferenceableAxis
This 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:
extendFirstValue
in 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:AbstractReferenceableAxis
This 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:
extendLastValue
in 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
-
hashCode
public int hashCode()
- Specified by:
hashCode
in interfaceReferenceableAxis<Double>
- Overrides:
hashCode
in classAbstractReferenceableAxis<Double>
-
equals
public boolean equals(Object obj)
- Specified by:
equals
in interfaceReferenceableAxis<Double>
- Overrides:
equals
in classAbstractReferenceableAxis<Double>
-
-