net.sf.jga.fn.string

Class ParseFormat<R>

public class ParseFormat<R> extends AbstractUnaryFunctor<String,R> implements Serializable

Unary Functor that parses a given text format.

Note that declaring the return type incorrectly can result in a ClassCastException being thrown when the functor is invoked: the compiler cannot check the return type.

Copyright © 2003 David A. Hall

Author: David A. Hall

Nested Class Summary
interfaceParseFormat.Visitor
Interface for classes that may interpret a ParseFormat predicate.
Constructor Summary
ParseFormat(Format format)
Builds a functor that will create instances of the given class by parsing string argument with the given text format.
Method Summary
voidaccept(Visitor v)
Calls the Visitor's visit(ParseFormat) method, if it implements the nested Visitor interface.
Rfn(String arg)
Parses the value from the given string, using the java.text.Format object passed at construction.
FormatgetFormat()
StringtoString()

Constructor Detail

ParseFormat

public ParseFormat(Format format)
Builds a functor that will create instances of the given class by parsing string argument with the given text format. The generic type of the functor must be the class (or a superclass) of the type of objects returned by the text format. For example ParseFormat parser = new ParseFormat(DateFormat.getDateInstance());

Throws: IllegalArgumentException if either argument is omitted

Method Detail

accept

public void accept(Visitor v)
Calls the Visitor's visit(ParseFormat) method, if it implements the nested Visitor interface.

fn

public R fn(String arg)
Parses the value from the given string, using the java.text.Format object passed at construction.

Parameters: arg formatted string to be parsed

Returns: the value that the string represented

getFormat

public Format getFormat()

Returns: the format used to parse values

toString

public String toString()