com.soft9000.dates
Class DateJulian

java.lang.Object
  extended by com.soft9000.dates.DateJulian
All Implemented Interfaces:
java.lang.Comparable<DateJulian>

public class DateJulian
extends java.lang.Object
implements java.lang.Comparable<DateJulian>

Opportunity to create a day + year reference as a REFLEXIVE INTEGRAL Julian-Date. You can download the source for this class at Soft9000.com

Based around the Roman concept of "no zero", the first day of an era starts at day 1, year 1. The day before that is day 1, year -1.

Under Nagy's REFLEXIVE INTEGRAL encoding, NO assumption is made about what we are attempting to record: Your relative passage of days could be before / after the 'UNIX Epoch', Runic Era, Gregorian Event, Roman Rise / Fall, BC/AD, or the days before / since you met your cat... -Whatever enumerated context you care to mark as "Day 1", this Julian convention works both before and after the day, in the same way... for a LONG time! (i.e. Feel free to change the integral type to LONG if / when desired.)

REFLEXIVE INTEGRAL Julian-Dates are user-WYSIWYG. -What you write, is what you encode:

NOTES ON NULL STATE MANAGEMENT: Note that incrementing or decrementing out of the NULL state is both expected, and supported. Once so enrolled in "real time" however, no combination of inc() or dec() will ever restore an object to the said isNull() state.

JUSTIFICATION: In order to remain truly event-reflexive, an ex nihilo - or spontaneously-generated event - is the very essence of encoding a "no-zero," or "big bang," type of milestone.

Indeed, one can effectively argue - in certain circumstances - that until any unscheduled - yet noteworthy event - has actually begun, that tracking relative-time can simply have no practical value or meaning at-all. -In such cosmic circumstance therefore, relative time-measurement only becomes significant immediately after said event has taken place.

The test case is here.


Field Summary
static int FIRST_NEGATIVE_DAY
           
static int FIRST_POSITIVE_DAY
           
 
Constructor Summary
DateJulian()
          The NULL Constructor.
DateJulian(DateJulian ref)
          Copy constructor.
DateJulian(int iTest)
          WYSIWYG Construction.
DateJulian(java.lang.String sTest)
          WYSIWYG Construction.
 
Method Summary
 void addDays(int iDays)
          Add a given number of days to this instance.
 void addYears(int iYears)
          Add a given number of years to this instance.
 int compareTo(DateJulian ref)
          Obligatory comparison.
 void dec()
          Decrement the present interval.
 boolean encodeJulian(int iTest)
          Encode a REFLEXIVE INTEGRAL Julian integer.
 boolean encodeJulian(int year, int jday)
          Encode a REFLEXIVE INTEGRAL Julian day + year.
 boolean equals(DateJulian ref)
          WYSIWYG - Convenience Comparison.
 boolean equals(int icomp)
          WYSIWYG - Convenience Comparison.
 boolean equals(java.lang.String str)
          WYSIWYG - Convenience Comparison.
 boolean fromString(java.lang.String str)
          Convert a suspected toString() representation.
static DateJulian GetComplement(DateJulian ref)
          Return the equa-distant "other side" of a DateJulian.
 int getDay()
          Decode the day.
 int getEncoded()
          Get the properly encoded value.
 int getLastDay()
          Return the last Julian-day-number for the present given year.
static int GetLastDay(int iYear)
          Return the last Julian-day-number for a REFLEXIVE INTEGRAL year-encoding.
 int getMaxYear()
          Returns 'almost' the last year available.
 int getYear()
          Decode the year.
 void inc()
          Increment the present interval.
 boolean isAfter()
          Determine if the encoding 'isAfter' the event took place.
 boolean isBefore()
          Determine if the encoding 'isBefore' the event took place.
 boolean isNull()
          Determine if this instance has been assigned a meaningful value.
 void removeDays(int iDays)
          Remove a given number of days from this instance.
 void removeYears(int iYears)
          Remove a given number of years from this instance.
 void setFirstDay()
          Retreat to the first day of the year.
 void setLastDay()
          Advance to the end of the year.
 void setYearComplement()
          Invert the year - (hence the name "reflexive",) downward-adjusting (only downward, never upward) for the end-of-year, as required.
 java.lang.String toString()
          Convert the payload (integer) to a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FIRST_POSITIVE_DAY

public static final int FIRST_POSITIVE_DAY
See Also:
Constant Field Values

FIRST_NEGATIVE_DAY

public static final int FIRST_NEGATIVE_DAY
See Also:
Constant Field Values
Constructor Detail

DateJulian

public DateJulian()
The NULL Constructor. Once created, inc() and dec() will work properly, as well.


DateJulian

public DateJulian(DateJulian ref)
Copy constructor.

Parameters:
ref - A DateJulian

DateJulian

public DateJulian(int iTest)
WYSIWYG Construction. Will only encode if valid. Check isNull() to determine construction result.

Parameters:
iTest - An integer. Cannot be zero OR less than getLastDay().

DateJulian

public DateJulian(java.lang.String sTest)
WYSIWYG Construction. Will only encode if valid. Check isNull() to determine construction result.

Parameters:
sTest - A String. Presumed to be a product of toStirng().
Method Detail

inc

public void inc()
Increment the present interval. isNull() is managed properly.


dec

public void dec()
Decrement the present interval. isNull() is managed properly.


addDays

public void addDays(int iDays)
Add a given number of days to this instance.

Parameters:
iDays - The number of days to add.

removeDays

public void removeDays(int iDays)
Remove a given number of days from this instance.

Parameters:
iDays - The number of days to remove.

addYears

public void addYears(int iYears)
Add a given number of years to this instance.

Parameters:
iYears - The number of years to add.

removeYears

public void removeYears(int iYears)
Remove a given number of years from this instance.

Parameters:
iYears - The number of years to remove.

toString

public java.lang.String toString()
Convert the payload (integer) to a string. The string is WYSIWYG: It will match an integral encoding.

Overrides:
toString in class java.lang.Object
Returns:
The string representation for whatever this instance contains.

fromString

public boolean fromString(java.lang.String str)
Convert a suspected toString() representation. The string is WYSIWYG: It will match an integral encoding.

Parameters:
str - A suspected toString() representation.
Returns:
True if encoded properly to this instance. False on error + isNull().

getEncoded

public int getEncoded()
Get the properly encoded value.

Returns:
-1 if the instance isNull()

isNull

public boolean isNull()
Determine if this instance has been assigned a meaningful value. Using inc() and dec() will either perminately advance, or perminately retreat, away from the isNull() state.

Returns:
True if this instance is usable. False otherwise.

getDay

public int getDay()
Decode the day.

Returns:
Te day, or -1 on error.

getYear

public int getYear()
Decode the year.

Returns:
The year, or -1 on error.

encodeJulian

public boolean encodeJulian(int year,
                            int jday)
Encode a REFLEXIVE INTEGRAL Julian day + year.

Parameters:
year - The year (error if zero)
jday - The day (error if zero or negative)
Returns:
True if encoded properly to this instance. False on error + isNull().

encodeJulian

public boolean encodeJulian(int iTest)
Encode a REFLEXIVE INTEGRAL Julian integer.

Parameters:
iTest - An integer, as suspected of being properly encoded. Cannot be < -1001 or < 1001.
Returns:
True if encoded properly to this instance. False on error + isNull().

getMaxYear

public int getMaxYear()
Returns 'almost' the last year available. (We reserve one on either side of the +/- range).

Returns:
The maximum on the 1's based, reflexive-year-encodings, possible.

getLastDay

public int getLastDay()
Return the last Julian-day-number for the present given year. Either 365 or 366.

Returns:
The last day. Will be 366 (the potentia) when the date isNull(), or in a leap-year.

GetLastDay

public static int GetLastDay(int iYear)
Return the last Julian-day-number for a REFLEXIVE INTEGRAL year-encoding. Result will be either 365 or 366.

Parameters:
iYear - A REFLEXIVE INTEGRAL year (before event < 0, after event > 0.) Zero is considered NULL. Submitting a NULL value will always return the potentia.
Returns:
Either 365 or 366.

equals

public boolean equals(java.lang.String str)
WYSIWYG - Convenience Comparison.

Parameters:
str - The pattern as a String.
Returns:
True on equity.

equals

public boolean equals(int icomp)
WYSIWYG - Convenience Comparison.

Parameters:
str - The pattern as an integer.
Returns:
True on equity.

equals

public boolean equals(DateJulian ref)
WYSIWYG - Convenience Comparison.

Parameters:
ref - The pattern as another object.
Returns:
True on equity.

compareTo

public int compareTo(DateJulian ref)
Obligatory comparison.

Specified by:
compareTo in interface java.lang.Comparable<DateJulian>
Parameters:
refo - Comparator (subject)
Returns:
Return 0 on equality, negative on less, positive on greater.

setLastDay

public void setLastDay()
Advance to the end of the year.


setFirstDay

public void setFirstDay()
Retreat to the first day of the year.


isBefore

public boolean isBefore()
Determine if the encoding 'isBefore' the event took place.

Returns:
True if the encoded time is BEFORE the event.

isAfter

public boolean isAfter()
Determine if the encoding 'isAfter' the event took place.

Returns:
True if the encoded time is AFTER the event.

setYearComplement

public void setYearComplement()
Invert the year - (hence the name "reflexive",) downward-adjusting (only downward, never upward) for the end-of-year, as required.


GetComplement

public static DateJulian GetComplement(DateJulian ref)
Return the equa-distant "other side" of a DateJulian.

Parameters:
ref - The subject to invert.
Returns:
The complement (inversion) of the DateJulian provided.