eu.etaxonomy.cdm.model.common
Class TimePeriod

java.lang.Object
  extended by eu.etaxonomy.cdm.model.common.TimePeriod
All Implemented Interfaces:
Serializable, Cloneable

public class TimePeriod
extends Object
implements Cloneable, Serializable

Version:
1.0
Author:
m.doering
See Also:
Serialized Form

Field Summary
static org.joda.time.DateTimeFieldType DAY_TYPE
           
static org.joda.time.DateTimeFieldType MONTH_TYPE
           
static org.joda.time.DateTimeFieldType YEAR_TYPE
           
 
Constructor Summary
protected TimePeriod()
          Constructor
  TimePeriod(org.joda.time.Partial startDate)
           
  TimePeriod(org.joda.time.Partial startDate, org.joda.time.Partial endDate)
           
 
Method Summary
static org.joda.time.Partial calendarToPartial(Calendar calendar)
          Transforms a Calendar into a Partial
 Object clone()
           
 boolean equals(Object obj)
           
 org.joda.time.Partial getEnd()
           
 Integer getEndDay()
           
 Integer getEndMonth()
           
 Integer getEndYear()
           
 String getFreeText()
          For time periods that need to store more information than the one that can be stored in start and end.
static Integer getPartialValue(org.joda.time.Partial partial, org.joda.time.DateTimeFieldType type)
           
 org.joda.time.Partial getStart()
           
 Integer getStartDay()
           
 Integer getStartMonth()
           
 Integer getStartYear()
           
 String getYear()
           
 int hashCode()
           
 boolean isEmpty()
          True, if there is no start date and no end date and no freetext representation exists.
 boolean isPeriod()
          True, if this time period represents a period not a single point in time.
static TimePeriod NewInstance()
          Factory method
static TimePeriod NewInstance(Calendar startCalendar)
          Factory method to create a TimePeriod from a Calendar.
static TimePeriod NewInstance(Calendar startCalendar, Calendar endCalendar)
          Factory method to create a TimePeriod from a starting and an ending Calendar
static TimePeriod NewInstance(Integer year)
          Factory method
static TimePeriod NewInstance(Integer startYear, Integer endYear)
          Factory method
static TimePeriod NewInstance(org.joda.time.Partial startDate)
          Factory method
static TimePeriod NewInstance(org.joda.time.Partial startDate, org.joda.time.Partial endDate)
          Factory method
static TimePeriod NewInstance(org.joda.time.ReadableInstant readableInstant)
          Factory method to create a TimePeriod from a ReadableInstant(e.g.
static TimePeriod NewInstance(org.joda.time.ReadableInstant startInstant, org.joda.time.ReadableInstant endInstant)
          Factory method to create a TimePeriod from a starting and an ending ReadableInstant(e.g.
protected static org.joda.time.Partial parseSingleDate(String singleDateString)
           
protected static org.joda.time.Partial parseSingleDotDate(String singleDateString)
           
static TimePeriod parseString(String strPeriod)
           
static TimePeriod parseString(TimePeriod timePeriod, String periodString)
           
static org.joda.time.Partial readableInstantToPartial(org.joda.time.ReadableInstant readableInstant)
          Transforms a Calendar into a Partial
 void setEnd(org.joda.time.Partial end)
           
 TimePeriod setEndDay(Integer day)
           
 TimePeriod setEndMonth(Integer month)
           
 TimePeriod setEndYear(Integer year)
           
 void setFreeText(String freeText)
          Use parseSingleDate(String) for public use.
static org.joda.time.Partial setPartialField(org.joda.time.Partial partial, Integer value, org.joda.time.DateTimeFieldType type)
           
 void setStart(org.joda.time.Partial start)
           
 TimePeriod setStartDay(Integer day)
           
 TimePeriod setStartMonth(Integer month)
           
 TimePeriod setStartYear(Integer year)
           
 String toString()
          Returns the getFreeText() value if free text is not null.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MONTH_TYPE

public static final org.joda.time.DateTimeFieldType MONTH_TYPE

YEAR_TYPE

public static final org.joda.time.DateTimeFieldType YEAR_TYPE

DAY_TYPE

public static final org.joda.time.DateTimeFieldType DAY_TYPE
Constructor Detail

TimePeriod

protected TimePeriod()
Constructor


TimePeriod

public TimePeriod(org.joda.time.Partial startDate)

TimePeriod

public TimePeriod(org.joda.time.Partial startDate,
                  org.joda.time.Partial endDate)
Method Detail

NewInstance

public static TimePeriod NewInstance()
Factory method

Returns:

NewInstance

public static TimePeriod NewInstance(org.joda.time.Partial startDate)
Factory method

Returns:

NewInstance

public static TimePeriod NewInstance(org.joda.time.Partial startDate,
                                     org.joda.time.Partial endDate)
Factory method

Returns:

NewInstance

public static TimePeriod NewInstance(Integer year)
Factory method

Returns:

NewInstance

public static TimePeriod NewInstance(Integer startYear,
                                     Integer endYear)
Factory method

Returns:

NewInstance

public static TimePeriod NewInstance(Calendar startCalendar)
Factory method to create a TimePeriod from a Calendar. The Calendar is stored as the starting instant.

Returns:

NewInstance

public static TimePeriod NewInstance(org.joda.time.ReadableInstant readableInstant)
Factory method to create a TimePeriod from a ReadableInstant(e.g. DateTime). The ReadableInstant is stored as the starting instant.

Returns:

NewInstance

public static TimePeriod NewInstance(Calendar startCalendar,
                                     Calendar endCalendar)
Factory method to create a TimePeriod from a starting and an ending Calendar

Returns:

NewInstance

public static TimePeriod NewInstance(org.joda.time.ReadableInstant startInstant,
                                     org.joda.time.ReadableInstant endInstant)
Factory method to create a TimePeriod from a starting and an ending ReadableInstant(e.g. DateTime)

Returns:

calendarToPartial

public static org.joda.time.Partial calendarToPartial(Calendar calendar)
Transforms a Calendar into a Partial

Parameters:
calendar -
Returns:

readableInstantToPartial

public static org.joda.time.Partial readableInstantToPartial(org.joda.time.ReadableInstant readableInstant)
Transforms a Calendar into a Partial

Parameters:
calendar -
Returns:

isPeriod

public boolean isPeriod()
True, if this time period represents a period not a single point in time. This is by definition, that the time period has a start and an end value, and both have a year value that is not null

Returns:

isEmpty

public boolean isEmpty()
True, if there is no start date and no end date and no freetext representation exists.

Returns:

getStart

public org.joda.time.Partial getStart()

setStart

public void setStart(org.joda.time.Partial start)

getEnd

public org.joda.time.Partial getEnd()

setEnd

public void setEnd(org.joda.time.Partial end)

getFreeText

public String getFreeText()
For time periods that need to store more information than the one that can be stored in start and end. If free text is not null toString() will always return the free text value.
Use toString() for public use.

Returns:
the freeText

setFreeText

public void setFreeText(String freeText)
Use parseSingleDate(String) for public use.

Parameters:
freeText - the freeText to set

getYear

public String getYear()

getStartYear

public Integer getStartYear()

getStartMonth

public Integer getStartMonth()

getStartDay

public Integer getStartDay()

getEndYear

public Integer getEndYear()

getEndMonth

public Integer getEndMonth()

getEndDay

public Integer getEndDay()

getPartialValue

public static Integer getPartialValue(org.joda.time.Partial partial,
                                      org.joda.time.DateTimeFieldType type)

setStartYear

public TimePeriod setStartYear(Integer year)

setStartMonth

public TimePeriod setStartMonth(Integer month)
                         throws IndexOutOfBoundsException
Throws:
IndexOutOfBoundsException

setStartDay

public TimePeriod setStartDay(Integer day)
                       throws IndexOutOfBoundsException
Throws:
IndexOutOfBoundsException

setEndYear

public TimePeriod setEndYear(Integer year)

setEndMonth

public TimePeriod setEndMonth(Integer month)
                       throws IndexOutOfBoundsException
Throws:
IndexOutOfBoundsException

setEndDay

public TimePeriod setEndDay(Integer day)
                     throws IndexOutOfBoundsException
Throws:
IndexOutOfBoundsException

setPartialField

public static org.joda.time.Partial setPartialField(org.joda.time.Partial partial,
                                                    Integer value,
                                                    org.joda.time.DateTimeFieldType type)
                                             throws IndexOutOfBoundsException
Throws:
IndexOutOfBoundsException

parseString

public static TimePeriod parseString(TimePeriod timePeriod,
                                     String periodString)

parseString

public static TimePeriod parseString(String strPeriod)

parseSingleDate

protected static org.joda.time.Partial parseSingleDate(String singleDateString)
                                                throws IllegalArgumentException
Throws:
IllegalArgumentException

parseSingleDotDate

protected static org.joda.time.Partial parseSingleDotDate(String singleDateString)
                                                   throws IllegalArgumentException
Throws:
IllegalArgumentException

toString

public String toString()
Returns the getFreeText() value if free text is not null. Otherwise the concatenation of start and end is returned.

Overrides:
toString in class Object
See Also:
Object.toString()

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

clone

public Object clone()
Overrides:
clone in class Object


Copyright © 2007-2012 EDIT. All Rights Reserved.