jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From k...@apache.org
Subject svn commit: r1866118 - in /jackrabbit/commons/filevault/trunk/vault-core/src: main/java/org/apache/jackrabbit/vault/fs/api/ main/java/org/apache/jackrabbit/vault/fs/config/ test/java/org/apache/jackrabbit/vault/fs/filter/
Date Fri, 30 Aug 2019 06:37:46 GMT
Author: kwin
Date: Fri Aug 30 06:37:46 2019
New Revision: 1866118

URL: http://svn.apache.org/viewvc?rev=1866118&view=rev
Log:
JCRVLT-360 add toString, equals and hashCode to all filter related
classes

This closes #55

Modified:
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/FilterSet.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/PathFilter.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/DefaultWorkspaceFilter.java
    jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/fs/filter/WorkspaceFilterTest.java

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/FilterSet.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/FilterSet.java?rev=1866118&r1=1866117&r2=1866118&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/FilterSet.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/FilterSet.java
Fri Aug 30 06:37:46 2019
@@ -17,6 +17,8 @@
 
 package org.apache.jackrabbit.vault.fs.api;
 
+import java.io.PrintWriter;
+import java.io.StringWriter;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.LinkedList;
@@ -284,6 +286,14 @@ public abstract class FilterSet<E extend
 
     }
 
+    @Override
+    public String toString() {
+        StringWriter stringWriter = new StringWriter();
+        dump(new DumpContext(new PrintWriter(stringWriter)), true);
+        return stringWriter.toString();
+    }
+
+
     /**
      * Holds a filter entry
      */
@@ -363,5 +373,13 @@ public abstract class FilterSet<E extend
             return include == entry.include && filter.equals(entry.filter);
         }
 
+        @Override
+        public String toString() {
+            StringWriter stringWriter = new StringWriter();
+            dump(new DumpContext(new PrintWriter(stringWriter)), true);
+            return stringWriter.toString();
+        }
+
+        
     }
 }
\ No newline at end of file

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/PathFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/PathFilter.java?rev=1866118&r1=1866117&r2=1866118&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/PathFilter.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/PathFilter.java
Fri Aug 30 06:37:46 2019
@@ -17,6 +17,9 @@
 
 package org.apache.jackrabbit.vault.fs.api;
 
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
@@ -25,7 +28,7 @@ import javax.annotation.Nullable;
  * It is usually part of a {@link PathFilterSet}.
  *
  */
-public interface PathFilter extends Filter {
+public interface PathFilter extends Filter, Dumpable {
 
     /**
      * The "Catch all" item filter.
@@ -59,6 +62,24 @@ public interface PathFilter extends Filt
         public PathFilter translate(PathMapping mapping) {
             return this;
         }
+
+        @Override
+        public int hashCode() {
+            return 1;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            return (obj == this);
+        }
+
+        @Override
+        public String toString() {
+            StringWriter stringWriter = new StringWriter();
+            dump(new DumpContext(new PrintWriter(stringWriter)), true);
+            return stringWriter.toString();
+        }
+
     };
 
     /**
@@ -93,6 +114,23 @@ public interface PathFilter extends Filt
         public PathFilter translate(PathMapping mapping) {
             return this;
         }
+
+        @Override
+        public int hashCode() {
+            return 2;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            return (obj == this);
+        }
+
+        @Override
+        public String toString() {
+            StringWriter stringWriter = new StringWriter();
+            dump(new DumpContext(new PrintWriter(stringWriter)), true);
+            return stringWriter.toString();
+        }
     };
 
     /**

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/DefaultWorkspaceFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/DefaultWorkspaceFilter.java?rev=1866118&r1=1866117&r2=1866118&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/DefaultWorkspaceFilter.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/DefaultWorkspaceFilter.java
Fri Aug 30 06:37:46 2019
@@ -23,7 +23,10 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
 import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
@@ -209,7 +212,7 @@ public class DefaultWorkspaceFilter impl
         if (importMode != null) {
             return importMode;
         }
-        FilterSet set = getCoveringFilterSet(path);
+        FilterSet<PathFilter> set = getCoveringFilterSet(path);
         return set == null ? ImportMode.REPLACE : set.getImportMode();
     }
 
@@ -578,6 +581,67 @@ public class DefaultWorkspaceFilter impl
         }
     }
 
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((globalIgnored == null) ? 0 : globalIgnored.hashCode());
+        result = prime * result + ((importMode == null) ? 0 : importMode.hashCode());
+        result = prime * result + ((nodesFilterSets == null) ? 0 : nodesFilterSets.hashCode());
+        result = prime * result + ((propsFilterSets == null) ? 0 : propsFilterSets.hashCode());
+        result = prime * result + ((referenceFilterSets == null) ? 0 : referenceFilterSets.hashCode());
+        result = prime * result + Arrays.hashCode(source);
+        long temp;
+        temp = Double.doubleToLongBits(version);
+        result = prime * result + (int) (temp ^ (temp >>> 32));
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        DefaultWorkspaceFilter other = (DefaultWorkspaceFilter) obj;
+        if (globalIgnored == null) {
+            if (other.globalIgnored != null)
+                return false;
+        } else if (!globalIgnored.equals(other.globalIgnored))
+            return false;
+        if (importMode != other.importMode)
+            return false;
+        if (nodesFilterSets == null) {
+            if (other.nodesFilterSets != null)
+                return false;
+        } else if (!nodesFilterSets.equals(other.nodesFilterSets))
+            return false;
+        if (propsFilterSets == null) {
+            if (other.propsFilterSets != null)
+                return false;
+        } else if (!propsFilterSets.equals(other.propsFilterSets))
+            return false;
+        if (referenceFilterSets == null) {
+            if (other.referenceFilterSets != null)
+                return false;
+        } else if (!referenceFilterSets.equals(other.referenceFilterSets))
+            return false;
+        if (!Arrays.equals(source, other.source))
+            return false;
+        if (Double.doubleToLongBits(version) != Double.doubleToLongBits(other.version))
+            return false;
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        StringWriter stringWriter = new StringWriter();
+        dump(new DumpContext(new PrintWriter(stringWriter)), true);
+        return stringWriter.toString();
+    }
+
     /**
      * internal class to mark the property filter entries. eventually promote to outer class
and adjust the 'contains'
      * code accordingly. But since the filter set are publicly accessible, this would introduce
backward compatibility

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/fs/filter/WorkspaceFilterTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/fs/filter/WorkspaceFilterTest.java?rev=1866118&r1=1866117&r2=1866118&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/fs/filter/WorkspaceFilterTest.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/fs/filter/WorkspaceFilterTest.java
Fri Aug 30 06:37:46 2019
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.vault.fs.filter;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.List;
 
 import org.apache.jackrabbit.vault.fs.api.FilterSet;
@@ -32,6 +33,7 @@ import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
@@ -192,4 +194,24 @@ public class WorkspaceFilterTest {
 
     }
 
+    @Test
+    public  void testEquals() throws IOException, ConfigurationException {
+        DefaultWorkspaceFilter filter = new DefaultWorkspaceFilter();
+        try (InputStream input = getClass().getResourceAsStream("workspacefilters/complex.xml"))
{
+            filter.load(input);
+        }
+        DefaultWorkspaceFilter filter2 = new DefaultWorkspaceFilter();
+        try (InputStream input = getClass().getResourceAsStream("workspacefilters/complex.xml"))
{
+            filter2.load(input);
+        }
+        assertEquals(filter, filter2);
+        DefaultWorkspaceFilter filter3 = new DefaultWorkspaceFilter();
+        try (InputStream input = getClass().getResourceAsStream("workspacefilters/mixed.xml"))
{
+            filter3.load(input);
+        }
+        assertNotEquals(filter, filter3);
+        // modify filter2 slightly
+        filter2.setGlobalIgnored(PathFilter.NONE);
+        assertNotEquals(filter, filter2);
+    }
 }
\ No newline at end of file



Mime
View raw message