|
20 | 20 | import java.util.List; |
21 | 21 | import java.util.Map; |
22 | 22 | import java.util.Set; |
| 23 | +import java.util.stream.Collectors; |
| 24 | +import java.util.stream.IntStream; |
23 | 25 |
|
24 | | -import org.apache.jackrabbit.guava.common.collect.Sets; |
25 | 26 | import org.apache.jackrabbit.api.JackrabbitSession; |
26 | 27 | import org.apache.jackrabbit.oak.AbstractSecurityTest; |
27 | 28 | import org.apache.jackrabbit.oak.api.PropertyState; |
@@ -63,9 +64,9 @@ public void hasPrivilegesTest() throws Exception { |
63 | 64 |
|
64 | 65 | // tests all possible 256 shuffles |
65 | 66 | for (CompositionType type : CompositionType.values()) { |
66 | | - for (Set<String> granted1 : Sets.powerSet(supp1)) { |
67 | | - for (Set<String> granted2 : Sets.powerSet(supp2)) { |
68 | | - for (Set<String> ps : Sets.powerSet(all)) { |
| 67 | + for (Set<String> granted1 : powerSet(supp1)) { |
| 68 | + for (Set<String> granted2 : powerSet(supp2)) { |
| 69 | + for (Set<String> ps : powerSet(all)) { |
69 | 70 | CompositePermissionProvider cpp = buildCpp(supp1, granted1, supp2, granted2, type, null); |
70 | 71 |
|
71 | 72 | boolean expected = expected(ps, supp1, granted1, supp2, granted2, type, true); |
@@ -99,9 +100,9 @@ public void isGrantedTest() throws Exception { |
99 | 100 | Tree tree = mock(Tree.class, withSettings().extraInterfaces(ReadOnly.class)); |
100 | 101 | // tests all possible 256 shuffles |
101 | 102 | for (CompositionType type : CompositionType.values()) { |
102 | | - for (Set<String> granted1 : Sets.powerSet(supp1)) { |
103 | | - for (Set<String> granted2 : Sets.powerSet(supp2)) { |
104 | | - for (Set<String> ps : Sets.powerSet(all)) { |
| 103 | + for (Set<String> granted1 : powerSet(supp1)) { |
| 104 | + for (Set<String> granted2 : powerSet(supp2)) { |
| 105 | + for (Set<String> ps : powerSet(all)) { |
105 | 106 | CompositePermissionProvider cpp = buildCpp(supp1, granted1, supp2, granted2, type, grantMap); |
106 | 107 | boolean expected = expected(ps, supp1, granted1, supp2, granted2, type, false); |
107 | 108 |
|
@@ -140,9 +141,9 @@ public void getRepositoryPermissionTest() throws Exception { |
140 | 141 |
|
141 | 142 | // tests all possible 256 shuffles |
142 | 143 | for (CompositionType type : CompositionType.values()) { |
143 | | - for (Set<String> granted1 : Sets.powerSet(supp1)) { |
144 | | - for (Set<String> granted2 : Sets.powerSet(supp2)) { |
145 | | - for (Set<String> ps : Sets.powerSet(all)) { |
| 144 | + for (Set<String> granted1 : powerSet(supp1)) { |
| 145 | + for (Set<String> granted2 : powerSet(supp2)) { |
| 146 | + for (Set<String> ps : powerSet(all)) { |
146 | 147 | CompositePermissionProvider cpp = buildCpp(supp1, granted1, supp2, granted2, type, grantMap); |
147 | 148 |
|
148 | 149 | boolean expected = expected(ps, supp1, granted1, supp2, granted2, type, false); |
@@ -170,9 +171,9 @@ public void getTreePermissionTest() throws Exception { |
170 | 171 |
|
171 | 172 | // tests all possible 256 shuffles |
172 | 173 | for (CompositionType type : CompositionType.values()) { |
173 | | - for (Set<String> granted1 : Sets.powerSet(supp1)) { |
174 | | - for (Set<String> granted2 : Sets.powerSet(supp2)) { |
175 | | - for (Set<String> ps : Sets.powerSet(all)) { |
| 174 | + for (Set<String> granted1 : powerSet(supp1)) { |
| 175 | + for (Set<String> granted2 : powerSet(supp2)) { |
| 176 | + for (Set<String> ps : powerSet(all)) { |
176 | 177 | CompositePermissionProvider cpp = buildCpp(supp1, granted1, supp2, granted2, type, grantMap); |
177 | 178 |
|
178 | 179 | boolean expected = expected(ps, supp1, granted1, supp2, granted2, type, false); |
@@ -410,4 +411,13 @@ public boolean isGranted(long permissions, @NotNull PropertyState property) { |
410 | 411 | } |
411 | 412 |
|
412 | 413 | } |
| 414 | + |
| 415 | + private <T> Set<Set<T>> powerSet(final Set<T> s) { |
| 416 | + final T[] arr = s.toArray((T[]) new Object[0]); |
| 417 | + return IntStream |
| 418 | + .range(0, (int) Math.pow(2, arr.length)) |
| 419 | + .parallel() //performance improvement |
| 420 | + .mapToObj(e -> IntStream.range(0, arr.length).filter(i -> (e & (0b1 << i)) != 0).mapToObj(i -> arr[i]).collect(Collectors.toSet())) |
| 421 | + .collect(Collectors.toSet()); |
| 422 | + } |
413 | 423 | } |
0 commit comments