Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #1247
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | markspace <-@.> |
| Newsgroups | comp.lang.java.help |
| Subject | Re: Dynamic enums |
| Date | Wed, 12 Oct 2011 07:46:49 -0700 |
| Organization | A noiseless patient Spider |
| Lines | 44 |
| Message-ID | <j7498t$pcn$1@dont-email.me> (permalink) |
| References | <4e94eeb1$0$16274$9a566e8b@news.aliant.net> <j72sn7$cl$1@dont-email.me> <j72t18$1u6$1@dont-email.me> <4e952d5d$0$14660$9a566e8b@news.aliant.net> <j73vgl$n1o$1@dont-email.me> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Wed, 12 Oct 2011 14:46:53 +0000 (UTC) |
| Injection-Info | mx04.eternal-september.org; posting-host="XjIWM99mD7Ijfdu600oVPA"; logging-data="26007"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ALjaryK7eLQQL4d4IMR5yuDxiHbYpIU8=" |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1 |
| In-Reply-To | <j73vgl$n1o$1@dont-email.me> |
| Cancel-Lock | sha1:3h22qeA1pVPGKTqstKCvggOMd/Y= |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.java.help:1247 |
Show key headers only | View raw
On 10/12/2011 4:58 AM, Eric Sosman wrote:
> Stepping back a bit, it's not clear to me why you need a separate
> data structure just to hold the keys. In your original post you wrote
> of pairings in "a table called foobar," matching A with 1, B with 2,
> and so forth. This sounds very much like a Map with entries {A,1},
> {B,2} and so on,
Because if the "enums" are dynamic, he needs someplace to store them.
IF the database table lists enums as strings or ints, he needs a place
to lookup up "A" or 1 and get the singleton class back that represents
the enum.
Regular singleton:
class MyEnum {
public static final MyEnum A = new MyEnum();
public static final MyEnum B = new MyEnum();
private MyEnum() {}
}
Dynamic:
class MyEnum {
private MyEnum() {}
private final HashMap enums = new HashMap();
public void addEnum( String name ) {
if( enums.get( name ) == null )
enums.put( name, new MyEnum() );
}
public MyEnum getEnum( String name ) {
return enums.get( name );
}
}
Probably need some fields for getting the name of the enum or it's
ordinal value, but that's how I see the out line of the dynamic part of
the code.
Back to comp.lang.java.help | Previous | Next — Previous in thread | Next in thread | Find similar
Dynamic enums Linus Flustillbe <admin@nacs.dyndns-office.com> - 2011-10-12 01:34 +0000
Re: Dynamic enums Lew <lewbloch@gmail.com> - 2011-10-11 19:03 -0700
Re: Dynamic enums Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-10-11 22:05 -0400
Re: Dynamic enums Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-10-11 22:11 -0400
Re: Dynamic enums Linus Flustillbe <admin@nacs.dyndns-office.com> - 2011-10-12 06:02 +0000
Re: Dynamic enums markspace <-@.> - 2011-10-11 23:44 -0700
Re: Dynamic enums Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-10-12 07:58 -0400
Re: Dynamic enums markspace <-@.> - 2011-10-12 07:46 -0700
Re: Dynamic enums markspace <-@.> - 2011-10-11 19:32 -0700
Re: Dynamic enums Roedy Green <see_website@mindprod.com.invalid> - 2011-10-12 07:02 -0700
csiph-web