Package org.jfree.chart.axis
Class DateTickUnit
- java.lang.Object
-
- org.jfree.chart.axis.TickUnit
-
- org.jfree.chart.axis.DateTickUnit
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable
public class DateTickUnit extends TickUnit implements java.io.Serializable
A tick unit for use by subclasses ofDateAxis. Instances of this class are immutable.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private intcountThe unit count.private java.text.DateFormatformatterThe date formatter.private introllCountThe roll count.private DateTickUnitTyperollUnitTypeThe roll unit type.private static longserialVersionUIDFor serialization.private DateTickUnitTypeunitTypeThe units.
-
Constructor Summary
Constructors Constructor Description DateTickUnit(DateTickUnitType unitType, int multiple)Creates a new date tick unit.DateTickUnit(DateTickUnitType unitType, int multiple, java.text.DateFormat formatter)Creates a new date tick unit.DateTickUnit(DateTickUnitType unitType, int multiple, DateTickUnitType rollUnitType, int rollMultiple, java.text.DateFormat formatter)Creates a new unit.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.DateaddToDate(java.util.Date base, java.util.TimeZone zone)Calculates a new date by adding this unit to the base date.java.lang.StringdateToString(java.util.Date date)Formats a date using the tick unit's formatter.booleanequals(java.lang.Object obj)Tests this unit for equality with another object.intgetCalendarField()Returns a field code that can be used with theCalendarclass.private static longgetMillisecondCount(DateTickUnitType unit, int count)Returns the (approximate) number of milliseconds for the given unit and unit count.intgetMultiple()Returns the unit multiple.intgetRollMultiple()Returns the roll unit multiple.DateTickUnitTypegetRollUnitType()Returns the roll unit type.DateTickUnitTypegetUnitType()Returns the unit type.inthashCode()Returns a hash code for this object.java.util.DaterollDate(java.util.Date base)Rolls the date forward by the amount specified by the roll unit and count.java.util.DaterollDate(java.util.Date base, java.util.TimeZone zone)Rolls the date forward by the amount specified by the roll unit and count.java.lang.StringtoString()Returns a string representation of this instance, primarily used for debugging purposes.java.lang.StringvalueToString(double milliseconds)Formats a value.-
Methods inherited from class org.jfree.chart.axis.TickUnit
compareTo, getMinorTickCount, getSize
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
For serialization.- See Also:
- Constant Field Values
-
unitType
private DateTickUnitType unitType
The units.
-
count
private int count
The unit count.
-
rollUnitType
private DateTickUnitType rollUnitType
The roll unit type.
-
rollCount
private int rollCount
The roll count.
-
formatter
private java.text.DateFormat formatter
The date formatter.
-
-
Constructor Detail
-
DateTickUnit
public DateTickUnit(DateTickUnitType unitType, int multiple)
Creates a new date tick unit.- Parameters:
unitType- the unit type (nullnot permitted).multiple- the multiple (of the unit type, must be > 0).
-
DateTickUnit
public DateTickUnit(DateTickUnitType unitType, int multiple, java.text.DateFormat formatter)
Creates a new date tick unit.- Parameters:
unitType- the unit type (nullnot permitted).multiple- the multiple (of the unit type, must be > 0).formatter- the date formatter (nullnot permitted).
-
DateTickUnit
public DateTickUnit(DateTickUnitType unitType, int multiple, DateTickUnitType rollUnitType, int rollMultiple, java.text.DateFormat formatter)
Creates a new unit.- Parameters:
unitType- the unit.multiple- the multiple.rollUnitType- the roll unit.rollMultiple- the roll multiple.formatter- the date formatter (nullnot permitted).
-
-
Method Detail
-
getUnitType
public DateTickUnitType getUnitType()
Returns the unit type.- Returns:
- The unit type (never
null).
-
getMultiple
public int getMultiple()
Returns the unit multiple.- Returns:
- The unit multiple (always > 0).
-
getRollUnitType
public DateTickUnitType getRollUnitType()
Returns the roll unit type.- Returns:
- The roll unit type (never
null).
-
getRollMultiple
public int getRollMultiple()
Returns the roll unit multiple.- Returns:
- The roll unit multiple.
-
valueToString
public java.lang.String valueToString(double milliseconds)
Formats a value.- Overrides:
valueToStringin classTickUnit- Parameters:
milliseconds- date in milliseconds since 01-01-1970.- Returns:
- The formatted date.
-
dateToString
public java.lang.String dateToString(java.util.Date date)
Formats a date using the tick unit's formatter.- Parameters:
date- the date.- Returns:
- The formatted date.
-
addToDate
public java.util.Date addToDate(java.util.Date base, java.util.TimeZone zone)Calculates a new date by adding this unit to the base date.- Parameters:
base- the base date.zone- the time zone for the date calculation.- Returns:
- A new date one unit after the base date.
-
rollDate
public java.util.Date rollDate(java.util.Date base)
Rolls the date forward by the amount specified by the roll unit and count.- Parameters:
base- the base date.- Returns:
- The rolled date.
- See Also:
rollDate(Date, TimeZone)
-
rollDate
public java.util.Date rollDate(java.util.Date base, java.util.TimeZone zone)Rolls the date forward by the amount specified by the roll unit and count.- Parameters:
base- the base date.zone- the time zone.- Returns:
- The rolled date.
-
getCalendarField
public int getCalendarField()
Returns a field code that can be used with theCalendarclass.- Returns:
- The field code.
-
getMillisecondCount
private static long getMillisecondCount(DateTickUnitType unit, int count)
Returns the (approximate) number of milliseconds for the given unit and unit count.This value is an approximation some of the time (e.g. months are assumed to have 31 days) but this shouldn't matter.
- Parameters:
unit- the unit.count- the unit count.- Returns:
- The number of milliseconds.
-
equals
public boolean equals(java.lang.Object obj)
Tests this unit for equality with another object.
-
hashCode
public int hashCode()
Returns a hash code for this object.
-
toString
public java.lang.String toString()
Returns a string representation of this instance, primarily used for debugging purposes.- Overrides:
toStringin classjava.lang.Object- Returns:
- A string representation of this instance.
-
-