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/08 18:50:24 UTC
[sling-whiteboard] 02/02: formatting standard and clean up
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 057812bf7b16e475b90cc329fdb0717406f13e9e
Author: Jason E Bailey <je...@apache.org>
AuthorDate: Fri Jun 8 14:50:12 2018 -0400
formatting standard and clean up
---
.../resource/predicates/PropertyPredicates.java | 5 ++---
.../resource/predicates/ResourcePredicates.java | 3 ++-
.../resource/stream/ResourcePredicateTest.java | 26 +++++++++++++---------
3 files changed, 19 insertions(+), 15 deletions(-)
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 abfb2ee..c238ab3 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
@@ -15,7 +15,6 @@ package org.apache.sling.resource.predicates;
import java.lang.reflect.Array;
import java.util.Calendar;
-import java.util.Date;
import java.util.Objects;
import java.util.function.Predicate;
@@ -88,10 +87,10 @@ public class PropertyPredicates {
* earliest acceptable value
* @return predicate
*/
- public Predicate<Resource> isAfter(Date when) {
+ public Predicate<Resource> isAfter(Calendar when) {
Objects.requireNonNull(when, "value may not be null");
return value -> {
- Date then = value.adaptTo(ValueMap.class).get(key, Date.class);
+ Calendar then = value.adaptTo(ValueMap.class).get(key, Calendar.class);
if (then != null) {
return then.after(when);
}
diff --git a/resource-predicates/src/main/java/org/apache/sling/resource/predicates/ResourcePredicates.java b/resource-predicates/src/main/java/org/apache/sling/resource/predicates/ResourcePredicates.java
index c417f3b..ac7e16c 100644
--- a/resource-predicates/src/main/java/org/apache/sling/resource/predicates/ResourcePredicates.java
+++ b/resource-predicates/src/main/java/org/apache/sling/resource/predicates/ResourcePredicates.java
@@ -43,6 +43,7 @@ public class ResourcePredicates {
public static Predicate<Resource> maxDepth(final int depth) {
return new Predicate<Resource>() {
int startingDepth = -1;
+
@Override
public boolean test(Resource resource) {
int currentDepth = resource.getPath().split("/").length;
@@ -51,7 +52,7 @@ public class ResourcePredicates {
}
return currentDepth - startingDepth < depth;
}
-
+
};
}
diff --git a/resource-predicates/src/test/java/org/apache/sling/resource/stream/ResourcePredicateTest.java b/resource-predicates/src/test/java/org/apache/sling/resource/stream/ResourcePredicateTest.java
index 67ddec2..a7788ed 100644
--- a/resource-predicates/src/test/java/org/apache/sling/resource/stream/ResourcePredicateTest.java
+++ b/resource-predicates/src/test/java/org/apache/sling/resource/stream/ResourcePredicateTest.java
@@ -21,8 +21,8 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
-import java.util.Date;
import java.util.List;
+import java.util.TimeZone;
import java.util.stream.Collectors;
import org.apache.sling.api.resource.Resource;
@@ -36,18 +36,21 @@ public class ResourcePredicateTest {
@Rule
public final SlingContext context = new SlingContext();
- private Date midPoint;
+ private Calendar midPoint;
private static String DATE_STRING = "Thu Aug 07 2013 16:32:59 GMT+0200";
private static String DATE_FORMAT = "EEE MMM dd yyyy HH:mm:ss 'GMT'Z";
private List<Resource> list;
-
+
@Before
public void setUp() throws ParseException {
context.load().json("/data.json", "/content/sample/en");
- midPoint = new SimpleDateFormat(DATE_FORMAT).parse(DATE_STRING);
+ Calendar cal = Calendar.getInstance();
+ cal.setTimeZone(TimeZone.getTimeZone("GMT+0200"));
+ cal.setTime(new SimpleDateFormat(DATE_FORMAT).parse(DATE_STRING));
+ midPoint = cal;
Resource resource = context.resourceResolver().getResource("/content/sample/en");
list = new ArrayList<>();
resource.listChildren().forEachRemaining(list::add);
@@ -70,30 +73,31 @@ public class ResourcePredicateTest {
@Test
public void testBeforeThenDate() {
List<Resource> found = list.stream()
- .filter(property("jcr:content/created").isBefore(Calendar.getInstance().getTime()))
+ .filter(property("jcr:content/created").isBefore(Calendar.getInstance()))
.collect(Collectors.toList());
assertEquals(7, found.size());
}
@Test
public void testAfterThenDate() {
- List<Resource> found = list.stream()
- .filter( child("jcr:content").has(property("created").isAfter(new Date(0))))
+ Calendar cal = Calendar.getInstance();
+ cal.setTimeInMillis(0);
+ List<Resource> found = list.stream().filter(child("jcr:content").has(property("created").isAfter(cal)))
.collect(Collectors.toList());
assertEquals(7, found.size());
}
@Test
public void testAfterMidDate() {
- List<Resource> found = list.stream()
- .filter(property("jcr:content/created").isAfter(midPoint)).collect(Collectors.toList());
+ List<Resource> found = list.stream().filter(property("jcr:content/created").isAfter(midPoint))
+ .collect(Collectors.toList());
assertEquals(4, found.size());
}
@Test
public void testBeforeMidDate() {
- List<Resource> found = list.stream()
- .filter(property("jcr:content/created").isBefore(midPoint)).collect(Collectors.toList());
+ List<Resource> found = list.stream().filter(property("jcr:content/created").isBefore(midPoint))
+ .collect(Collectors.toList());
assertEquals(1, found.size());
}
--
To stop receiving notification emails like this one, please contact
jeb@apache.org.