|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.tridas.io.util.SafeIntYear
public final class SafeIntYear
A BC/AD calendar year in the form of a signed integer It normally acts similar to an integer, but skips the mythical "year 0".
In SafeIntYear
math:
Years, like Numbers and Strings, are immutable, so they are not Cloneable (there's no reason for them to be).
Field Summary | |
---|---|
static SafeIntYear |
DEFAULT
The default year: 1. |
Constructor Summary | |
---|---|
SafeIntYear()
Default constructor. |
|
SafeIntYear(int x)
Constructor for int s. |
|
SafeIntYear(int row,
int col)
Constructor from (row,col) pair. |
|
SafeIntYear(String s)
Constructor from String. |
|
SafeIntYear(String s,
boolean isAstronomical)
Constructor from String. |
|
SafeIntYear(org.tridas.schema.Year x)
Construct a SafeIntYear from a native TridasYear. |
Method Summary | |
---|---|
SafeIntYear |
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 . |
SafeIntYear |
cropToCentury()
|
int |
diff(SafeIntYear 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 SafeIntYear |
max(SafeIntYear y1,
SafeIntYear y2)
The maximum (later) of two years. |
static SafeIntYear |
min(SafeIntYear y1,
SafeIntYear y2)
The minimum (earlier) of two years. |
int |
mod(int m)
Computes this modulo m . |
SafeIntYear |
nextCentury()
|
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. |
Integer |
toAstronomicalInteger()
Returns this SafeIntYear as an integer using the astronomical convention for BC years. |
AstronomicalYear |
toAstronomicalYear()
Convert to an AstronomicalYear where 0 is valid and is equal to 1BC. |
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 |
---|
public static final SafeIntYear DEFAULT
Constructor Detail |
---|
public SafeIntYear()
DEFAULT
as the year.
DEFAULT
public SafeIntYear(int x)
int
s. Uses DEFAULT
as the year
if an invalid value is passed.
x
- the year value, as an intDEFAULT
public SafeIntYear(org.tridas.schema.Year x)
x
- public SafeIntYear(int row, int col)
row
- the row; row 0 is the decade ending in year 9col
- the column; in row 0, year is the columnpublic SafeIntYear(String s) throws NumberFormatException
scanf(" %d ", &y)
would.
NumberFormatException
- if the String cannot be parsed, or is equal to zeroString
public SafeIntYear(String s, boolean isAstronomical) throws NumberFormatException
scanf(" %d ", &y)
would. If isAstronomical is true, then it subtracts 1 from all values which are <=0.
i.e., -5 means 6 BC.
NumberFormatException
- if the String cannot be parsedString
Method Detail |
---|
public String toString()
toString
in class Object
String
public int intValue()
Integer.parseInt(y.toString())
. That way you know you're
doing it to get the int, and not for imagined performance or convenience
reasons.
UnsupportedOperationException
- always!public org.tridas.schema.Year toTridasYear(org.tridas.schema.DatingSuffix suffix)
public AstronomicalYear toAstronomicalYear()
public Integer toAstronomicalInteger()
public boolean isYearOne()
public static SafeIntYear max(SafeIntYear y1, SafeIntYear y2)
public static SafeIntYear min(SafeIntYear y1, SafeIntYear y2)
public SafeIntYear add(int dy)
dy
- the number of years to add (subtract)diff(org.tridas.io.util.SafeIntYear)
public int diff(SafeIntYear y2)
this
and y2
;
if they are equal, this number is zero.
y2
- the year to subtract
this
and
y2
add(int)
public int mod(int m)
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.
m
- base for modulo
m
public int row()
column()
public int column()
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 |
row()
public int compareTo(Object o)
o
.
compareTo
in interface Comparable
o
- Object to compare
ClassCastException
- if o is not a YearComparable
public boolean equals(Object y2)
true
if and only if this
is equal to
y2
.
equals
in class Object
y2
- the year to compare this
to
true
if this
is equal to y2
, else
false
public int hashCode()
hashCode
in class Object
public SafeIntYear cropToCentury()
public SafeIntYear nextCentury()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |