ICU-6447 First pass at fixes to MessageFormat

X-SVN-Rev: 26473
This commit is contained in:
Mark Davis 2009-08-07 01:17:33 +00:00
parent e23963cb67
commit 66b106094d
7 changed files with 146 additions and 5 deletions

View file

@ -0,0 +1,15 @@
/*
*******************************************************************************
* Copyright (C) 2009, Google, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.text;
/**
* @author markdavis
*
*/
public interface BaseFormat<T, U extends Appendable, S extends CharSequence> extends Formatter<T, U>, Parser<T, S> {
}

View file

@ -0,0 +1,50 @@
/*
*******************************************************************************
* Copyright (C) 2009, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.text;
import java.text.FieldPosition;
/**
* General Interface for formatting.
* @author markdavis
*/
public interface Formatter<T, U extends Appendable> {
/**
* Formats an object to produce a string. This is equivalent to
* <blockquote>
* {@link #format(Object, Appendable, FieldPosition)}<code>(obj,
* new StringBuilder(), new FieldPosition(0)).toString();</code>
* </blockquote>
*
* @param obj The object to format
* @return Formatted string.
* @exception IllegalArgumentException if the Format cannot format the given
* object
* @draft ICU 4.4
*/
public String format (T obj);
/**
* Formats an object and appends the resulting text to a given {@link java.lang.Appendable}.
* If the <code>pos</code> argument identifies a field used by the format,
* then its indices are set to the beginning and end of the first such
* field encountered.
*
* @param obj The object to format
* @param toAppendTo where the text is to be appended
* @param pos A <code>FieldPosition</code> identifying a field
* in the formatted text
* @return the {@link java.lang.Appendable} passed in as <code>toAppendTo</code>,
* with formatted text appended
* @exception NullPointerException if <code>toAppendTo</code> or
* <code>pos</code> is null
* @exception IllegalArgumentException if the Format cannot format the given
* object. If the Appendable throws an exception, then the cause is that exception.
* @draft ICU 4.4
*/
public U format(T obj, U toAppendTo, FieldPosition pos);
}

View file

@ -393,7 +393,7 @@ import com.ibm.icu.util.ULocale;
// TODO: Update JavaDoc class description with regards to named arguments.
// TODO: Update JavaDoc class description with regards to PluralFormat
// integration.
public class MessageFormat extends UFormat {
public class MessageFormat extends UFormat implements BaseFormat<Object,StringBuffer,String> {
// Generated by serialver from JDK 1.4.1_01
static final long serialVersionUID = 7136212545847378651L;

View file

@ -0,0 +1,50 @@
/*
*******************************************************************************
* Copyright (C) 2009, Google, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.text;
import java.text.ParseException;
import java.text.ParsePosition;
/**
* @author markdavis
*
*/
public interface Parser<T, S extends CharSequence> {
/**
* Parses text from the beginning of the given string to produce an object.
* The method may not use the entire text of the given string.
*
* @param source A <code>String</code> whose beginning should be parsed.
* @return An <code>Object</code> parsed from the string.
* @exception ParseException if the beginning of the specified string
* cannot be parsed.
*/
public T parseObject(S source) throws ParseException;
/**
* Parses text from a string to produce an object.
* <p>
* The method attempts to parse text starting at the index given by
* <code>pos</code>.
* If parsing succeeds, then the index of <code>pos</code> is updated
* to the index after the last character used (parsing does not necessarily
* use all characters up to the end of the string), and the parsed
* object is returned. The updated <code>pos</code> can be used to
* indicate the starting point for the next call to this method.
* If an error occurs, then the index of <code>pos</code> is not
* changed, the error index of <code>pos</code> is set to the index of
* the character where the error occurred, and null is returned.
*
* @param source A <code>String</code>, part of which should be parsed.
* @param pos A <code>ParsePosition</code> object with index and error
* index information as described above.
* @return An <code>Object</code> parsed from the string. In case of
* error, returns null.
* @exception NullPointerException if <code>pos</code> is null.
*/
public T parseObject (S source, ParsePosition pos);
}

View file

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 1996-2008, International Business Machines Corporation and *
* Copyright (C) 1996-2009, Google, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
@ -13,7 +13,7 @@ package com.ibm.icu.text;
* @author markdavis
*
*/
public interface StringTransform {
public interface StringTransform extends Transform<String,String> {
/**
* Transform the text in some way, to be determined by the subclass.
* @param source text to be transformed (eg lowercased)

View file

@ -0,0 +1,26 @@
/*
*******************************************************************************
* Copyright (C) 2009, Google, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.text;
/**
* Provide an interface for Transforms that focuses just on the transformation of the text.
* APIs that take Transliterator or StringTransform, but only depend on the transformation should use this interface in the API instead.
*
* @draft ICU 4.4
* @author markdavis
*
*/
public interface Transform<S,D> {
/**
* Transform the input in some way, to be determined by the subclass.
* @param source to be transformed (eg lowercased)
* @return result
* @stable ICU 3.8
*/
public D transform(S source);
}

View file

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 2003-2006, International Business Machines Corporation and *
* Copyright (C) 2003-2009, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
@ -20,7 +20,7 @@ import com.ibm.icu.util.ULocale;
* @draft ICU 2.8 (retain)
* @provisional This API might change or be removed in a future release.
*/
public abstract class UFormat extends Format {
public abstract class UFormat extends Format implements BaseFormat<Object,StringBuffer,String> {
// jdk1.4.2 serialver
private static final long serialVersionUID = -4964390515840164416L;