You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2015/10/30 08:05:41 UTC
svn commit: r1711408 - in /sling/trunk/bundles/api/src:
main/java/org/apache/sling/api/resource/PathSet.java
test/java/org/apache/sling/api/resource/PathSetTest.java
Author: cziegeler
Date: Fri Oct 30 07:05:40 2015
New Revision: 1711408
URL: http://svn.apache.org/viewvc?rev=1711408&view=rev
Log:
SLING-5220 : Add Path and PathSet
Modified:
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/PathSet.java
sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/PathSetTest.java
Modified: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/PathSet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/PathSet.java?rev=1711408&r1=1711407&r2=1711408&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/PathSet.java (original)
+++ sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/PathSet.java Fri Oct 30 07:05:40 2015
@@ -36,7 +36,7 @@ public class PathSet implements Iterable
* @param paths The collection of path objects
* @return The path set
*/
- public static PathSet fromPathSet(final Collection<Path> paths) {
+ public static PathSet fromPathCollection(final Collection<Path> paths) {
final Set<Path> set = new HashSet<Path>();
for(final Path p : paths) {
set.add(p);
@@ -64,7 +64,7 @@ public class PathSet implements Iterable
* @param paths The collection of strings
* @return The path set
*/
- public static PathSet fromStringSet(final Collection<String> paths) {
+ public static PathSet fromStringCollection(final Collection<String> paths) {
final Set<Path> set = new HashSet<Path>();
for(final String p : paths) {
set.add(new Path(p));
@@ -162,6 +162,17 @@ public class PathSet implements Iterable
}
/**
+ * Create a unmodifiable set of strings
+ */
+ public Set<String> toStringSet() {
+ final Set<String> set = new HashSet<String>();
+ for(final Path p : this) {
+ set.add(p.getPath());
+ }
+ return Collections.unmodifiableSet(set);
+ }
+
+ /**
* Return an unmodifiable iterator for the paths.
*/
@Override
Modified: sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/PathSetTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/PathSetTest.java?rev=1711408&r1=1711407&r2=1711408&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/PathSetTest.java (original)
+++ sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/PathSetTest.java Fri Oct 30 07:05:40 2015
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertEqu
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.util.HashSet;
import java.util.Set;
@@ -50,7 +51,7 @@ public class PathSetTest {
strings.add("/a");
strings.add("/x/y");
strings.add("/z");
- final PathSet set = PathSet.fromStringSet(strings);
+ final PathSet set = PathSet.fromStringCollection(strings);
assertNotNull(set);
assertEqualSets(set, "/a", "/x/y", "/z");
}
@@ -66,7 +67,7 @@ public class PathSetTest {
paths.add(new Path("/a"));
paths.add(new Path("/x/y"));
paths.add(new Path("/z"));
- final PathSet set = PathSet.fromPathSet(paths);
+ final PathSet set = PathSet.fromPathCollection(paths);
assertNotNull(set);
assertEqualSets(set, "/a", "/x/y", "/z");
}
@@ -105,4 +106,20 @@ public class PathSetTest {
assertEquals(new Path("/x/y"), set.matches("/x/y/1"));
assertEquals(new Path("/x/y"), set.matches("/x/y/g/e"));
}
+
+ @Test public void testToStringSet() {
+ final PathSet set = PathSet.fromStrings("/a", "/x/y");
+
+ final Set<String> stringSet = set.toStringSet();
+ assertEquals(2, stringSet.size());
+ assertTrue(stringSet.contains("/a"));
+ assertTrue(stringSet.contains("/x/y"));
+
+ try {
+ stringSet.add("foo");
+ fail();
+ } catch ( final UnsupportedOperationException uoe) {
+ // expected
+ }
+ }
}