You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Eero Nevalainen <ee...@indagon.com> on 2007/05/22 12:18:30 UTC
setEnumAttribute?
I was thinking about an earlier discussion about setting attributes last
night. One thing that bugs me a bit is that the key is a String and
someone else might be using that same String as their key.
So I had the thought of setting attributes with Enums. Mapping to the
correct enum class and then with the enum key would probably "eliminate"
an accidental key collision.
This could even be implemented without the need to calculate hashvalues,
by making the clients store the index of their specifice enum class.
Unfortunately I also just noticed that there's no implementation for a
ConcurrentEnumMap yet in JDK 1.6. This damps the idea quite a bit but I
thought I'd voice it anyway.
-Eero Nevalainen
Re: setEnumAttribute?
Posted by peter royal <pe...@pobox.com>.
On May 22, 2007, at 10:37 PM, Brigham Stevens wrote:
> I would like the Attribute keys to be Objects instead of Strings or
> Enums.
> (Because then we could use Enums if we want, right?
> Or is there another good reason for not using POJO? .hashCode()
> collision?)
Yes, you could use Enum's with Object keys.
-pete
--
(peter.royal|osi)@pobox.com - http://fotap.org/~osi
RE: setEnumAttribute?
Posted by Brigham Stevens <br...@vikingmind.com>.
I would like the Attribute keys to be Objects instead of Strings or Enums.
(Because then we could use Enums if we want, right?
Or is there another good reason for not using POJO? .hashCode() collision?)
This isn't really on the topic, but please someone correct me if I'm wrong.
A serious shortcoming of Enums is no reverse mapping from ordinal to Enum.
Only from String to enum. Which means you can't really use enums in a
Binary protocol definition talking to other languages and such.
I was bummed about that.
# -----Original Message-----
# From: Trustin Lee [mailto:trustin@gmail.com]
# Sent: Tuesday, May 22, 2007 10:17 PM
# To: dev@mina.apache.org
# Subject: Re: setEnumAttribute?
#
# On 5/23/07, peter royal <pr...@apache.org> wrote:
# > On May 22, 2007, at 10:01 PM, Trustin Lee wrote:
# > > Do you think we need to remove the restriction that the
# key must be
# > > a string? It makes sense IMHO.
# >
# > i don't think we need to.. i find it easy enough now, since
# its like
# > the servlet API that i know well :) .. but i won't object if the
# > community as a whole would rather have it gone.
#
# I think so too. The community drives! What do you think guys? :)
#
# Trustin
# --
# what we call human nature is actually human habit
# --
# http://gleamynode.net/
# --
# PGP Key ID: 0x0255ECA6
Re: setEnumAttribute?
Posted by Trustin Lee <tr...@gmail.com>.
On 5/23/07, peter royal <pr...@apache.org> wrote:
> On May 22, 2007, at 10:01 PM, Trustin Lee wrote:
> > Do you think we need to remove the restriction that the key must be a
> > string? It makes sense IMHO.
>
> i don't think we need to.. i find it easy enough now, since its like
> the servlet API that i know well :) .. but i won't object if the
> community as a whole would rather have it gone.
I think so too. The community drives! What do you think guys? :)
Trustin
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6
Re: setEnumAttribute?
Posted by peter royal <pr...@apache.org>.
On May 22, 2007, at 10:01 PM, Trustin Lee wrote:
> Do you think we need to remove the restriction that the key must be a
> string? It makes sense IMHO.
i don't think we need to.. i find it easy enough now, since its like
the servlet API that i know well :) .. but i won't object if the
community as a whole would rather have it gone.
-pete
--
proyal@apache.org - http://fotap.org/~osi
Re: setEnumAttribute?
Posted by Trustin Lee <tr...@gmail.com>.
On 5/23/07, peter royal <pr...@apache.org> wrote:
> On May 22, 2007, at 3:18 AM, Eero Nevalainen wrote:
> > I was thinking about an earlier discussion about setting attributes
> > last night. One thing that bugs me a bit is that the key is a
> > String and someone else might be using that same String as their key.
> >
> > So I had the thought of setting attributes with Enums. Mapping to
> > the correct enum class and then with the enum key would probably
> > "eliminate" an accidental key collision.
> >
> > This could even be implemented without the need to calculate
> > hashvalues, by making the clients store the index of their
> > specifice enum class.
The hash code is cached once calculated AFAIK. But we cannot avoid
the equals() operation that will take some time.
> > Unfortunately I also just noticed that there's no implementation
> > for a ConcurrentEnumMap yet in JDK 1.6. This damps the idea quite a
> > bit but I thought I'd voice it anyway.
ConcurrentHashMap will work fine with enums, so I see no problem here.
> Not sure this will work as you expect.. since the EnumMap has values
> from a specific Enum as its keys.
>
> To prevent key collisions, one thing I do is use getClass().getName()
> as a prefix for my keys, that way it provides some uniqueness. Same
> trick I learned to use when writing servlets :)
Yep, it's a very useful tip. :)
Do you think we need to remove the restriction that the key must be a
string? It makes sense IMHO.
Trustin
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6
Re: setEnumAttribute?
Posted by peter royal <pr...@apache.org>.
On May 22, 2007, at 3:18 AM, Eero Nevalainen wrote:
> I was thinking about an earlier discussion about setting attributes
> last night. One thing that bugs me a bit is that the key is a
> String and someone else might be using that same String as their key.
>
> So I had the thought of setting attributes with Enums. Mapping to
> the correct enum class and then with the enum key would probably
> "eliminate" an accidental key collision.
>
> This could even be implemented without the need to calculate
> hashvalues, by making the clients store the index of their
> specifice enum class.
>
> Unfortunately I also just noticed that there's no implementation
> for a ConcurrentEnumMap yet in JDK 1.6. This damps the idea quite a
> bit but I thought I'd voice it anyway.
Not sure this will work as you expect.. since the EnumMap has values
from a specific Enum as its keys.
To prevent key collisions, one thing I do is use getClass().getName()
as a prefix for my keys, that way it provides some uniqueness. Same
trick I learned to use when writing servlets :)
-pete
--
proyal@apache.org - http://fotap.org/~osi