You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pivot.apache.org by Edgar Merino <do...@gmail.com> on 2009/05/26 08:37:27 UTC

Window#setTitle()

Hello,

    By looking through the Window source code, I've noticed the 
setTitle() method has this restriction:

    String previousTitle = this.title;

    if (previousTitle == null ^ title == null) {
        this.title = title;
        windowListeners.titleChanged(this, previousTitle);
    }

    This is keeping the windows in my application to not be able to 
change their title once it's been set for the first time. Why is that 
restriction there? I've removed the restriction and changed it to only 
check if the new title is not null, so far I haven't encountered any 
problems, but there might be some explanation as to why it's there.

Edgar Merino

Re: Window#setTitle()

Posted by Greg Brown <gk...@mac.com>.
We were doing that type of check way back but have pretty much eliminated it in favor of simple reference equality checks for string setters. But Window#setTitle() is a pretty old method and we obviously haven't been in there in a while.  :-)
 
On Tuesday, May 26, 2009, at 10:24AM, "Todd Volkert" <tv...@gmail.com> wrote:
>Yeah I just looked at it again, and the XOR covers the first part of
>this phrase -- "if one is null and the other is non-null".  So we can
>just add to the original phrasing...
>
>On Tue, May 26, 2009 at 10:22 AM, Todd Volkert <tv...@gmail.com> wrote:
>> I think the original check was an incorrect phrasing of "if one is
>> null and the other is non-null or if they're both non-null and
>> logically different".
>>
>> -T
>>
>> On Tue, May 26, 2009 at 9:46 AM, Christopher Brind <br...@brindy.org.uk> wrote:
>>> What if previousTitle is null?
>>>
>>> Though it will fire the listeners unnecessarily (if the titles are the same
>>> text just with a different reference) Greg's version is safer.
>>>
>>> Cheers,
>>> Chris
>>>
>>>
>>> 2009/5/26 Edgar Merino <do...@gmail.com>
>>>
>>>> Ok, just a little change there:
>>>>
>>>>   if (!previousTitle.equals(title)) { ... }
>>>>
>>>> Edgar Merino
>>>>
>>>>
>>>>
>>>> Greg Brown escribió:
>>>>
>>>>  Good catch. There's no reason we need the XOR. I changed it to this:
>>>>>
>>>>>        String previousTitle = this.title;
>>>>>
>>>>>        if (previousTitle != title) {
>>>>>            this.title = title;
>>>>>            windowListeners.titleChanged(this, previousTitle);
>>>>>        }
>>>>>
>>>>> Thanks,
>>>>> Greg
>>>>>  On Tuesday, May 26, 2009, at 02:37AM, "Edgar Merino" <do...@gmail.com>
>>>>> wrote:
>>>>>
>>>>>
>>>>>> Hello,
>>>>>>
>>>>>>   By looking through the Window source code, I've noticed the setTitle()
>>>>>> method has this restriction:
>>>>>>
>>>>>>   String previousTitle = this.title;
>>>>>>
>>>>>>   if (previousTitle == null ^ title == null) {
>>>>>>       this.title = title;
>>>>>>       windowListeners.titleChanged(this, previousTitle);
>>>>>>   }
>>>>>>
>>>>>>   This is keeping the windows in my application to not be able to change
>>>>>> their title once it's been set for the first time. Why is that restriction
>>>>>> there? I've removed the restriction and changed it to only check if the new
>>>>>> title is not null, so far I haven't encountered any problems, but there
>>>>>> might be some explanation as to why it's there.
>>>>>>
>>>>>> Edgar Merino
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>
>
>

Re: Window#setTitle()

Posted by Todd Volkert <tv...@gmail.com>.
Yeah I just looked at it again, and the XOR covers the first part of
this phrase -- "if one is null and the other is non-null".  So we can
just add to the original phrasing...

On Tue, May 26, 2009 at 10:22 AM, Todd Volkert <tv...@gmail.com> wrote:
> I think the original check was an incorrect phrasing of "if one is
> null and the other is non-null or if they're both non-null and
> logically different".
>
> -T
>
> On Tue, May 26, 2009 at 9:46 AM, Christopher Brind <br...@brindy.org.uk> wrote:
>> What if previousTitle is null?
>>
>> Though it will fire the listeners unnecessarily (if the titles are the same
>> text just with a different reference) Greg's version is safer.
>>
>> Cheers,
>> Chris
>>
>>
>> 2009/5/26 Edgar Merino <do...@gmail.com>
>>
>>> Ok, just a little change there:
>>>
>>>   if (!previousTitle.equals(title)) { ... }
>>>
>>> Edgar Merino
>>>
>>>
>>>
>>> Greg Brown escribió:
>>>
>>>  Good catch. There's no reason we need the XOR. I changed it to this:
>>>>
>>>>        String previousTitle = this.title;
>>>>
>>>>        if (previousTitle != title) {
>>>>            this.title = title;
>>>>            windowListeners.titleChanged(this, previousTitle);
>>>>        }
>>>>
>>>> Thanks,
>>>> Greg
>>>>  On Tuesday, May 26, 2009, at 02:37AM, "Edgar Merino" <do...@gmail.com>
>>>> wrote:
>>>>
>>>>
>>>>> Hello,
>>>>>
>>>>>   By looking through the Window source code, I've noticed the setTitle()
>>>>> method has this restriction:
>>>>>
>>>>>   String previousTitle = this.title;
>>>>>
>>>>>   if (previousTitle == null ^ title == null) {
>>>>>       this.title = title;
>>>>>       windowListeners.titleChanged(this, previousTitle);
>>>>>   }
>>>>>
>>>>>   This is keeping the windows in my application to not be able to change
>>>>> their title once it's been set for the first time. Why is that restriction
>>>>> there? I've removed the restriction and changed it to only check if the new
>>>>> title is not null, so far I haven't encountered any problems, but there
>>>>> might be some explanation as to why it's there.
>>>>>
>>>>> Edgar Merino
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>
>

Re: Window#setTitle()

Posted by Todd Volkert <tv...@gmail.com>.
I think the original check was an incorrect phrasing of "if one is
null and the other is non-null or if they're both non-null and
logically different".

-T

On Tue, May 26, 2009 at 9:46 AM, Christopher Brind <br...@brindy.org.uk> wrote:
> What if previousTitle is null?
>
> Though it will fire the listeners unnecessarily (if the titles are the same
> text just with a different reference) Greg's version is safer.
>
> Cheers,
> Chris
>
>
> 2009/5/26 Edgar Merino <do...@gmail.com>
>
>> Ok, just a little change there:
>>
>>   if (!previousTitle.equals(title)) { ... }
>>
>> Edgar Merino
>>
>>
>>
>> Greg Brown escribió:
>>
>>  Good catch. There's no reason we need the XOR. I changed it to this:
>>>
>>>        String previousTitle = this.title;
>>>
>>>        if (previousTitle != title) {
>>>            this.title = title;
>>>            windowListeners.titleChanged(this, previousTitle);
>>>        }
>>>
>>> Thanks,
>>> Greg
>>>  On Tuesday, May 26, 2009, at 02:37AM, "Edgar Merino" <do...@gmail.com>
>>> wrote:
>>>
>>>
>>>> Hello,
>>>>
>>>>   By looking through the Window source code, I've noticed the setTitle()
>>>> method has this restriction:
>>>>
>>>>   String previousTitle = this.title;
>>>>
>>>>   if (previousTitle == null ^ title == null) {
>>>>       this.title = title;
>>>>       windowListeners.titleChanged(this, previousTitle);
>>>>   }
>>>>
>>>>   This is keeping the windows in my application to not be able to change
>>>> their title once it's been set for the first time. Why is that restriction
>>>> there? I've removed the restriction and changed it to only check if the new
>>>> title is not null, so far I haven't encountered any problems, but there
>>>> might be some explanation as to why it's there.
>>>>
>>>> Edgar Merino
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>
>>
>

Re: Window#setTitle()

Posted by Greg Brown <gk...@mac.com>.
Right. In general, we don't use equals() to check for equality when invoking string setters since it's generally not worth the extra code to perform the null checks and the performance overhead of a string scan.
 
On Tuesday, May 26, 2009, at 09:46AM, "Christopher Brind" <br...@brindy.org.uk> wrote:
>What if previousTitle is null?
>
>Though it will fire the listeners unnecessarily (if the titles are the same
>text just with a different reference) Greg's version is safer.
>
>Cheers,
>Chris
>
>
>2009/5/26 Edgar Merino <do...@gmail.com>
>
>> Ok, just a little change there:
>>
>>   if (!previousTitle.equals(title)) { ... }
>>
>> Edgar Merino
>>
>>
>>
>> Greg Brown escribió:
>>
>>  Good catch. There's no reason we need the XOR. I changed it to this:
>>>
>>>        String previousTitle = this.title;
>>>
>>>        if (previousTitle != title) {
>>>            this.title = title;
>>>            windowListeners.titleChanged(this, previousTitle);
>>>        }
>>>
>>> Thanks,
>>> Greg
>>>  On Tuesday, May 26, 2009, at 02:37AM, "Edgar Merino" <do...@gmail.com>
>>> wrote:
>>>
>>>
>>>> Hello,
>>>>
>>>>   By looking through the Window source code, I've noticed the setTitle()
>>>> method has this restriction:
>>>>
>>>>   String previousTitle = this.title;
>>>>
>>>>   if (previousTitle == null ^ title == null) {
>>>>       this.title = title;
>>>>       windowListeners.titleChanged(this, previousTitle);
>>>>   }
>>>>
>>>>   This is keeping the windows in my application to not be able to change
>>>> their title once it's been set for the first time. Why is that restriction
>>>> there? I've removed the restriction and changed it to only check if the new
>>>> title is not null, so far I haven't encountered any problems, but there
>>>> might be some explanation as to why it's there.
>>>>
>>>> Edgar Merino
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>
>>
>

Re: Window#setTitle()

Posted by Christopher Brind <br...@brindy.org.uk>.
What if previousTitle is null?

Though it will fire the listeners unnecessarily (if the titles are the same
text just with a different reference) Greg's version is safer.

Cheers,
Chris


2009/5/26 Edgar Merino <do...@gmail.com>

> Ok, just a little change there:
>
>   if (!previousTitle.equals(title)) { ... }
>
> Edgar Merino
>
>
>
> Greg Brown escribió:
>
>  Good catch. There's no reason we need the XOR. I changed it to this:
>>
>>        String previousTitle = this.title;
>>
>>        if (previousTitle != title) {
>>            this.title = title;
>>            windowListeners.titleChanged(this, previousTitle);
>>        }
>>
>> Thanks,
>> Greg
>>  On Tuesday, May 26, 2009, at 02:37AM, "Edgar Merino" <do...@gmail.com>
>> wrote:
>>
>>
>>> Hello,
>>>
>>>   By looking through the Window source code, I've noticed the setTitle()
>>> method has this restriction:
>>>
>>>   String previousTitle = this.title;
>>>
>>>   if (previousTitle == null ^ title == null) {
>>>       this.title = title;
>>>       windowListeners.titleChanged(this, previousTitle);
>>>   }
>>>
>>>   This is keeping the windows in my application to not be able to change
>>> their title once it's been set for the first time. Why is that restriction
>>> there? I've removed the restriction and changed it to only check if the new
>>> title is not null, so far I haven't encountered any problems, but there
>>> might be some explanation as to why it's there.
>>>
>>> Edgar Merino
>>>
>>>
>>>
>>>
>>
>>
>>
>
>

Re: Window#setTitle()

Posted by Edgar Merino <do...@gmail.com>.
Ok, just a little change there:

    if (!previousTitle.equals(title)) { ... }

Edgar Merino



Greg Brown escribió:
> Good catch. There's no reason we need the XOR. I changed it to this:
>
>         String previousTitle = this.title;
>
>         if (previousTitle != title) {
>             this.title = title;
>             windowListeners.titleChanged(this, previousTitle);
>         }
>
> Thanks,
> Greg
>  
> On Tuesday, May 26, 2009, at 02:37AM, "Edgar Merino" <do...@gmail.com> wrote:
>   
>> Hello,
>>
>>    By looking through the Window source code, I've noticed the 
>> setTitle() method has this restriction:
>>
>>    String previousTitle = this.title;
>>
>>    if (previousTitle == null ^ title == null) {
>>        this.title = title;
>>        windowListeners.titleChanged(this, previousTitle);
>>    }
>>
>>    This is keeping the windows in my application to not be able to 
>> change their title once it's been set for the first time. Why is that 
>> restriction there? I've removed the restriction and changed it to only 
>> check if the new title is not null, so far I haven't encountered any 
>> problems, but there might be some explanation as to why it's there.
>>
>> Edgar Merino
>>
>>
>>     
>
>   


Re: Window#setTitle()

Posted by Greg Brown <gk...@mac.com>.
Good catch. There's no reason we need the XOR. I changed it to this:

        String previousTitle = this.title;

        if (previousTitle != title) {
            this.title = title;
            windowListeners.titleChanged(this, previousTitle);
        }

Thanks,
Greg
 
On Tuesday, May 26, 2009, at 02:37AM, "Edgar Merino" <do...@gmail.com> wrote:
>Hello,
>
>    By looking through the Window source code, I've noticed the 
>setTitle() method has this restriction:
>
>    String previousTitle = this.title;
>
>    if (previousTitle == null ^ title == null) {
>        this.title = title;
>        windowListeners.titleChanged(this, previousTitle);
>    }
>
>    This is keeping the windows in my application to not be able to 
>change their title once it's been set for the first time. Why is that 
>restriction there? I've removed the restriction and changed it to only 
>check if the new title is not null, so far I haven't encountered any 
>problems, but there might be some explanation as to why it's there.
>
>Edgar Merino
>
>