commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephen Colebourne" <scolebou...@btopenworld.com>
Subject Re: [lang] Formats for enums
Date Fri, 25 Apr 2003 21:03:07 GMT
There could be a role for something like this in [lang] after the next
release. We already look like adding a better DateFormat, so this is a
similar idea.

However the main problem is obtaining the data from the files. [lang] is
essentially a non-configuration file project, which causes a problem. One
solution might be to place the code in a more i18n focussed project in
commons, such as [resources], or maybe a new [format] or some such...

Stephen

----- Original Message -----
From: <erjablow@praxiseng.com>
To: <commons-user@jakarta.apache.org>
Sent: Thursday, April 24, 2003 3:14 PM
Subject: [lang] Formats for enums


>
>
> I'm working on an application that uses a lot of type-safe enumerations
> and must be internationalized.  One thing I think is missing from the lang
> package and could profitably be added to it is a set of Formats for Enums.
> It would certainly help me, and I would be willing to work on it.
> People might want it in a separate project, though.
>
> For example:
>
> package org.fide.chess;  // No, I do not work for FIDE.
> import org.apache.commons.lang.enum.Enum;
>
> public final class Piece extends Enum {
>   public final static Piece KING   = new Piece("King");
>   public final static Piece QUEEN  = new Piece("Queen");
>   public final static Piece ROOK   = new Piece("Rook");
>   public final static Piece BISHOP = new Piece("Bishop");
>   public final static Piece KNIGHT = new Piece("Knight");
>   public final static Piece PAWN   = new Piece("Pawn");
>
>   private Piece(String piece) {
>     super(piece);
>   }
>
>   public static Piece getEnum(String piece) {
>     return (Piece) getEnum(Piece.class, piece);
>   }
>
>   public static Map getEnumMap() {
>     return getEnumMap(Piece.class);
>   }
>
>   public static List getEnumList() {
>     return getEnumList(Piece.class);
>   }
>
>   public static Iterator iterator() {
>     return iterator(Piece.class);
>   }
> }
>
> Now, for some applications I would want a format that would take a Piece
> and output an internationalized version of the name:
>
>   ChessFormat tf = new ChessFormat();
>   String s = tf .format(Piece.KNIGHT);
>   // In Locale.US, s is "knight".
>   // In Locale.DE, s is "Springer".
>
> For other applications, I might want the abbreviation.
>
>   ChessFormat af= new ChessFormat(ChessFormat.SHORT);
>   String s = af.format(Piece.KNIGHT);
>   // s is "N".
>
> And I might want figurine algebraic, although there are separate Unicode
> characters for white and black:
>
>
>   ChessFormat ff= new ChessFormat(ChessFormat.FIGURINE);
>   String s = ff.format(Piece.KNIGHT);
>   // s is "\u2658" (or "\u265E").
>
> I have some ideas for doing this; they involve finding a set of properties
> files alongside the enum class.  But my ideas are still fuzzy, and I'd
like
> to know if I'm on the right track, or even if this is the right place to
ask.
>
> I have some similar ideas for MessageFormat, but that should come later.
>
> Respectfully,
> Eric Jablow
>
>
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>


Mime
View raw message