package uk.ac.leeds.ccg.andyt.projects.genesis.utilities; //import java.lang.Comparable; public class Time implements Comparable { public static final int _Normal_Days_In_Year = 365; public static final int _Normal_Seconds_In_Day = 60 * 60 * 24; public int _Year; public int _DayOfYear; public int _SecondOfDay; public Time() { } public Time(Time _Time) { _Year = _Time._Year; _DayOfYear = _Time._DayOfYear; _SecondOfDay = _Time._SecondOfDay; } public Time( int _Year, int _DayOfYear, int _SecondOfDay) { this._Year = _Year; this._DayOfYear = _DayOfYear; this._SecondOfDay = _SecondOfDay; } public Time( int _Year, int _DayOfYear) { this._Year = _Year; this._DayOfYear = _DayOfYear; this._SecondOfDay = 0; } public static void main(String[] args) { Time _Time0 = new Time(1, 10); Time _Time1 = new Time(10, 1); Time _Time0_Difference_Time1 = _Time0._Difference(_Time1); Time _Time1_Difference_Time0 = _Time1._Difference(_Time0); System.out.println("_Time0_Difference_Time1 " + _Time0_Difference_Time1); System.out.println("_Time1_Difference_Time0 " + _Time1_Difference_Time0); } public void _Increment_Day() { if (_DayOfYear == _Normal_Days_In_Year - 1) { _DayOfYear = 0; _Year++; } else { _DayOfYear++; } } public Time _Difference(Time _Time) { Time result = new Time(); result._SecondOfDay = this._SecondOfDay - _Time._SecondOfDay; result._DayOfYear = this._DayOfYear - _Time._DayOfYear; result._Year = this._Year - _Time._Year; int compareTo_Time = this.compareTo(_Time); if ( compareTo_Time == 1) { if (result._SecondOfDay < 0) { result._SecondOfDay += _Normal_Seconds_In_Day; result._DayOfYear--; } if (result._DayOfYear < 0) { result._DayOfYear += _Normal_Days_In_Year; result._Year--; } return result; } if ( compareTo_Time == -1) { if (result._SecondOfDay > 0) { result._SecondOfDay -= _Normal_Seconds_In_Day; result._DayOfYear++; } if (result._DayOfYear > 0) { result._DayOfYear -= _Normal_Days_In_Year; result._Year++; } } return result; } @Override public String toString() { return new String("_Year " + _Year + ", _DayOfYear " + _DayOfYear + ", _SecondOfDay " + _SecondOfDay); } public int compareTo(Object _Object) { if (_Object instanceof Time) { Time _Time_Object = (Time) _Object; if (this._Year < _Time_Object._Year) { return -1; } else { if (this._Year == _Time_Object._Year) { if (this._DayOfYear < _Time_Object._DayOfYear) { return -1; } else { if (this._DayOfYear == _Time_Object._DayOfYear) { if (this._SecondOfDay < _Time_Object._SecondOfDay) { return -1; } else { if (this._SecondOfDay == _Time_Object._SecondOfDay) { return 0; } } } } } } } return 1; } @Override public boolean equals(Object _Object) { if (_Object instanceof Time) { Time _Object_Time = (Time) _Object; return _Object_Time._Year == this._Year && _Object_Time._DayOfYear == this._DayOfYear && _Object_Time._SecondOfDay == this._SecondOfDay; } return false; } @Override public int hashCode() { int hash = 5; hash = 37 * hash + this._Year; hash = 37 * hash + this._DayOfYear; hash = 37 * hash + this._SecondOfDay; return hash; } }