You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pivot.apache.org by Sandro Martini <sa...@gmail.com> on 2009/08/06 17:03:19 UTC

Other Small things

Hi to all,
some other small fixed today, grouped by type:

Int division result cast to double or float
Here there are 33 warnings, for example see these 2:
TerraAccordionSkin.java:145 int division result cast to double or float
TerraAccordionSkin.java:144 int division result cast to double or float

This code casts the result of an integer division operation to double
or float. Doing division on integers truncates the result to the
integer value closest to zero. The fact that the result was cast to
double suggests that this precision should have been retained. What
was probably meant was to cast one or both of the operands to double
before performing the division. Here is an example:

int x = 2;
int y = 5;
// Wrong: yields result 0.0
double value1 =  x / y;

// Right: yields result 0.4
double value2 =  x / (double) y;



Call to unsupported method
Description: All targets of this method invocation throw an
UnsupportedOperationException.
Component.java:85 Call to unsupported method
org.apache.pivot.beans.BeanDictionary.remove(String)


Class doesn't override equals in the superclass
ArrayList.java:365 org.apache.pivot.wtk.TreeView$BranchHandler doesn't
override org.apache.pivot.collections.ArrayList.equals(Object)


Comparator doesn't implement Serializable
=> sorry, maybe some of these have already be discussed, i don't
remember well ...
TreeNodeComparator.java:1
org.apache.pivot.tutorials.TreeNodeComparator implements Comparator
but not Serializable
TableView.java:484 org.apache.pivot.wtk.TableView$RowComparator
implements Comparator but not Serializable
TreeView.java:331 org.apache.pivot.wtk.TreeView$PathComparator
implements Comparator but not Serializable
Element.java:72 org.apache.pivot.wtk.text.Element$NodeOffsetComparator
implements Comparator but not Serializable


Method invokes inefficient Number constructor
=> 8 times ... ok, it's a test class, but i can patch ...
ParentResourcesTest.java:66 Method
org.apache.pivot.util.test.ParentResourcesTest.testInteger() invokes
inefficient new Integer(int) constructor; use Integer.valueOf(int)
instead



Tell me something.

Bye

Re: Other Small things

Posted by Sandro Martini <sa...@gmail.com>.
Done.

Still I have to make the random patch:
instead of Math.random(), using the more efficient random.nextInt() ,
but I have to make some experiments, creating a global variable Random
(i think static), and see random numbers generated, if they are really
random, or at least not always the same ...

Bye

Re: Other Small things

Posted by Sandro Martini <sa...@gmail.com>.
Yes,
I'll start in a few minutes ...

Re: Other Small things

Posted by Greg Brown <gk...@mac.com>.
OK. Are you also planning to make the listener list change?

On Aug 7, 2009, at 10:41 AM, Sandro Martini wrote:

> Hi Greg,
>
>> What specifically are you referring to?  :-)  If you mean making the
>> listener list classes static, then yes.
>
>
>> It probably should be valueOf(), yes.
> Ok, but i was asking to Christopher if he wants me to make patch to
> his source ... i think there aren't problems.
>
> Bye


Re: Other Small things

Posted by Sandro Martini <sa...@gmail.com>.
Hi Greg,

> What specifically are you referring to?  :-)  If you mean making the
> listener list classes static, then yes.


> It probably should be valueOf(), yes.
Ok, but i was asking to Christopher if he wants me to make patch to
his source ... i think there aren't problems.

Bye

Re: Other Small things

Posted by Greg Brown <gk...@mac.com>.
What specifically are you referring to?  :-)  If you mean making the  
listener list classes static, then yes.

On Aug 7, 2009, at 10:18 AM, Sandro Martini wrote:

> Hi,
> i can do this, ok ?
>
> Bye


Re: Other Small things

Posted by Sandro Martini <sa...@gmail.com>.
Hi,
i can do this, ok ?

Bye

Re: Other Small things

Posted by Christopher Brind <br...@brindy.org.uk>.
2009/8/6 Greg Brown <gk...@mac.com>

>
>
>  Method invokes inefficient Number constructor
>> => 8 times ... ok, it's a test class, but i can patch ...
>> ParentResourcesTest.java:66 Method
>> org.apache.pivot.util.test.ParentResourcesTest.testInteger() invokes
>> inefficient new Integer(int) constructor; use Integer.valueOf(int)
>> instead
>>
>
> Chris, was this intentional, or would valueOf() be OK?
>

It probably should be valueOf(), yes.

Cheers,
Chris

Re: Other Small things

Posted by Greg Brown <gk...@mac.com>.
> Int division result cast to double or float

These are OK. In general, we're dividing by 2 to center something, so  
rounding doesn't really help.

> Call to unsupported method
> Description: All targets of this method invocation throw an
> UnsupportedOperationException.
> Component.java:85 Call to unsupported method
> org.apache.pivot.beans.BeanDictionary.remove(String)

Good catch. That was a copy/paste error. Fixed.

> Class doesn't override equals in the superclass
> ArrayList.java:365 org.apache.pivot.wtk.TreeView$BranchHandler doesn't
> override org.apache.pivot.collections.ArrayList.equals(Object)

Todd can comment on this one.

> Comparator doesn't implement Serializable
> => sorry, maybe some of these have already be discussed, i don't
> remember well ...

Yeah - we already covered these. We can ignore them.

> Method invokes inefficient Number constructor
> => 8 times ... ok, it's a test class, but i can patch ...
> ParentResourcesTest.java:66 Method
> org.apache.pivot.util.test.ParentResourcesTest.testInteger() invokes
> inefficient new Integer(int) constructor; use Integer.valueOf(int)
> instead

Chris, was this intentional, or would valueOf() be OK?