[jdom-interest] Visibility patch: org.jdom.filter

Jason Hunter jhunter at acm.org
Tue May 27 12:10:08 PDT 2003


Here's a visibility patch for org.jdom.filter.

* I removed the protected no-arg constructors since while they make 
sense for org.jdom they aren't needed for simple filters.

* Made the name/namespace props on ElementFilter private since someone 
who wants different behavior should write their own filter.  Subclassing 
here isn't important.

* The left/right props on OrFilter are also private now.

Since subclassing isn't important I'm thinking I may make some of the 
filters final.

-jh-
-------------- next part --------------
Index: AbstractFilter.java
===================================================================
RCS file: /home/cvs/jdom/src/java/org/jdom/filter/AbstractFilter.java,v
retrieving revision 1.1
diff -u -r1.1 AbstractFilter.java
--- AbstractFilter.java	21 May 2003 09:17:45 -0000	1.1
+++ AbstractFilter.java	27 May 2003 19:46:54 -0000
@@ -69,27 +69,6 @@
     private static final String CVS_ID = 
       "@(#) $RCSfile: AbstractFilter.java,v $ $Revision: 1.1 $ $Date: 2003/05/21 09:17:45 $";
 
-    /**
-     * This is the protected, no-args constructor standard in all JDOM
-     * classes. It allows subclassers to get a raw instance with no
-     * initialization.
-     * <p>
-     * It intentionally leaves all instance variables null, allowing a
-     * lightweight subclass implementation.  The subclass is responsible for
-     * ensuring all the get and set methods behave as documented.
-     * </p>
-     * <p>
-     * When implementing a subclass which doesn't require full control over
-     * variable initialization, be aware that simply calling super() (or
-     * letting the compiler add the implicit super() call) will not
-     * initialize the instance variables which will cause many of the methods
-     * to throw a <code>NullPointerException</code>.  Therefore, the
-     * constructor for these subclasses should call one of the public
-     * constructors so variable initialization is handled automatically.
-     * </p>
-     */
-    protected AbstractFilter() {}
-
     public Filter negate() {
         return new NegateFilter(this);
     }
@@ -103,6 +82,6 @@
     }
 
     public boolean equals(Object obj) {
-        return (this == obj) ? true : false;
+        return this == obj;
     }
 }
Index: AndFilter.java
===================================================================
RCS file: /home/cvs/jdom/src/java/org/jdom/filter/AndFilter.java,v
retrieving revision 1.1
diff -u -r1.1 AndFilter.java
--- AndFilter.java	21 May 2003 09:17:45 -0000	1.1
+++ AndFilter.java	27 May 2003 19:46:54 -0000
@@ -75,28 +75,6 @@
     private Filter right;
 
     /**
-     * This is the protected, no-args constructor standard in all JDOM
-     * classes. It allows subclassers to get a raw instance with no
-     * initialization.
-     * <p>
-     * It intentionally leaves all instance variables null, allowing a
-     * lightweight subclass implementation.  The subclass is responsible for
-     * ensuring all the get and set methods behave as documented.
-     * </p>
-     * <p>
-     * When implementing a subclass which doesn't require full control over
-     * variable initialization, be aware that simply calling super() (or
-     * letting the compiler add the implicit super() call) will not
-     * initialize the instance variables which will cause many of the methods
-     * to throw a <code>NullPointerException</code>.  Therefore, the
-     * constructor for these subclasses should call one of the public
-     * constructors so variable initialization is handled automatically.
-     * </p>
-     */
-    protected AndFilter() {
-    }
-
-    /**
      * Match if only both supplied filters match.
      *
      * @param left left side of logical <b>and</b>
Index: ElementFilter.java
===================================================================
RCS file: /home/cvs/jdom/src/java/org/jdom/filter/ElementFilter.java,v
retrieving revision 1.12
diff -u -r1.12 ElementFilter.java
--- ElementFilter.java	21 May 2003 09:17:45 -0000	1.12
+++ ElementFilter.java	27 May 2003 19:46:55 -0000
@@ -71,10 +71,10 @@
       "@(#) $RCSfile: ElementFilter.java,v $ $Revision: 1.12 $ $Date: 2003/05/21 09:17:45 $ $Name:  $";
 
     /** The element name */
-    protected String name;
+    private String name;
 
     /** The element namespace */
-    protected Namespace namespace;
+    private Namespace namespace;
 
     /**
      * Select only the Elements.
Index: NegateFilter.java
===================================================================
RCS file: /home/cvs/jdom/src/java/org/jdom/filter/NegateFilter.java,v
retrieving revision 1.1
diff -u -r1.1 NegateFilter.java
--- NegateFilter.java	21 May 2003 09:17:45 -0000	1.1
+++ NegateFilter.java	27 May 2003 19:46:55 -0000
@@ -72,28 +72,6 @@
     private Filter filter;
 
     /**
-     * This is the protected, no-args constructor standard in all JDOM
-     * classes. It allows subclassers to get a raw instance with no
-     * initialization.
-     * <p>
-     * It intentionally leaves all instance variables null, allowing a
-     * lightweight subclass implementation.  The subclass is responsible for
-     * ensuring all the get and set methods behave as documented.
-     * </p>
-     * <p>
-     * When implementing a subclass which doesn't require full control over
-     * variable initialization, be aware that simply calling super() (or
-     * letting the compiler add the implicit super() call) will not
-     * initialize the instance variables which will cause many of the methods
-     * to throw a <code>NullPointerException</code>.  Therefore, the
-     * constructor for these subclasses should call one of the public
-     * constructors so variable initialization is handled automatically.
-     * </p>
-     */
-    protected NegateFilter() {
-    }
-
-    /**
      * Match if the supplied filter <b>does not</b> match.
      *
      * @param filter filter to use.
@@ -103,7 +81,7 @@
     }
 
     public boolean matches(Object obj) {
-        return filter.matches(obj) == false;
+        return !filter.matches(obj);
     }
 
     public Filter negate() {
Index: OrFilter.java
===================================================================
RCS file: /home/cvs/jdom/src/java/org/jdom/filter/OrFilter.java,v
retrieving revision 1.1
diff -u -r1.1 OrFilter.java
--- OrFilter.java	21 May 2003 09:17:45 -0000	1.1
+++ OrFilter.java	27 May 2003 19:46:55 -0000
@@ -71,32 +71,10 @@
       "@(#) $RCSfile: OrFilter.java,v $ $Revision: 1.1 $ $Date: 2003/05/21 09:17:45 $";
 
     /** Filter for left side of logical <b>or</b> */
-    protected Filter left;
+    private Filter left;
 
     /** Filter for right side of logical <b>or</b> */
-    protected Filter right;
-
-    /**
-     * This is the protected, no-args constructor standard in all JDOM
-     * classes. It allows subclassers to get a raw instance with no
-     * initialization.
-     * <p>
-     * It intentionally leaves all instance variables null, allowing a
-     * lightweight subclass implementation.  The subclass is responsible for
-     * ensuring all the get and set methods behave as documented.
-     * </p>
-     * <p>
-     * When implementing a subclass which doesn't require full control over
-     * variable initialization, be aware that simply calling super() (or
-     * letting the compiler add the implicit super() call) will not
-     * initialize the instance variables which will cause many of the methods
-     * to throw a <code>NullPointerException</code>.  Therefore, the
-     * constructor for these subclasses should call one of the public
-     * constructors so variable initialization is handled automatically.
-     * </p>
-     */
-    protected OrFilter() {
-    }
+    private Filter right;
 
     /**
      * Match if either of the supplied filters.


More information about the jdom-interest mailing list