net.sf.jga.fn.string
Class ParseFormat<R>

java.lang.Object
  extended by net.sf.jga.fn.Functor<R>
      extended by net.sf.jga.fn.UnaryFunctor<java.lang.String,R>
          extended by net.sf.jga.fn.string.ParseFormat<R>
All Implemented Interfaces:
java.io.Serializable, Visitable
Direct Known Subclasses:
ParseFormat.Date, ParseFormat.Number

public class ParseFormat<R>
extends UnaryFunctor<java.lang.String,R>

Unary Functor that parses a given Format.

Copyright © 2003-2005 David A. Hall

Author:
David A. Hall
See Also:
Serialized Form

Nested Class Summary
static class ParseFormat.Date<T extends java.util.Date>
          ParseFormat functor for use with Dates.
static class ParseFormat.Number<T extends java.lang.Number>
          ParseFormat functor for use with Numbers.
static interface ParseFormat.Visitor
          Interface for classes that may interpret a ParseFormat predicate.
 
Constructor Summary
protected ParseFormat(java.text.Format format, UnaryFunctor<java.lang.Object,R> conv)
          Builds the ParseFormat given a text Format and a functor that can convert Objects returned by the Format's parse(Object) method and the desired type of this functor.
 
Method Summary
 void accept(Visitor v)
          Calls the Visitor's visit(ParseFormat) method, if it implements the nested Visitor interface.
 R fn(java.lang.String arg)
          Parses the value from the given string, using the java.text.Format object passed at construction.
 java.text.Format getFormat()
           
 java.lang.String toString()
           
 
Methods inherited from class net.sf.jga.fn.UnaryFunctor
bind, bind0th, bindNth, compose, compose, compose, composeNth, composeNth, eval, generate, generateNth
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ParseFormat

protected ParseFormat(java.text.Format format,
                      UnaryFunctor<java.lang.Object,R> conv)
Builds the ParseFormat given a text Format and a functor that can convert Objects returned by the Format's parse(Object) method and the desired type of this functor.

Method Detail

getFormat

public java.text.Format getFormat()
Returns:
the format used to parse values

fn

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

Specified by:
fn in class UnaryFunctor<java.lang.String,R>
Parameters:
arg - formatted string to be parsed
Returns:
the value that the string represented
Throws:
java.text.ParseException - when the string cannot be parsed to the correct type

accept

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

Specified by:
accept in interface Visitable
Overrides:
accept in class Functor<R>

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2002-2006 David A. Hall. All Rights Reserved.