com.Ostermiller.util Java Utilities


com.Ostermiller.util
Class YearExtensionAround

java.lang.Object
  extended by com.Ostermiller.util.YearExtensionAround
All Implemented Interfaces:
YearExtensionPolicy

public class YearExtensionAround
extends Object
implements YearExtensionPolicy

Extend years like '99 to 1999 based on dates around the current date.

Since:
ostermillerutils 1.08.00
Author:
Stephen Ostermiller http://ostermiller.org/contact.pl?regarding=Java+Utilities

Field Summary
static YearExtensionAround CENTURY_1900
          Extend a two digit year to a year in the 1900s 00 to 1900 01 to 1901 49 to 1949 50 to 1950 99 to 1999
static YearExtensionAround CENTURY_2000
          Extend a two digit year to a year in the 2000s 00 to 2000 01 to 2001 49 to 2049 50 to 2050 99 to 2099
static YearExtensionAround LATEST
          Extend a two digit year to the nearest year that ends in those two digits.
static YearExtensionAround NEAREST
          Extend a two digit year to the nearest year that ends in those two digits.
 
Constructor Summary
YearExtensionAround(int allowedYearsInPast)
          Create a year extension nearest policy with the current year taken from the system time.
YearExtensionAround(int allowedYearsInPast, int currentYear)
          Create a year extension nearest policy with the given current year
 
Method Summary
 int extendYear(int twoDigitYear)
          Extend a two digit year to the nearest year that ends in those two digits.
static YearExtensionAround getLatest(int currentYear)
          Extend a two digit year to the nearest year that ends in those two digits.
static YearExtensionAround getNearest(int currentYear)
          Extend a two digit year to the nearest year that ends in those two digits.
 void setAllowedYearsInPast(int allowedYearsInPast)
          Number of years in the past to allow dates
 void setCurrentYear(int currentYear)
          Set the current year.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NEAREST

public static final YearExtensionAround NEAREST
Extend a two digit year to the nearest year that ends in those two digits.

When it is the year 2000:

Since:
ostermillerutils 1.08.00

LATEST

public static final YearExtensionAround LATEST
Extend a two digit year to the nearest year that ends in those two digits.

When it is the year 2000:

Since:
ostermillerutils 1.08.00

CENTURY_1900

public static final YearExtensionAround CENTURY_1900
Extend a two digit year to a year in the 1900s

Since:
ostermillerutils 1.08.00

CENTURY_2000

public static final YearExtensionAround CENTURY_2000
Extend a two digit year to a year in the 2000s

Since:
ostermillerutils 1.08.00
Constructor Detail

YearExtensionAround

public YearExtensionAround(int allowedYearsInPast)
Create a year extension nearest policy with the current year taken from the system time.

Since:
ostermillerutils 1.08.00

YearExtensionAround

public YearExtensionAround(int allowedYearsInPast,
                           int currentYear)
Create a year extension nearest policy with the given current year

Parameters:
currentYear - full year eg 2000
Since:
ostermillerutils 1.08.00
Method Detail

getNearest

public static final YearExtensionAround getNearest(int currentYear)
Extend a two digit year to the nearest year that ends in those two digits.

When it is the year 2000:

Parameters:
currentYear - the current year
Since:
ostermillerutils 1.08.00

getLatest

public static final YearExtensionAround getLatest(int currentYear)
Extend a two digit year to the nearest year that ends in those two digits.

When it is the year 2000:

Parameters:
currentYear - the current year
Since:
ostermillerutils 1.08.00

setAllowedYearsInPast

public void setAllowedYearsInPast(int allowedYearsInPast)
Number of years in the past to allow dates

Parameters:
allowedYearsInPast - number between 0 and 99

setCurrentYear

public void setCurrentYear(int currentYear)
Set the current year.

Parameters:
currentYear - full year eg 2000
Since:
ostermillerutils 1.08.00

extendYear

public int extendYear(int twoDigitYear)
Extend a two digit year to the nearest year that ends in those two digits.

Will choose a year within 100 years of the current year. Whether the year is in the past or future is determined by how many years are allowed in the past.

Specified by:
extendYear in interface YearExtensionPolicy
Parameters:
twoDigitYear - year from 0 to 99
Returns:
Full year representation
Since:
ostermillerutils 1.08.00

com.Ostermiller.util Java Utilities


Copyright © 2001-2012 by Stephen Ostermiller