org.tridas.io.util
Class AstronomicalYear

java.lang.Object
  extended by org.tridas.io.util.AstronomicalYear
All Implemented Interfaces:
Comparable

public final class AstronomicalYear
extends Object
implements Comparable

This is a year format using the astronomical conventions rather than BC/AD calendar. The value 0 is valid in the astronomical convention. 1 = 1AD 0 = 1BC -1 = 2BC Like Numbers and Strings, are immutable, so they are not Cloneable (there's no reason for them to be).


Field Summary
static AstronomicalYear DEFAULT
          The default year: 1001.
 
Constructor Summary
AstronomicalYear()
          Default constructor.
AstronomicalYear(int x)
          Constructor for ints.
AstronomicalYear(int row, int col)
          Constructor from (row,col) pair.
AstronomicalYear(SafeIntYear x)
          Construct a AstronomicalYear from a SafeIntYear.
AstronomicalYear(String s)
          Constructor from String.
AstronomicalYear(org.tridas.schema.Year x)
          Construct a AstronomicalYear from a native TridasYear.
 
Method Summary
 AstronomicalYear add(int dy)
          Adds (or subtracts, for negative values) some number of years, and generates a new Year object.
 int column()
          Determines what column this year would be, if years were in a grid 10 wide, with the left column years ending in zero.
 int compareTo(Object o)
          Compares this and o.
 int diff(AstronomicalYear y2)
          Calculate the number of years difference between two years.
 boolean equals(Object y2)
          Returns true if and only if this is equal to y2.
 int hashCode()
           
 int intValue()
          This method always throws UnsupportedOperationException.
 boolean isYearOne()
          Return true, iff this is year 1.
static AstronomicalYear max(AstronomicalYear y1, AstronomicalYear y2)
          The maximum (later) of two years.
static AstronomicalYear min(AstronomicalYear y1, AstronomicalYear y2)
          The minimum (earlier) of two years.
 int mod(int m)
          Computes this modulo m.
 int row()
          Determines what row this year would be, if years were in a grid 10 wide, with the left column years ending in zero.
 SafeIntYear toSafeIntYear()
           
 String toString()
          Convert to a String
 org.tridas.schema.Year toTridasYear(org.tridas.schema.DatingSuffix suffix)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT

public static final AstronomicalYear DEFAULT
The default year: 1001.

Constructor Detail

AstronomicalYear

public AstronomicalYear()
Default constructor. Uses DEFAULT as the year.

See Also:
DEFAULT

AstronomicalYear

public AstronomicalYear(int x)
Constructor for ints.

Parameters:
x - the year value, as an int
See Also:
DEFAULT

AstronomicalYear

public AstronomicalYear(org.tridas.schema.Year x)
Construct a AstronomicalYear from a native TridasYear. The TridasYear allows the use of suffixes (BP, AD, BC). problem.

Parameters:
x -

AstronomicalYear

public AstronomicalYear(SafeIntYear x)
Construct a AstronomicalYear from a SafeIntYear.

Parameters:
x -

AstronomicalYear

public AstronomicalYear(int row,
                        int col)
Constructor from (row,col) pair. Assumes 10-year rows. The column should always be between 0 and 9, inclusive.

Parameters:
row - the row; row 0 is the decade ending in year 9
col - the column; in row 0, year is the column

AstronomicalYear

public AstronomicalYear(String s)
                 throws NumberFormatException
Constructor from String. The string should be in astronomical format where 0 is valid and is equal to 1BC.

Throws:
NumberFormatException - if the String cannot be parsed
See Also:
String
Method Detail

toString

public String toString()
Convert to a String

Overrides:
toString in class Object
Returns:
this year as a String
See Also:
String

intValue

public int intValue()
This method always throws UnsupportedOperationException. It's not implemented, and don't even think about implementing it yourself! It encourages being lazy and bypassing Year's methods to just deal with ints. And that defeats the whole purpose of having Years. So I'll just disallow it. You don't need it anyway. If you really need the int for some reason I can't imagine, you can always do Integer.parseInt(y.toString()). That way you know you're doing it to get the int, and not for imagined performance or convenience reasons.

Returns:
never returns
Throws:
UnsupportedOperationException - always!

toTridasYear

public org.tridas.schema.Year toTridasYear(org.tridas.schema.DatingSuffix suffix)

toSafeIntYear

public SafeIntYear toSafeIntYear()

isYearOne

public boolean isYearOne()
Return true, iff this is year 1. (This actually comes up fairly often.)

Returns:
true iff this is year 1

max

public static AstronomicalYear max(AstronomicalYear y1,
                                   AstronomicalYear y2)
The maximum (later) of two years.

Returns:
the later of two years

min

public static AstronomicalYear min(AstronomicalYear y1,
                                   AstronomicalYear y2)
The minimum (earlier) of two years.

Returns:
the earlier of two years

add

public AstronomicalYear add(int dy)
Adds (or subtracts, for negative values) some number of years, and generates a new Year object.

Parameters:
dy - the number of years to add (subtract)
See Also:
diff(org.tridas.io.util.AstronomicalYear)

diff

public int diff(AstronomicalYear y2)
Calculate the number of years difference between two years. That is, there are this many years difference between this and y2; if they are equal, this number is zero.

Parameters:
y2 - the year to subtract
Returns:
the number of years difference between this and y2
See Also:
add(int)

mod

public int mod(int m)
Computes this modulo m. Always gives a positive result, even for negative numbers, so it is suitable for computing a grid position for a span of years.

Parameters:
m - base for modulo
Returns:
the year modulo m

row

public int row()
Determines what row this year would be, if years were in a grid 10 wide, with the left column years ending in zero. Row 0 is years 1 through 9.

Returns:
this year's row
See Also:
column()

column

public int column()
Determines what column this year would be, if years were in a grid 10 wide, with the left column years ending in zero. Works for BC years, also:
column() 0 1 2 3 4 5 6 7 8 9
Year -10 -9 -8 -7 -6 -5 -4 -3 -2 -1
1 2 3 4 5 6 7 8 9
10 11 12 13 14 15 16 17 18 19

Returns:
this year's column
See Also:
row()

compareTo

public int compareTo(Object o)
Compares this and o.

Specified by:
compareTo in interface Comparable
Parameters:
o - Object to compare
Returns:
>0, =0, or <0 if this is greater-than, equal-to, or less-than o
Throws:
ClassCastException - if o is not a Year
See Also:
Comparable

equals

public boolean equals(Object y2)
Returns true if and only if this is equal to y2.

Overrides:
equals in class Object
Parameters:
y2 - the year to compare this to
Returns:
true if this is equal to y2, else false

hashCode

public int hashCode()
Overrides:
hashCode in class Object


Copyright © 2011. All Rights Reserved.