You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by je...@apache.org on 2018/06/14 13:14:52 UTC

[sling-whiteboard] branch master updated (5bf6310 -> 71dee9a)

This is an automated email from the ASF dual-hosted git repository.

jeb pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git.


    from 5bf6310  update README for simplified implementation
     new 5d9ce33  refactor of ResourceStream
     new 71dee9a  cleaning up predicates

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../sling/resource/filter/ResourceStream.java      | 34 ++++++++++++----------
 .../predicates/ChildResourcePredicates.java        | 18 +-----------
 .../resource/predicates/PropertyPredicates.java    | 14 ++++-----
 3 files changed, 26 insertions(+), 40 deletions(-)

-- 
To stop receiving notification emails like this one, please contact
jeb@apache.org.

[sling-whiteboard] 01/02: refactor of ResourceStream

Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jeb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git

commit 5d9ce33b126f24e16082500a8f76369ef7fc8373
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Tue Jun 12 22:47:36 2018 +0200

    refactor of ResourceStream
---
 .../sling/resource/filter/ResourceStream.java      | 34 ++++++++++++----------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/resource-filter/src/main/java/org/apache/sling/resource/filter/ResourceStream.java b/resource-filter/src/main/java/org/apache/sling/resource/filter/ResourceStream.java
index 2a6f865..db4d78a 100644
--- a/resource-filter/src/main/java/org/apache/sling/resource/filter/ResourceStream.java
+++ b/resource-filter/src/main/java/org/apache/sling/resource/filter/ResourceStream.java
@@ -13,10 +13,12 @@
  */
 package org.apache.sling.resource.filter;
 
+import java.util.Deque;
 import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.NoSuchElementException;
 import java.util.Spliterator;
 import java.util.Spliterators;
-import java.util.Stack;
 import java.util.function.Predicate;
 import java.util.stream.Stream;
 import java.util.stream.StreamSupport;
@@ -47,16 +49,14 @@ public class ResourceStream {
      * @return {@code Stream<Resource>} of unknown size.
      */
     public Stream<Resource> stream(Predicate<Resource> branchSelector) {
-        final Resource resource = this.resource;
+
         return StreamSupport.stream(Spliterators.spliteratorUnknownSize(new Iterator<Resource>() {
 
-            private final Stack<Iterator<Resource>> resources = new Stack<Iterator<Resource>>();
-            private Resource current;
-            private Iterator<Resource> iterator;
+            private final Deque<Iterator<Resource>> resources = new LinkedList<>();
+            private Resource current = resource;
 
             {
                 resources.push(resource.getChildren().iterator());
-                current = resource;
             }
 
             @Override
@@ -69,28 +69,30 @@ public class ResourceStream {
 
             @Override
             public Resource next() {
+                if (current == null) {
+                    seek();
+                }
+                if (current == null) {
+                    throw new NoSuchElementException();
+                }
                 Resource next = current;
                 current = null;
                 return next;
             }
 
             private boolean seek() {
-                while (true) {
-                    if (resources.isEmpty()) {
-                        return false;
-                    }
-                    iterator = resources.peek();
-                    if (!iterator.hasNext()) {
-                        resources.pop();
-                    } else {
+                while (!resources.isEmpty()) {
+                    Iterator<Resource> iterator = resources.peek();
+                    if (iterator.hasNext()) {
                         current = iterator.next();
                         if (branchSelector.test(current)) {
                             resources.push(current.getChildren().iterator());
-                            break;
                         }
+                        return true;
                     }
+                    resources.pop();
                 }
-                return true;
+                return false;
             }
 
         }, Spliterator.ORDERED | Spliterator.IMMUTABLE), false);

-- 
To stop receiving notification emails like this one, please contact
jeb@apache.org.

[sling-whiteboard] 02/02: cleaning up predicates

Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jeb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git

commit 71dee9a7a1b3d9130ba3db36c7af7528cf3a9175
Author: JE Bailey <ja...@sas.com>
AuthorDate: Wed Jun 13 16:05:20 2018 -0400

    cleaning up predicates
---
 .../resource/predicates/ChildResourcePredicates.java   | 18 +-----------------
 .../sling/resource/predicates/PropertyPredicates.java  | 14 +++++++-------
 2 files changed, 8 insertions(+), 24 deletions(-)

diff --git a/resource-predicates/src/main/java/org/apache/sling/resource/predicates/ChildResourcePredicates.java b/resource-predicates/src/main/java/org/apache/sling/resource/predicates/ChildResourcePredicates.java
index b9b5e56..ef486af 100644
--- a/resource-predicates/src/main/java/org/apache/sling/resource/predicates/ChildResourcePredicates.java
+++ b/resource-predicates/src/main/java/org/apache/sling/resource/predicates/ChildResourcePredicates.java
@@ -14,21 +14,6 @@
 package org.apache.sling.resource.predicates;
 
 import java.util.Objects;
-/*
- * Copyright 2016 Jason E Bailey
- *
- * Licensed 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.
- */
 import java.util.function.Predicate;
 
 import org.apache.sling.api.resource.Resource;
@@ -44,7 +29,6 @@ public class ChildResourcePredicates {
 
     private ChildResourcePredicates(String name) {
         this.name = Objects.requireNonNull(name, "name value may not be null");
-        ;
     }
 
     /**
@@ -55,7 +39,7 @@ public class ChildResourcePredicates {
      *            of the expected child resource
      * @return Object providing helper predicates for a child resource
      */
-    static public ChildResourcePredicates child(String name) {
+    public static ChildResourcePredicates child(String name) {
         return new ChildResourcePredicates(name);
     }
 
diff --git a/resource-predicates/src/main/java/org/apache/sling/resource/predicates/PropertyPredicates.java b/resource-predicates/src/main/java/org/apache/sling/resource/predicates/PropertyPredicates.java
index c238ab3..2a3c587 100644
--- a/resource-predicates/src/main/java/org/apache/sling/resource/predicates/PropertyPredicates.java
+++ b/resource-predicates/src/main/java/org/apache/sling/resource/predicates/PropertyPredicates.java
@@ -46,7 +46,6 @@ public class PropertyPredicates {
 
     private PropertyPredicates(String name) {
         this.key = Objects.requireNonNull(name, "value may not be null");
-        ;
     }
 
     /**
@@ -56,7 +55,7 @@ public class PropertyPredicates {
      *            key value of the property
      * @return PropertyPredicate instance
      */
-    static public PropertyPredicates property(String name) {
+    public static PropertyPredicates property(String name) {
         return new PropertyPredicates(name);
     }
 
@@ -122,7 +121,7 @@ public class PropertyPredicates {
             @SuppressWarnings("unchecked")
             T propValue = (T) valueMapOf(resource).get(key, type.getClass());
             if (propValue instanceof Comparable<?>) {
-                return ((Comparable<T>) propValue).compareTo(type) > 0;
+                return propValue.compareTo(type) > 0;
             }
             return type.equals(propValue);
         };
@@ -139,7 +138,7 @@ public class PropertyPredicates {
             @SuppressWarnings("unchecked")
             T propValue = (T) valueMapOf(resource).get(key, type.getClass());
             if (propValue instanceof Comparable<?>) {
-                return ((Comparable<T>) propValue).compareTo(type) >= 0;
+                return propValue.compareTo(type) >= 0;
             }
             return type.equals(propValue);
         };
@@ -156,7 +155,7 @@ public class PropertyPredicates {
             @SuppressWarnings("unchecked")
             T propValue = (T) valueMapOf(resource).get(key, type.getClass());
             if (propValue instanceof Comparable<?>) {
-                return ((Comparable<T>) propValue).compareTo(type) < 0;
+                return propValue.compareTo(type) < 0;
             }
             return type.equals(propValue);
         };
@@ -173,7 +172,7 @@ public class PropertyPredicates {
             @SuppressWarnings("unchecked")
             T propValue = (T) valueMapOf(resource).get(key, type.getClass());
             if (propValue instanceof Comparable<?>) {
-                return ((Comparable<T>) propValue).compareTo(type) >= 0;
+                return propValue.compareTo(type) >= 0;
             }
             return type.equals(propValue);
         };
@@ -208,6 +207,7 @@ public class PropertyPredicates {
                 return false;
             }
             // validate that all items in values have matches in properties
+            
             for (T item : values) {
                 innerloop: {
                     for (T propItem : propValues) {
@@ -318,7 +318,7 @@ public class PropertyPredicates {
         if (resource == null || ResourceUtil.isNonExistingResource(resource)) {
             return ValueMap.EMPTY;
         }
-        return resource.adaptTo(ValueMap.class);
+        return resource.getValueMap();
     }
 
 }

-- 
To stop receiving notification emails like this one, please contact
jeb@apache.org.