Return-Path: Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 64173 invoked from network); 25 Apr 2003 20:58:02 -0000 Received: from einsteinium.btinternet.com (194.73.73.147) by daedalus.apache.org with SMTP; 25 Apr 2003 20:58:02 -0000 Received: from host217-34-89-171.in-addr.btopenworld.com ([217.34.89.171] helo=oemcomputer) by einsteinium.btinternet.com with smtp (Exim 3.22 #23) id 199AGl-0003pW-00 for commons-user@jakarta.apache.org; Fri, 25 Apr 2003 21:58:07 +0100 Message-ID: <001401c30b6e$12e03ee0$ab5922d9@oemcomputer> From: "Stephen Colebourne" To: "Jakarta Commons Users List" References: <200304241414.h3OEEb5j005787@web162.megawebservers.com> Subject: Re: [lang] Formats for enums Date: Fri, 25 Apr 2003 22:03:07 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N 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: To: 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 >