Package org.jfree.data.time
Class Month
- java.lang.Object
-
- org.jfree.data.time.RegularTimePeriod
-
- org.jfree.data.time.Month
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable
,MonthConstants
,TimePeriod
public class Month extends RegularTimePeriod implements java.io.Serializable
Represents a single month. This class is immutable, which is a requirement for allRegularTimePeriod
subclasses.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private long
firstMillisecond
The first millisecond.private long
lastMillisecond
The last millisecond.private int
month
The month (1-12).private static long
serialVersionUID
For serialization.private int
year
The year in which the month falls.
-
Constructor Summary
Constructors Constructor Description Month()
Constructs a new Month, based on the current system time.Month(int month, int year)
Constructs a new month instance.Month(int month, Year year)
Constructs a new month instance.Month(java.util.Date time)
Constructs a newMonth
instance, based on a date/time.Month(java.util.Date time, java.util.Calendar calendar)
Constructs a new instance, based on a particular date/time.Month(java.util.Date time, java.util.TimeZone zone, java.util.Locale locale)
Creates a newMonth
instance, based on the specified time, zone and locale.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(java.lang.Object o1)
Returns an integer indicating the order of this Month object relative to the specified object: negative == before, zero == same, positive == after.boolean
equals(java.lang.Object obj)
Tests the equality of this Month object to an arbitrary object.private static Year
evaluateAsYear(java.lang.String s)
Creates a year from a string, or returnsnull
(format exceptions suppressed).private static int
findSeparator(java.lang.String s)
Finds the first occurrence of '-', or if that character is not found, the first occurrence of ',', or the first occurrence of ' ' or '.'long
getFirstMillisecond()
Returns the first millisecond of the month.long
getFirstMillisecond(java.util.Calendar calendar)
Returns the first millisecond of the month, evaluated using the supplied calendar (which determines the time zone).long
getLastMillisecond()
Returns the last millisecond of the month.long
getLastMillisecond(java.util.Calendar calendar)
Returns the last millisecond of the month, evaluated using the supplied calendar (which determines the time zone).int
getMonth()
Returns the month.long
getSerialIndex()
Returns a serial index number for the month.Year
getYear()
Returns the year in which the month falls.int
getYearValue()
Returns the year in which the month falls.int
hashCode()
Returns a hash code for this object instance.RegularTimePeriod
next()
Returns the month following this one.static Month
parseMonth(java.lang.String s)
Parses the string argument as a month.void
peg(java.util.Calendar calendar)
Recalculates the start date/time and end date/time for this time period relative to the supplied calendar (which incorporates a time zone).RegularTimePeriod
previous()
Returns the month preceding this one.java.lang.String
toString()
Returns a string representing the month (e.g.-
Methods inherited from class org.jfree.data.time.RegularTimePeriod
createInstance, downsize, getCalendarInstance, getEnd, getMiddleMillisecond, getMiddleMillisecond, getMillisecond, getStart, setCalendarInstancePrototype, setThreadLocalCalendarInstance
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
For serialization.- See Also:
- Constant Field Values
-
month
private int month
The month (1-12).
-
year
private int year
The year in which the month falls.
-
firstMillisecond
private long firstMillisecond
The first millisecond.
-
lastMillisecond
private long lastMillisecond
The last millisecond.
-
-
Constructor Detail
-
Month
public Month()
Constructs a new Month, based on the current system time. The time zone and locale are determined by the calendar returned byRegularTimePeriod.getCalendarInstance()
.
-
Month
public Month(int month, int year)
Constructs a new month instance. The time zone and locale are determined by the calendar returned byRegularTimePeriod.getCalendarInstance()
.- Parameters:
month
- the month (in the range 1 to 12).year
- the year.
-
Month
public Month(int month, Year year)
Constructs a new month instance. The time zone and locale are determined by the calendar returned byRegularTimePeriod.getCalendarInstance()
.- Parameters:
month
- the month (in the range 1 to 12).year
- the year.
-
Month
public Month(java.util.Date time)
Constructs a newMonth
instance, based on a date/time. The time zone and locale are determined by the calendar returned byRegularTimePeriod.getCalendarInstance()
.- Parameters:
time
- the date/time (null
not permitted).- See Also:
Month(Date, TimeZone, Locale)
-
Month
public Month(java.util.Date time, java.util.TimeZone zone, java.util.Locale locale)
Creates a newMonth
instance, based on the specified time, zone and locale.- Parameters:
time
- the current time.zone
- the time zone.locale
- the locale.
-
Month
public Month(java.util.Date time, java.util.Calendar calendar)
Constructs a new instance, based on a particular date/time. The time zone and locale are determined by thecalendar
parameter.- Parameters:
time
- the date/time (null
not permitted).calendar
- the calendar to use for calculations (null
not permitted).
-
-
Method Detail
-
getYear
public Year getYear()
Returns the year in which the month falls.- Returns:
- The year in which the month falls (as a Year object).
-
getYearValue
public int getYearValue()
Returns the year in which the month falls.- Returns:
- The year in which the month falls (as an int).
-
getMonth
public int getMonth()
Returns the month. Note that 1=JAN, 2=FEB, ...- Returns:
- The month.
-
getFirstMillisecond
public long getFirstMillisecond()
Returns the first millisecond of the month. This will be determined relative to the time zone specified in the constructor, or in the calendar instance passed in the most recent call to thepeg(Calendar)
method.- Specified by:
getFirstMillisecond
in classRegularTimePeriod
- Returns:
- The first millisecond of the month.
- See Also:
getLastMillisecond()
-
getLastMillisecond
public long getLastMillisecond()
Returns the last millisecond of the month. This will be determined relative to the time zone specified in the constructor, or in the calendar instance passed in the most recent call to thepeg(Calendar)
method.- Specified by:
getLastMillisecond
in classRegularTimePeriod
- Returns:
- The last millisecond of the month.
- See Also:
getFirstMillisecond()
-
peg
public void peg(java.util.Calendar calendar)
Recalculates the start date/time and end date/time for this time period relative to the supplied calendar (which incorporates a time zone).- Specified by:
peg
in classRegularTimePeriod
- Parameters:
calendar
- the calendar (null
not permitted).
-
previous
public RegularTimePeriod previous()
Returns the month preceding this one. Note that the returnedMonth
is "pegged" using the default calendar, obtained withRegularTimePeriod.getCalendarInstance()
, irrespective of the time-zone used to peg of the current month (which is not recorded anywhere). See thepeg(Calendar)
method.- Specified by:
previous
in classRegularTimePeriod
- Returns:
- The month preceding this one.
-
next
public RegularTimePeriod next()
Returns the month following this one. Note that the returnedMonth
is "pegged" using the default calendar, obtained withRegularTimePeriod.getCalendarInstance()
, irrespective of the time-zone used to peg of the current month (which is not recorded anywhere). See thepeg(Calendar)
method.- Specified by:
next
in classRegularTimePeriod
- Returns:
- The month following this one.
-
getSerialIndex
public long getSerialIndex()
Returns a serial index number for the month.- Specified by:
getSerialIndex
in classRegularTimePeriod
- Returns:
- The serial index number.
-
toString
public java.lang.String toString()
Returns a string representing the month (e.g. "January 2002").To do: look at internationalisation.
- Overrides:
toString
in classRegularTimePeriod
- Returns:
- A string representing the month.
-
equals
public boolean equals(java.lang.Object obj)
Tests the equality of this Month object to an arbitrary object. Returns true if the target is a Month instance representing the same month as this object. In all other cases, returns false.- Overrides:
equals
in classjava.lang.Object
- Parameters:
obj
- the object (null
permitted).- Returns:
true
if month and year of this and object are the same.
-
hashCode
public int hashCode()
Returns a hash code for this object instance. The approach described by Joshua Bloch in "Effective Java" has been used here:http://developer.java.sun.com/developer/Books/effectivejava /Chapter3.pdf
- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- A hash code.
-
compareTo
public int compareTo(java.lang.Object o1)
Returns an integer indicating the order of this Month object relative to the specified object: negative == before, zero == same, positive == after.- Specified by:
compareTo
in interfacejava.lang.Comparable
- Parameters:
o1
- the object to compare.- Returns:
- negative == before, zero == same, positive == after.
-
getFirstMillisecond
public long getFirstMillisecond(java.util.Calendar calendar)
Returns the first millisecond of the month, evaluated using the supplied calendar (which determines the time zone).- Specified by:
getFirstMillisecond
in classRegularTimePeriod
- Parameters:
calendar
- the calendar (null
not permitted).- Returns:
- The first millisecond of the month.
- Throws:
java.lang.NullPointerException
- ifcalendar
isnull
.- See Also:
RegularTimePeriod.getLastMillisecond(Calendar)
-
getLastMillisecond
public long getLastMillisecond(java.util.Calendar calendar)
Returns the last millisecond of the month, evaluated using the supplied calendar (which determines the time zone).- Specified by:
getLastMillisecond
in classRegularTimePeriod
- Parameters:
calendar
- the calendar (null
not permitted).- Returns:
- The last millisecond of the month.
- Throws:
java.lang.NullPointerException
- ifcalendar
isnull
.- See Also:
RegularTimePeriod.getFirstMillisecond(Calendar)
-
parseMonth
public static Month parseMonth(java.lang.String s)
Parses the string argument as a month. This method is required to accept the format "YYYY-MM". It will also accept "MM-YYYY". Anything else, at the moment, is a bonus.- Parameters:
s
- the string to parse (null
permitted).- Returns:
null
if the string is not parseable, the month otherwise.
-
findSeparator
private static int findSeparator(java.lang.String s)
Finds the first occurrence of '-', or if that character is not found, the first occurrence of ',', or the first occurrence of ' ' or '.'- Parameters:
s
- the string to parse.- Returns:
- The position of the separator character, or
-1
if none of the characters were found.
-
evaluateAsYear
private static Year evaluateAsYear(java.lang.String s)
Creates a year from a string, or returnsnull
(format exceptions suppressed).- Parameters:
s
- the string to parse.- Returns:
null
if the string is not parseable, the year otherwise.
-
-