You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by Andy Schwartz <an...@gmail.com> on 2012/02/14 04:23:45 UTC

[Trinidad] RequestContext.Accessibility.valueOfAlias() API

Gang -

For this newly logged issue:

TRINIDAD-2215 String -> Accessibility enum API
https://issues.apache.org/jira/browse/TRINIDAD-2215

I would like to add a new valueOfAlias() method to
RequestContext.Accessibility, as shown here:

https://issues.apache.org/jira/secure/attachment/12514439/trinidad-2215.patch

This serves a similar purpose to good old Enum.valueOf(), but operates
on the pretty names/aliases used by the Accessibility enum.

Any concerns about this?  Or suggestions for a better method name?

Andy

Re: [Trinidad] RequestContext.Accessibility.valueOfAlias() API

Posted by Andy Schwartz <an...@gmail.com>.
On Tue, Feb 14, 2012 at 12:51 PM, Blake Sullivan
<bl...@oracle.com> wrote:
> I prefer #1.  If the caller really cares about what she gets, she can call
> the explicit method.

Sounds reasonable.  Will leave toString() behavior undocumented.

Andy

Re: [Trinidad] RequestContext.Accessibility.valueOfAlias() API

Posted by Blake Sullivan <bl...@oracle.com>.
I prefer #1.  If the caller really cares about what she gets, she can 
call the explicit method.

-- Blake Sullivan

On 2/14/12 9:18 AM, Andy Schwartz wrote:
> On Tue, Feb 14, 2012 at 11:33 AM, Blake Sullivan
> <bl...@oracle.com>  wrote:
>> I would go with valueOfDisplayName().  I would actually add a displayName()
>> as well, just like we have name().
> Sounds good, will do.
>
>>   I am not a fan of assuming that
>> toString() == displayName()
> Er... two options here:
>
> 1. Leave toString() documentation/contract intentionally vague.
> 2. Document the current behavior (toString() == displayName()) as the
> spec'ed/required behavior.
>
> I was leaning towards #2 since folks out there might be relying on the
> existing toString() behavior - ie. we could enshrine this as required
> behavior in our contract.
>
> Do you prefer #1?
>
> Andy


Re: [Trinidad] RequestContext.Accessibility.valueOfAlias() API

Posted by Andy Schwartz <an...@gmail.com>.
On Tue, Feb 14, 2012 at 12:57 PM, Blake Sullivan
<bl...@oracle.com> wrote:
>
> It is actually the second of these, so everything is good.

Yep.  If it were the first, I wouldn't need my bonus valueOf<x> method.

In any case, new version of the patch uploaded here:

https://issues.apache.org/jira/secure/attachment/12514512/trinidad-2215-take2.patch

I'll commit soon unless anyone objects.

Andy

Re: [Trinidad] RequestContext.Accessibility.valueOfAlias() API

Posted by Blake Sullivan <bl...@oracle.com>.
I also just double-checked the Enum javadoc because I was curious which 
of the following was expected for Enum foo

foo == Enum.valueOf(foo.getClass(), foo.toString())

or

foo == Enum.valueOf(foo.getClass(), foo.name())

It is actually the second of these, so everything is good.

-- Blake

On 2/14/12 9:18 AM, Andy Schwartz wrote:
> On Tue, Feb 14, 2012 at 11:33 AM, Blake Sullivan
> <bl...@oracle.com>  wrote:
>> I would go with valueOfDisplayName().  I would actually add a displayName()
>> as well, just like we have name().
> Sounds good, will do.
>
>>   I am not a fan of assuming that
>> toString() == displayName()
> Er... two options here:
>
> 1. Leave toString() documentation/contract intentionally vague.
> 2. Document the current behavior (toString() == displayName()) as the
> spec'ed/required behavior.
>
> I was leaning towards #2 since folks out there might be relying on the
> existing toString() behavior - ie. we could enshrine this as required
> behavior in our contract.
>
> Do you prefer #1?
>
> Andy


Re: [Trinidad] RequestContext.Accessibility.valueOfAlias() API

Posted by Andy Schwartz <an...@gmail.com>.
On Tue, Feb 14, 2012 at 11:33 AM, Blake Sullivan
<bl...@oracle.com> wrote:
> I would go with valueOfDisplayName().  I would actually add a displayName()
> as well, just like we have name().

Sounds good, will do.

>  I am not a fan of assuming that
> toString() == displayName()

Er... two options here:

1. Leave toString() documentation/contract intentionally vague.
2. Document the current behavior (toString() == displayName()) as the
spec'ed/required behavior.

I was leaning towards #2 since folks out there might be relying on the
existing toString() behavior - ie. we could enshrine this as required
behavior in our contract.

Do you prefer #1?

Andy

Re: [Trinidad] RequestContext.Accessibility.valueOfAlias() API

Posted by Blake Sullivan <bl...@oracle.com>.
I would go with valueOfDisplayName().  I would actually add a 
displayName() as well, just like we have name().  I am not a fan of 
assuming that toString() == displayName()

-- Blake Sullivan


On 2/14/12 4:21 AM, Andy Schwartz wrote:
> Thanks for the comments guys.
>
> On Mon, Feb 13, 2012 at 11:51 PM, Blake Sullivan
> <bl...@oracle.com>  wrote:
>> Overloaded how?
>>
>> The other question is that we want to be able to go from the
>> displayName->Enum
> Actually, this is the only question. :-)
>
> We've already got an "accessor" - the Accessibility enum overrides
> toString() to return the display name/pretty name/alias that gets
> passed in when the constant is created.
>
> What I need is a way to map back from the toString() value to the
> corresponding enum constant.  For this, we should follow the pattern
> set by Enum.valueOf().  So, we'll want something like:
>
> Accessibility.valueOfTheStringThatGetsReturnedFromToStringNotTheEnumConstantName()
>
> But shorter.
>
> Maybe:
>
> - valueOfDisplayName()?  Or...
> - valueOfAlias()?
>
> Whatever name we come up with, I will:
>
> - Update the name of the Accessibility enum constant constructor
> argument to match.
> - Add javadoc to toString() that clarifies that it returns the display
> name/alias/whatever we call it.
>
> Andy


Re: [Trinidad] RequestContext.Accessibility.valueOfAlias() API

Posted by Andy Schwartz <an...@gmail.com>.
Thanks for the comments guys.

On Mon, Feb 13, 2012 at 11:51 PM, Blake Sullivan
<bl...@oracle.com> wrote:
> Overloaded how?
>
> The other question is that we want to be able to go from the
> displayName->Enum

Actually, this is the only question. :-)

We've already got an "accessor" - the Accessibility enum overrides
toString() to return the display name/pretty name/alias that gets
passed in when the constant is created.

What I need is a way to map back from the toString() value to the
corresponding enum constant.  For this, we should follow the pattern
set by Enum.valueOf().  So, we'll want something like:

Accessibility.valueOfTheStringThatGetsReturnedFromToStringNotTheEnumConstantName()

But shorter.

Maybe:

- valueOfDisplayName()?  Or...
- valueOfAlias()?

Whatever name we come up with, I will:

- Update the name of the Accessibility enum constant constructor
argument to match.
- Add javadoc to toString() that clarifies that it returns the display
name/alias/whatever we call it.

Andy

Re: [Trinidad] RequestContext.Accessibility.valueOfAlias() API

Posted by Blake Sullivan <bl...@oracle.com>.
Overloaded how?

The other question is that we want to be able to go from the 
displayName->Enum

-- Blake Sullivan

On 2/13/12 8:44 PM, Scott O'Bryan wrote:
> How would this differ from an overloaded toString()?  By contract, 
> that can be overloaded to make more sense.
>
> Scott
>
> Sent from my iPad
>
> On Feb 13, 2012, at 9:27 PM, Blake Sullivan <blake.sullivan@oracle.com 
> <ma...@oracle.com>> wrote:
>
>> This example 
>> <http://www.basilv.com/psd/blog/2006/advanced-uses-of-java-5-enums>uses 
>> getDisplayName(), though given the presence of name(), I think 
>> displayName() makes more sense (Josh Bloch hates the getXXX(), 
>> setXXX() pattern)
>>
>> -- Blake Sullivan
>>
>>
>> On 2/13/12 7:23 PM, Andy Schwartz wrote:
>>> Gang -
>>>
>>> For this newly logged issue:
>>>
>>> TRINIDAD-2215 String ->  Accessibility enum API
>>> https://issues.apache.org/jira/browse/TRINIDAD-2215
>>>
>>> I would like to add a new valueOfAlias() method to
>>> RequestContext.Accessibility, as shown here:
>>>
>>> https://issues.apache.org/jira/secure/attachment/12514439/trinidad-2215.patch
>>>
>>> This serves a similar purpose to good old Enum.valueOf(), but operates
>>> on the pretty names/aliases used by the Accessibility enum.
>>>
>>> Any concerns about this?  Or suggestions for a better method name?
>>>
>>> Andy
>>


Re: [Trinidad] RequestContext.Accessibility.valueOfAlias() API

Posted by Scott O'Bryan <da...@gmail.com>.
How would this differ from an overloaded toString()?  By contract, that can
be overloaded to make more sense.

Scott

Sent from my iPad

On Feb 13, 2012, at 9:27 PM, Blake Sullivan <bl...@oracle.com>
wrote:

 This example
<http://www.basilv.com/psd/blog/2006/advanced-uses-of-java-5-enums>uses
getDisplayName(), though given the presence of name(), I think
displayName() makes more sense (Josh Bloch hates the getXXX(), setXXX()
pattern)

-- Blake Sullivan


On 2/13/12 7:23 PM, Andy Schwartz wrote:

Gang -

For this newly logged issue:

TRINIDAD-2215 String -> Accessibility enum
APIhttps://issues.apache.org/jira/browse/TRINIDAD-2215

I would like to add a new valueOfAlias() method to
RequestContext.Accessibility, as shown here:
https://issues.apache.org/jira/secure/attachment/12514439/trinidad-2215.patch

This serves a similar purpose to good old Enum.valueOf(), but operates
on the pretty names/aliases used by the Accessibility enum.

Any concerns about this?  Or suggestions for a better method name?

Andy

Re: [Trinidad] RequestContext.Accessibility.valueOfAlias() API

Posted by Blake Sullivan <bl...@oracle.com>.
This example 
<http://www.basilv.com/psd/blog/2006/advanced-uses-of-java-5-enums>uses 
getDisplayName(), though given the presence of name(), I think 
displayName() makes more sense (Josh Bloch hates the getXXX(), setXXX() 
pattern)

-- Blake Sullivan


On 2/13/12 7:23 PM, Andy Schwartz wrote:
> Gang -
>
> For this newly logged issue:
>
> TRINIDAD-2215 String ->  Accessibility enum API
> https://issues.apache.org/jira/browse/TRINIDAD-2215
>
> I would like to add a new valueOfAlias() method to
> RequestContext.Accessibility, as shown here:
>
> https://issues.apache.org/jira/secure/attachment/12514439/trinidad-2215.patch
>
> This serves a similar purpose to good old Enum.valueOf(), but operates
> on the pretty names/aliases used by the Accessibility enum.
>
> Any concerns about this?  Or suggestions for a better method name?
>
> Andy