Java Doc for PeriodFormatterBuilder.java in  » Development » Joda-Time » org » joda » time » format » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Development » Joda Time » org.joda.time.format 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.joda.time.format.PeriodFormatterBuilder

PeriodFormatterBuilder
public class PeriodFormatterBuilder (Code)
Factory that creates complex instances of PeriodFormatter via method calls.

Period formatting is performed by the PeriodFormatter class. Three classes provide factory methods to create formatters, and this is one. The others are PeriodFormat and ISOPeriodFormat .

PeriodFormatterBuilder is used for constructing formatters which are then used to print or parse. The formatters are built by appending specific fields or other formatters to an instance of this builder.

For example, a formatter that prints years and months, like "15 years and 8 months", can be constructed as follows:

 PeriodFormatter yearsAndMonths = new PeriodFormatterBuilder()
 .printZeroAlways()
 .appendYears()
 .appendSuffix(" year", " years")
 .appendSeparator(" and ")
 .printZeroRarely()
 .appendMonths()
 .appendSuffix(" month", " months")
 .toFormatter();
 

PeriodFormatterBuilder itself is mutable and not thread-safe, but the formatters that it builds are thread-safe and immutable.
author:
   Brian S O'Neill
since:
   1.0
See Also:   PeriodFormat


Inner Class :static interface PeriodFieldAffix
Inner Class :static class SimpleAffix implements PeriodFieldAffix
Inner Class :static class PluralAffix implements PeriodFieldAffix
Inner Class :static class CompositeAffix implements PeriodFieldAffix
Inner Class :static class FieldFormatter implements PeriodPrinter,PeriodParser
Inner Class :static class Literal implements PeriodPrinter,PeriodParser
Inner Class :static class Separator implements PeriodPrinter,PeriodParser
Inner Class :static class Composite implements PeriodPrinter,PeriodParser


Constructor Summary
public  PeriodFormatterBuilder()
    

Method Summary
public  PeriodFormatterBuilderappend(PeriodFormatter formatter)
     Appends another formatter.
public  PeriodFormatterBuilderappend(PeriodPrinter printer, PeriodParser parser)
     Appends a printer parser pair.
public  PeriodFormatterBuilderappendDays()
     Instruct the printer to emit an integer days field, if supported.
public  PeriodFormatterBuilderappendHours()
     Instruct the printer to emit an integer hours field, if supported.
public  PeriodFormatterBuilderappendLiteral(String text)
     Instructs the printer to emit specific text, and the parser to expect it.
public  PeriodFormatterBuilderappendMillis()
     Instruct the printer to emit an integer millis field, if supported.
public  PeriodFormatterBuilderappendMillis3Digit()
     Instruct the printer to emit an integer millis field, if supported.
public  PeriodFormatterBuilderappendMinutes()
     Instruct the printer to emit an integer minutes field, if supported.
public  PeriodFormatterBuilderappendMonths()
     Instruct the printer to emit an integer months field, if supported.
public  PeriodFormatterBuilderappendPrefix(String text)
     Append a field prefix which applies only to the next appended field.
public  PeriodFormatterBuilderappendPrefix(String singularText, String pluralText)
     Append a field prefix which applies only to the next appended field.
public  PeriodFormatterBuilderappendSeconds()
     Instruct the printer to emit an integer seconds field, if supported.
public  PeriodFormatterBuilderappendSecondsWithMillis()
     Instruct the printer to emit a combined seconds and millis field, if supported.
public  PeriodFormatterBuilderappendSecondsWithOptionalMillis()
     Instruct the printer to emit a combined seconds and millis field, if supported.
public  PeriodFormatterBuilderappendSeparator(String text)
     Append a separator, which is output if fields are printed both before and after the separator.
public  PeriodFormatterBuilderappendSeparator(String text, String finalText)
     Append a separator, which is output if fields are printed both before and after the separator.
public  PeriodFormatterBuilderappendSeparator(String text, String finalText, String[] variants)
     Append a separator, which is output if fields are printed both before and after the separator.
public  PeriodFormatterBuilderappendSeparatorIfFieldsAfter(String text)
     Append a separator, which is output only if fields are printed after the separator.
public  PeriodFormatterBuilderappendSeparatorIfFieldsBefore(String text)
     Append a separator, which is output only if fields are printed before the separator.
public  PeriodFormatterBuilderappendSuffix(String text)
     Append a field suffix which applies only to the last appended field.
public  PeriodFormatterBuilderappendSuffix(String singularText, String pluralText)
     Append a field suffix which applies only to the last appended field.
public  PeriodFormatterBuilderappendWeeks()
     Instruct the printer to emit an integer weeks field, if supported.
public  PeriodFormatterBuilderappendYears()
     Instruct the printer to emit an integer years field, if supported.
public  voidclear()
     Clears out all the appended elements, allowing this builder to be reused.
public  PeriodFormatterBuildermaximumParsedDigits(int maxDigits)
     Set the maximum digits parsed for the next and following appended fields.
public  PeriodFormatterBuilderminimumPrintedDigits(int minDigits)
     Set the minimum digits printed for the next and following appended fields.
public  PeriodFormatterBuilderprintZeroAlways()
     Always print zero values for the next and following appended fields, even if the period doesn't support it.
public  PeriodFormatterBuilderprintZeroIfSupported()
     Print zero values for the next and following appened fields only if the period supports it.
public  PeriodFormatterBuilderprintZeroNever()
     Never print zero values for the next and following appended fields, unless no fields would be printed.
public  PeriodFormatterBuilderprintZeroRarelyFirst()
     Never print zero values for the next and following appended fields, unless no fields would be printed.
public  PeriodFormatterBuilderprintZeroRarelyLast()
     Never print zero values for the next and following appended fields, unless no fields would be printed.
public  PeriodFormatterBuilderrejectSignedValues(boolean v)
     Reject signed values when parsing the next and following appended fields.
public  PeriodFormattertoFormatter()
     Constructs a PeriodFormatter using all the appended elements.
public  PeriodParsertoParser()
     Internal method to create a PeriodParser instance using all the appended elements.
public  PeriodPrintertoPrinter()
     Internal method to create a PeriodPrinter instance using all the appended elements.


Constructor Detail
PeriodFormatterBuilder
public PeriodFormatterBuilder()(Code)




Method Detail
append
public PeriodFormatterBuilder append(PeriodFormatter formatter)(Code)
Appends another formatter. this PeriodFormatterBuilder



append
public PeriodFormatterBuilder append(PeriodPrinter printer, PeriodParser parser)(Code)
Appends a printer parser pair.

Either the printer or the parser may be null, in which case the builder will be unable to produce a parser or printer repectively.
Parameters:
  printer - appends a printer to the builder, null if printing is not supported
Parameters:
  parser - appends a parser to the builder, null if parsing is not supported this PeriodFormatterBuilder
throws:
  IllegalArgumentException - if both the printer and parser are null




appendDays
public PeriodFormatterBuilder appendDays()(Code)
Instruct the printer to emit an integer days field, if supported.

The number of printed and parsed digits can be controlled using PeriodFormatterBuilder.minimumPrintedDigits(int) and PeriodFormatterBuilder.maximumParsedDigits(int) . this PeriodFormatterBuilder




appendHours
public PeriodFormatterBuilder appendHours()(Code)
Instruct the printer to emit an integer hours field, if supported.

The number of printed and parsed digits can be controlled using PeriodFormatterBuilder.minimumPrintedDigits(int) and PeriodFormatterBuilder.maximumParsedDigits(int) . this PeriodFormatterBuilder




appendLiteral
public PeriodFormatterBuilder appendLiteral(String text)(Code)
Instructs the printer to emit specific text, and the parser to expect it. The parser is case-insensitive. this PeriodFormatterBuilder
throws:
  IllegalArgumentException - if text is null



appendMillis
public PeriodFormatterBuilder appendMillis()(Code)
Instruct the printer to emit an integer millis field, if supported.

The number of printed and parsed digits can be controlled using PeriodFormatterBuilder.minimumPrintedDigits(int) and PeriodFormatterBuilder.maximumParsedDigits(int) . this PeriodFormatterBuilder




appendMillis3Digit
public PeriodFormatterBuilder appendMillis3Digit()(Code)
Instruct the printer to emit an integer millis field, if supported.

The number of arsed digits can be controlled using PeriodFormatterBuilder.maximumParsedDigits(int) . this PeriodFormatterBuilder




appendMinutes
public PeriodFormatterBuilder appendMinutes()(Code)
Instruct the printer to emit an integer minutes field, if supported.

The number of printed and parsed digits can be controlled using PeriodFormatterBuilder.minimumPrintedDigits(int) and PeriodFormatterBuilder.maximumParsedDigits(int) . this PeriodFormatterBuilder




appendMonths
public PeriodFormatterBuilder appendMonths()(Code)
Instruct the printer to emit an integer months field, if supported.

The number of printed and parsed digits can be controlled using PeriodFormatterBuilder.minimumPrintedDigits(int) and PeriodFormatterBuilder.maximumParsedDigits(int) . this PeriodFormatterBuilder




appendPrefix
public PeriodFormatterBuilder appendPrefix(String text)(Code)
Append a field prefix which applies only to the next appended field. If the field is not printed, neither is the prefix.
Parameters:
  text - text to print before field only if field is printed this PeriodFormatterBuilder
See Also:   PeriodFormatterBuilder.appendSuffix



appendPrefix
public PeriodFormatterBuilder appendPrefix(String singularText, String pluralText)(Code)
Append a field prefix which applies only to the next appended field. If the field is not printed, neither is the prefix.

During parsing, the singular and plural versions are accepted whether or not the actual value matches plurality.
Parameters:
  singularText - text to print if field value is one
Parameters:
  pluralText - text to print if field value is not one this PeriodFormatterBuilder
See Also:   PeriodFormatterBuilder.appendSuffix




appendSeconds
public PeriodFormatterBuilder appendSeconds()(Code)
Instruct the printer to emit an integer seconds field, if supported.

The number of printed and parsed digits can be controlled using PeriodFormatterBuilder.minimumPrintedDigits(int) and PeriodFormatterBuilder.maximumParsedDigits(int) . this PeriodFormatterBuilder




appendSecondsWithMillis
public PeriodFormatterBuilder appendSecondsWithMillis()(Code)
Instruct the printer to emit a combined seconds and millis field, if supported. The millis will overflow into the seconds if necessary. The millis are always output. this PeriodFormatterBuilder



appendSecondsWithOptionalMillis
public PeriodFormatterBuilder appendSecondsWithOptionalMillis()(Code)
Instruct the printer to emit a combined seconds and millis field, if supported. The millis will overflow into the seconds if necessary. The millis are only output if non-zero. this PeriodFormatterBuilder



appendSeparator
public PeriodFormatterBuilder appendSeparator(String text)(Code)
Append a separator, which is output if fields are printed both before and after the separator.

For example, builder.appendDays().appendSeparator(",").appendHours() will only output the comma if both the days and hours fields are output.

The text will be parsed case-insensitively.

Note: appending a separator discontinues any further work on the latest appended field.
Parameters:
  text - the text to use as a separator this PeriodFormatterBuilder
throws:
  IllegalStateException - if this separator follows a previous one




appendSeparator
public PeriodFormatterBuilder appendSeparator(String text, String finalText)(Code)
Append a separator, which is output if fields are printed both before and after the separator.

This method changes the separator depending on whether it is the last separator to be output.

For example, builder.appendDays().appendSeparator(",", "&").appendHours().appendSeparator(",", "&").appendMinutes() will output '1,2&3' if all three fields are output, '1&2' if two fields are output and '1' if just one field is output.

The text will be parsed case-insensitively.

Note: appending a separator discontinues any further work on the latest appended field.
Parameters:
  text - the text to use as a separator
Parameters:
  finalText - the text used used if this is the final separator to be printed this PeriodFormatterBuilder
throws:
  IllegalStateException - if this separator follows a previous one




appendSeparator
public PeriodFormatterBuilder appendSeparator(String text, String finalText, String[] variants)(Code)
Append a separator, which is output if fields are printed both before and after the separator.

This method changes the separator depending on whether it is the last separator to be output.

For example, builder.appendDays().appendSeparator(",", "&").appendHours().appendSeparator(",", "&").appendMinutes() will output '1,2&3' if all three fields are output, '1&2' if two fields are output and '1' if just one field is output.

The text will be parsed case-insensitively.

Note: appending a separator discontinues any further work on the latest appended field.
Parameters:
  text - the text to use as a separator
Parameters:
  finalText - the text used used if this is the final separator to be printed
Parameters:
  variants - set of text values which are also acceptable when parsed this PeriodFormatterBuilder
throws:
  IllegalStateException - if this separator follows a previous one




appendSeparatorIfFieldsAfter
public PeriodFormatterBuilder appendSeparatorIfFieldsAfter(String text)(Code)
Append a separator, which is output only if fields are printed after the separator.

For example, builder.appendDays().appendSeparatorIfFieldsAfter(",").appendHours() will only output the comma if the hours fields is output.

The text will be parsed case-insensitively.

Note: appending a separator discontinues any further work on the latest appended field.
Parameters:
  text - the text to use as a separator this PeriodFormatterBuilder
throws:
  IllegalStateException - if this separator follows a previous one




appendSeparatorIfFieldsBefore
public PeriodFormatterBuilder appendSeparatorIfFieldsBefore(String text)(Code)
Append a separator, which is output only if fields are printed before the separator.

For example, builder.appendDays().appendSeparatorIfFieldsBefore(",").appendHours() will only output the comma if the days fields is output.

The text will be parsed case-insensitively.

Note: appending a separator discontinues any further work on the latest appended field.
Parameters:
  text - the text to use as a separator this PeriodFormatterBuilder
throws:
  IllegalStateException - if this separator follows a previous one




appendSuffix
public PeriodFormatterBuilder appendSuffix(String text)(Code)
Append a field suffix which applies only to the last appended field. If the field is not printed, neither is the suffix.
Parameters:
  text - text to print after field only if field is printed this PeriodFormatterBuilder
throws:
  IllegalStateException - if no field exists to append to
See Also:   PeriodFormatterBuilder.appendPrefix



appendSuffix
public PeriodFormatterBuilder appendSuffix(String singularText, String pluralText)(Code)
Append a field suffix which applies only to the last appended field. If the field is not printed, neither is the suffix.

During parsing, the singular and plural versions are accepted whether or not the actual value matches plurality.
Parameters:
  singularText - text to print if field value is one
Parameters:
  pluralText - text to print if field value is not one this PeriodFormatterBuilder
throws:
  IllegalStateException - if no field exists to append to
See Also:   PeriodFormatterBuilder.appendPrefix




appendWeeks
public PeriodFormatterBuilder appendWeeks()(Code)
Instruct the printer to emit an integer weeks field, if supported.

The number of printed and parsed digits can be controlled using PeriodFormatterBuilder.minimumPrintedDigits(int) and PeriodFormatterBuilder.maximumParsedDigits(int) . this PeriodFormatterBuilder




appendYears
public PeriodFormatterBuilder appendYears()(Code)
Instruct the printer to emit an integer years field, if supported.

The number of printed and parsed digits can be controlled using PeriodFormatterBuilder.minimumPrintedDigits(int) and PeriodFormatterBuilder.maximumParsedDigits(int) . this PeriodFormatterBuilder




clear
public void clear()(Code)
Clears out all the appended elements, allowing this builder to be reused.



maximumParsedDigits
public PeriodFormatterBuilder maximumParsedDigits(int maxDigits)(Code)
Set the maximum digits parsed for the next and following appended fields. By default, the maximum digits parsed is ten. this PeriodFormatterBuilder



minimumPrintedDigits
public PeriodFormatterBuilder minimumPrintedDigits(int minDigits)(Code)
Set the minimum digits printed for the next and following appended fields. By default, the minimum digits printed is one. If the field value is zero, it is not printed unless a printZero rule is applied. this PeriodFormatterBuilder



printZeroAlways
public PeriodFormatterBuilder printZeroAlways()(Code)
Always print zero values for the next and following appended fields, even if the period doesn't support it. The parser requires values for fields that always print zero. this PeriodFormatterBuilder



printZeroIfSupported
public PeriodFormatterBuilder printZeroIfSupported()(Code)
Print zero values for the next and following appened fields only if the period supports it. this PeriodFormatterBuilder



printZeroNever
public PeriodFormatterBuilder printZeroNever()(Code)
Never print zero values for the next and following appended fields, unless no fields would be printed. If no fields are printed, the printer forces the last "printZeroRarely" field to print a zero.

This field setting is the default. this PeriodFormatterBuilder




printZeroRarelyFirst
public PeriodFormatterBuilder printZeroRarelyFirst()(Code)
Never print zero values for the next and following appended fields, unless no fields would be printed. If no fields are printed, the printer forces the first "printZeroRarely" field to print a zero. this PeriodFormatterBuilder



printZeroRarelyLast
public PeriodFormatterBuilder printZeroRarelyLast()(Code)
Never print zero values for the next and following appended fields, unless no fields would be printed. If no fields are printed, the printer forces the last "printZeroRarely" field to print a zero.

This field setting is the default. this PeriodFormatterBuilder




rejectSignedValues
public PeriodFormatterBuilder rejectSignedValues(boolean v)(Code)
Reject signed values when parsing the next and following appended fields. this PeriodFormatterBuilder



toFormatter
public PeriodFormatter toFormatter()(Code)
Constructs a PeriodFormatter using all the appended elements.

This is the main method used by applications at the end of the build process to create a usable formatter.

Subsequent changes to this builder do not affect the returned formatter.

The returned formatter may not support both printing and parsing. The methods PeriodFormatter.isPrinter and PeriodFormatter.isParser will help you determine the state of the formatter. the newly created formatter
throws:
  IllegalStateException - if the builder can produce neither a printer nor a parser




toParser
public PeriodParser toParser()(Code)
Internal method to create a PeriodParser instance using all the appended elements.

Most applications will not use this method. If you want a printer in an application, call PeriodFormatterBuilder.toFormatter() and just use the printing API.

Subsequent changes to this builder do not affect the returned parser. the newly created parser, null if builder cannot create a parser




toPrinter
public PeriodPrinter toPrinter()(Code)
Internal method to create a PeriodPrinter instance using all the appended elements.

Most applications will not use this method. If you want a printer in an application, call PeriodFormatterBuilder.toFormatter() and just use the printing API.

Subsequent changes to this builder do not affect the returned printer. the newly created printer, null if builder cannot create a printer




Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.