| java.lang.Object org.joda.time.format.PeriodFormatter
PeriodFormatter | public class PeriodFormatter (Code) | | Controls the printing and parsing of a time period to and from a string.
This class is the main API for printing and parsing used by most applications.
Instances of this class are created via one of three factory classes:
An instance of this class holds a reference internally to one printer and
one parser. It is possible that one of these may be null, in which case the
formatter cannot print/parse. This can be checked via the
PeriodFormatter.isPrinter() and
PeriodFormatter.isParser() methods.
The underlying printer/parser can be altered to behave exactly as required
by using a decorator modifier:
This returns a new formatter (instances of this class are immutable).
The main methods of the class are the printXxx and
parseXxx methods. These are used as follows:
// print using the default locale
String periodStr = formatter.print(period);
// print using the French locale
String periodStr = formatter.withLocale(Locale.FRENCH).print(period);
// parse using the French locale
Period date = formatter.withLocale(Locale.FRENCH).parsePeriod(str);
author: Brian S O'Neill author: Stephen Colebourne since: 1.0 |
PeriodFormatter | public PeriodFormatter(PeriodPrinter printer, PeriodParser parser)(Code) | | Creates a new formatter, however you will normally use the factory
or the builder.
Parameters: printer - the internal printer, null if cannot print Parameters: parser - the internal parser, null if cannot parse |
getLocale | public Locale getLocale()(Code) | | Gets the locale that will be used for printing and parsing.
the locale to use |
getParseType | public PeriodType getParseType()(Code) | | Gets the PeriodType that will be used for parsing.
the parse type to use |
getParser | public PeriodParser getParser()(Code) | | Gets the internal parser object that performs the real parsing work.
the internal parser |
getPrinter | public PeriodPrinter getPrinter()(Code) | | Gets the internal printer object that performs the real printing work.
the internal printer |
isParser | public boolean isParser()(Code) | | Is this formatter capable of parsing.
true if this is a parser |
isPrinter | public boolean isPrinter()(Code) | | Is this formatter capable of printing.
true if this is a printer |
parseInto | public int parseInto(ReadWritablePeriod period, String text, int position)(Code) | | Parses a period from the given text, at the given position, saving the
result into the fields of the given ReadWritablePeriod. If the parse
succeeds, the return value is the new text position. Note that the parse
may succeed without fully reading the text.
The parse type of the formatter is not used by this method.
If it fails, the return value is negative, but the period may still be
modified. To determine the position where the parse failed, apply the
one's complement operator (~) on the return value.
Parameters: period - a period that will be modified Parameters: text - text to parse Parameters: position - position to start parsing from new position, if negative, parse failed. Apply complementoperator (~) to get position of failure throws: IllegalArgumentException - if any field is out of range |
parseMutablePeriod | public MutablePeriod parseMutablePeriod(String text)(Code) | | Parses a period from the given text, returning a new MutablePeriod.
Parameters: text - text to parse parsed value in a MutablePeriod object throws: IllegalArgumentException - if any field is out of range |
parsePeriod | public Period parsePeriod(String text)(Code) | | Parses a period from the given text, returning a new Period.
Parameters: text - text to parse parsed value in a Period object throws: IllegalArgumentException - if any field is out of range |
print | public String print(ReadablePeriod period)(Code) | | Prints a ReadablePeriod to a new String.
Parameters: period - the period to format, not null the printed result |
printTo | public void printTo(StringBuffer buf, ReadablePeriod period)(Code) | | Prints a ReadablePeriod to a StringBuffer.
Parameters: buf - the formatted period is appended to this buffer Parameters: period - the period to format, not null |
printTo | public void printTo(Writer out, ReadablePeriod period) throws IOException(Code) | | Prints a ReadablePeriod to a Writer.
Parameters: out - the formatted period is written out Parameters: period - the period to format, not null |
withLocale | public PeriodFormatter withLocale(Locale locale)(Code) | | Returns a new formatter with a different locale that will be used
for printing and parsing.
A PeriodFormatter is immutable, so a new instance is returned,
and the original is unaltered and still usable.
Parameters: locale - the locale to use the new formatter |
withParseType | public PeriodFormatter withParseType(PeriodType type)(Code) | | Returns a new formatter with a different PeriodType for parsing.
A PeriodFormatter is immutable, so a new instance is returned,
and the original is unaltered and still usable.
Parameters: type - the type to use in parsing the new formatter |
|
|