jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1547062 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/observation/filter/PropertyPredicate.java test/java/org/apache/jackrabbit/oak/plugins/observation/filter/PropertyPredicateTest.java
Date Mon, 02 Dec 2013 15:38:06 GMT
Author: mduerig
Date: Mon Dec  2 15:38:06 2013
New Revision: 1547062

URL: http://svn.apache.org/r1547062
Log:
OAK-1133: Observation listener PLUS Replace NodeTypeFilter with UniversalFilter
Predicate on property

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/PropertyPredicate.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/observation/filter/PropertyPredicateTest.java

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/PropertyPredicate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/PropertyPredicate.java?rev=1547062&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/PropertyPredicate.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/PropertyPredicate.java
Mon Dec  2 15:38:06 2013
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.jackrabbit.oak.plugins.observation.filter;
+
+import com.google.common.base.Predicate;
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.core.ImmutableTree;
+
+/**
+ * Predicate on property values. This property holds if and only if
+ * the tree has a property of the given {@code name} and the given
+ * {@code propertyPredicate} holds on that property.
+ */
+public class PropertyPredicate implements Predicate<ImmutableTree> {
+    private final String name;
+    private final Predicate<PropertyState> propertyPredicate;
+
+    /**
+     * @param name               name of the property
+     * @param propertyPredicate  predicate on the named property
+     */
+    public PropertyPredicate(String name, Predicate<PropertyState> propertyPredicate)
{
+        this.name = name;
+        this.propertyPredicate = propertyPredicate;
+    }
+
+    @Override
+    public boolean apply(ImmutableTree tree) {
+        PropertyState property = tree.getProperty(name);
+        return property != null && propertyPredicate.apply(property);
+    }
+}

Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/observation/filter/PropertyPredicateTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/observation/filter/PropertyPredicateTest.java?rev=1547062&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/observation/filter/PropertyPredicateTest.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/observation/filter/PropertyPredicateTest.java
Mon Dec  2 15:38:06 2013
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.jackrabbit.oak.plugins.observation.filter;
+
+import static org.apache.jackrabbit.oak.api.Type.STRING;
+import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import com.google.common.base.Predicate;
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.core.ImmutableTree;
+import org.junit.Test;
+
+public class PropertyPredicateTest {
+
+    @Test
+    public void propertyMatch() {
+        String name = "foo";
+        final String value = "bar";
+        PropertyPredicate p = new PropertyPredicate(name, new Predicate<PropertyState>()
{
+            @Override
+            public boolean apply(PropertyState property) {
+                return value.equals(property.getValue(STRING));
+            }
+        });
+
+        assertTrue(p.apply(createWithProperty(name, value)));
+    }
+
+    @Test
+    public void propertyMiss() {
+        String name = "foo";
+        final String value = "bar";
+        PropertyPredicate p = new PropertyPredicate(name, new Predicate<PropertyState>()
{
+            @Override
+            public boolean apply(PropertyState property) {
+                return "baz".equals(property.getValue(STRING));
+            }
+        });
+
+        assertFalse(p.apply(createWithProperty(name, value)));
+    }
+
+    @Test
+    public void nonExistingProperty() {
+        String name = "foo";
+        final String value = "bar";
+        PropertyPredicate p = new PropertyPredicate("any", new Predicate<PropertyState>()
{
+            @Override
+            public boolean apply(PropertyState property) {
+                return value.equals(property.getValue(STRING));
+            }
+        });
+
+        assertFalse(p.apply(createWithProperty(name, value)));
+    }
+
+    private static ImmutableTree createWithProperty(String name, String value) {
+        return new ImmutableTree(EMPTY_NODE.builder()
+                .setProperty(name, value)
+                .getNodeState());
+    }
+
+
+}



Mime
View raw message