anon.crypto
Class Validity

java.lang.Object
  extended by anon.crypto.Validity

public class Validity
extends java.lang.Object

Describes the validity period of something by defining a start date (valid from) and an end date (valid to). The validity can then be tested for a given date.

Author:
Rolf Wendolsky

Field Summary
private  java.util.Calendar m_validFrom
           
private  java.util.Calendar m_validTo
           
private static int TEMPORARY_VALIDITY_IN_MINUTES
          This is the minimal time (in minutes) for a validity created by createValidTo().
 
Constructor Summary
Validity(java.util.Calendar a_validFrom, java.util.Calendar a_validTo)
          Creates a new Validity.
Validity(java.util.Calendar a_validFrom, int a_validityInYears)
          Creates a new Validity.
 
Method Summary
private static java.util.Calendar createValidTo(java.util.Calendar a_validFrom, int a_validityInYears)
          For a given Calendar object that represents a start date (valid from), this method creates an end date (valid to) that lies a specified amount of years ahead from the start date.
 java.util.Date getValidFrom()
          Returns the first valid date in the validity period.
 java.util.Date getValidTo()
          Returns the last valid date in the validity period.
 boolean isValid(java.util.Date a_date)
          Checks if the given date is contained in the validity period.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_validFrom

private java.util.Calendar m_validFrom

m_validTo

private java.util.Calendar m_validTo

TEMPORARY_VALIDITY_IN_MINUTES

private static final int TEMPORARY_VALIDITY_IN_MINUTES
This is the minimal time (in minutes) for a validity created by createValidTo().

See Also:
Constant Field Values
Constructor Detail

Validity

public Validity(java.util.Calendar a_validFrom,
                int a_validityInYears)
Creates a new Validity.

Parameters:
a_validFrom - a Calendar object that represents a start date
a_validityInYears - an amount of years that the created date should lie ahead from the start date; if the amount is less than 0 the created date will only be ahead from the start date for a very small time (some minutes)
Throws:
java.lang.IllegalArgumentException - if the calendar is null

Validity

public Validity(java.util.Calendar a_validFrom,
                java.util.Calendar a_validTo)
Creates a new Validity.

Parameters:
a_validFrom - a Calendar object that represents a start date
a_validTo - a Calendar object that represents a end date; if the date lies before the start date it will be set equal to the start date
Throws:
java.lang.IllegalArgumentException - if on of the calendars is null
Method Detail

getValidFrom

public java.util.Date getValidFrom()
Returns the first valid date in the validity period.

Returns:
the first valid date in the validity period

getValidTo

public java.util.Date getValidTo()
Returns the last valid date in the validity period.

Returns:
the last valid date in the validity period

isValid

public boolean isValid(java.util.Date a_date)
Checks if the given date is contained in the validity period.

Parameters:
a_date - a Date
Returns:
true if the given date is contained in the validity period; false otherwise

createValidTo

private static java.util.Calendar createValidTo(java.util.Calendar a_validFrom,
                                                int a_validityInYears)
For a given Calendar object that represents a start date (valid from), this method creates an end date (valid to) that lies a specified amount of years ahead from the start date.

Parameters:
a_validFrom - a Calendar object that represents a start date
a_validityInYears - an amount of years that the created date should lie ahead from the start date; if the amount is less than 0 the created date will only be ahead from the start date for a very small time (some minutes)
Returns:
an end date (valid to) that lies a specified amount of years ahead from the start date