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 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.intfindIndexOfUnconstrained(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.doublegetCoordinateSpacing()Gets the spacing between coordinate values, might be negative.DoublegetCoordinateValue(int index)Gets the coordinate value at the given indexinthashCode()booleanisAscending()Returns true if the values on the axis are in ascending order according to their natural ordering.intsize()StringtoString()booleanwraps()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:ReferenceableAxisReturns true if the values on the axis wrap around (e.g. longitude)- Specified by:
wrapsin interfaceReferenceableAxis<Double>
-
getCoordinateSpacing
public double getCoordinateSpacing()
Description copied from interface:RegularAxisGets the spacing between coordinate values, might be negative.- Specified by:
getCoordinateSpacingin interfaceRegularAxis
-
getCoordinateValue
public Double getCoordinateValue(int index)
Description copied from interface:ReferenceableAxisGets the coordinate value at the given index- Specified by:
getCoordinateValuein 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:
sizein 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:ReferenceableAxisReturns true if the values on the axis are in ascending order according to their natural ordering.- Specified by:
isAscendingin interfaceReferenceableAxis<Double>
-
getCoordinateBounds
public Extent<Double> getCoordinateBounds(int index)
Description copied from interface:ReferenceableAxisGets 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:
getCoordinateBoundsin 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:ReferenceableAxisGets the extent encompassing all the positions on this axis. This will usually be given by the low value of the first set ofcoordinate boundsand the high value of the last set of coordinate bounds (but beware that values along the axis might decrease, not increase).- Specified by:
getCoordinateExtentin interfaceReferenceableAxis<Double>- Overrides:
getCoordinateExtentin classAbstractReferenceableAxis<Double>
-
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>- Returns:
- the index of the given coordinate value, or -1 if not found.
-
findIndexOfUnconstrained
public int findIndexOfUnconstrained(Double position)
Description copied from interface:RegularAxisFinds the apparent index of a given position, even if this is beyond the bounds of the axis.- Specified by:
findIndexOfUnconstrainedin 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: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
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfaceReferenceableAxis<Double>- Overrides:
hashCodein classAbstractReferenceableAxis<Double>
-
equals
public boolean equals(Object obj)
- Specified by:
equalsin interfaceReferenceableAxis<Double>- Overrides:
equalsin classAbstractReferenceableAxis<Double>
-
-