You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mb...@apache.org on 2009/10/14 16:23:14 UTC

svn commit: r825151 - /commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NOPClosure.java

Author: mbenson
Date: Wed Oct 14 14:23:13 2009
New Revision: 825151

URL: http://svn.apache.org/viewvc?rev=825151&view=rev
Log:
[COLLECTIONS-341]

Modified:
    commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NOPClosure.java

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NOPClosure.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NOPClosure.java?rev=825151&r1=825150&r2=825151&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NOPClosure.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NOPClosure.java Wed Oct 14 14:23:13 2009
@@ -28,7 +28,7 @@
  *
  * @author Stephen Colebourne
  */
-public class NOPClosure<E> implements Closure<E>, Serializable {
+public final class NOPClosure<E> implements Closure<E>, Serializable {
 
     /** Serial version UID */
     private static final long serialVersionUID = 3518477308466486130L;
@@ -68,13 +68,7 @@
      */
     @Override
     public boolean equals(Object arg0) {
-        if (arg0 == this) {
-            return true;
-        }
-        if (arg0 instanceof NOPClosure == false) {
-            return false;
-        }
-        return arg0.hashCode() == this.hashCode();
+        return arg0 == this || arg0 instanceof NOPClosure<?>;
     }
 
     /**



Re: svn commit: r825151 - /commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NOPClosure.java

Posted by Goran Hacek <go...@gmail.com>.
On Wed, Oct 14, 2009 at 19:56, sebb <se...@gmail.com> wrote:
> Why not just remove the equals() and hashCode() methods?
> The defaults are just as good.

It is not the same because multiple instances of NOPClosure can exist.
This is because of serialization support.

By implementing readResolve() method which will always return INSTANCE
static member will ensure that no more then one instance of NOPClosure
exists at any given time. With this guaranty default equals() and
hashCode() will do their job as they should.

Javadoc comment on INSTANCE static member, which says "Singleton
predicate instance", is not correct because class doesn't implement
singleton pattern correctly. This would be fixed by implementing
readResolve() as previously described.

I have created a patch for this, it is in jira[1], so can someone review it?

[1] https://issues.apache.org/jira/browse/COLLECTIONS-343

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r825151 - /commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NOPClosure.java

Posted by Matt Benson <gu...@yahoo.com>.

--- On Wed, 10/14/09, sebb <se...@gmail.com> wrote:

> From: sebb <se...@gmail.com>
> Subject: Re: svn commit: r825151 - /commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NOPClosure.java
> To: dev@commons.apache.org
> Date: Wednesday, October 14, 2009, 12:56 PM
> On 14/10/2009, mbenson@apache.org
> <mb...@apache.org>
> wrote:
> > Author: mbenson
> >  Date: Wed Oct 14 14:23:13 2009
> >  New Revision: 825151
> >
> >  URL: http://svn.apache.org/viewvc?rev=825151&view=rev
> >  Log:
> >  [COLLECTIONS-341]
> >
> >  Modified:
> > 
>    commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NOPClosure.java
> >
> >  Modified:
> commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NOPClosure.java
> >  URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NOPClosure.java?rev=825151&r1=825150&r2=825151&view=diff
> > 
> ==============================================================================
> >  ---
> commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NOPClosure.java
> (original)
> >  +++
> commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NOPClosure.java
> Wed Oct 14 14:23:13 2009
> >  @@ -28,7 +28,7 @@
> >   *
> >   * @author Stephen Colebourne
> >   */
> >  -public class NOPClosure<E> implements
> Closure<E>, Serializable {
> >  +public final class NOPClosure<E>
> implements Closure<E>, Serializable {
> >
> >      /** Serial version UID */
> >      private static final long
> serialVersionUID = 3518477308466486130L;
> >  @@ -68,13 +68,7 @@
> >       */
> >      @Override
> >      public boolean equals(Object arg0)
> {
> >  -        if (arg0 == this)
> {
> >  -           
> return true;
> >  -        }
> >  -        if (arg0 instanceof
> NOPClosure == false) {
> >  -           
> return false;
> >  -        }
> >  -        return
> arg0.hashCode() == this.hashCode();
> >  +        return arg0 == this
> || arg0 instanceof NOPClosure<?>;
> >      }
> 
> Why not just remove the equals() and hashCode() methods?
> The defaults are just as good.
> 

Yeah, I s'pose that'd be fine as well.  :)

-Matt

> >      /**
> >
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
> 
> 


      

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r825151 - /commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NOPClosure.java

Posted by sebb <se...@gmail.com>.
On 14/10/2009, mbenson@apache.org <mb...@apache.org> wrote:
> Author: mbenson
>  Date: Wed Oct 14 14:23:13 2009
>  New Revision: 825151
>
>  URL: http://svn.apache.org/viewvc?rev=825151&view=rev
>  Log:
>  [COLLECTIONS-341]
>
>  Modified:
>     commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NOPClosure.java
>
>  Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NOPClosure.java
>  URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NOPClosure.java?rev=825151&r1=825150&r2=825151&view=diff
>  ==============================================================================
>  --- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NOPClosure.java (original)
>  +++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NOPClosure.java Wed Oct 14 14:23:13 2009
>  @@ -28,7 +28,7 @@
>   *
>   * @author Stephen Colebourne
>   */
>  -public class NOPClosure<E> implements Closure<E>, Serializable {
>  +public final class NOPClosure<E> implements Closure<E>, Serializable {
>
>      /** Serial version UID */
>      private static final long serialVersionUID = 3518477308466486130L;
>  @@ -68,13 +68,7 @@
>       */
>      @Override
>      public boolean equals(Object arg0) {
>  -        if (arg0 == this) {
>  -            return true;
>  -        }
>  -        if (arg0 instanceof NOPClosure == false) {
>  -            return false;
>  -        }
>  -        return arg0.hashCode() == this.hashCode();
>  +        return arg0 == this || arg0 instanceof NOPClosure<?>;
>      }

Why not just remove the equals() and hashCode() methods?
The defaults are just as good.

>      /**
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org