public void testDifference() { Set<String> friends = Sets.newHashSet("Tom", "Joe", "Dave"); Set<String> enemies = Sets.newHashSet("Dick", "Harry", "Tom"); Set<String> goodFriends = Sets.difference(friends, enemies); assertEquals(2, goodFriends.size()); ImmutableSet<String> immut = Sets.difference(friends, enemies).immutableCopy(); HashSet<String> mut = Sets.difference(friends, enemies).copyInto(new HashSet<String>()); enemies.add("Dave"); assertEquals(1, goodFriends.size()); assertEquals(2, immut.size()); assertEquals(2, mut.size()); }
public void testIntersection() { Set<String> friends = Sets.newHashSet("Tom", "Joe", "Dave"); Set<String> enemies = Sets.newHashSet("Dick", "Harry", "Tom"); Set<String> frenemies = Sets.intersection(friends, enemies); assertEquals(1, frenemies.size()); ImmutableSet<String> immut = Sets.intersection(friends, enemies).immutableCopy(); HashSet<String> mut = Sets.intersection(friends, enemies).copyInto(new HashSet<String>()); enemies.add("Joe"); assertEquals(2, frenemies.size()); assertEquals(1, immut.size()); assertEquals(1, mut.size()); }
public void testUnion() { Set<String> all = Sets.union(friends, enemies); assertEquals(5, all.size()); ImmutableSet<String> immut = Sets.union(friends, enemies).immutableCopy(); HashSet<String> mut = Sets.union(friends, enemies).copyInto(new HashSet<String>()); enemies.add("Buck"); assertEquals(6, all.size()); assertEquals(5, immut.size()); assertEquals(5, mut.size()); }
public void testSymmetricDifference() { Set<String> friends = Sets.newHashSet("Tom", "Joe", "Dave"); Set<String> enemies = Sets.newHashSet("Dick", "Harry", "Tom"); Set<String> symmetricDifferenceFriendsFirst = Sets.symmetricDifference( friends, enemies); assertEquals(4, symmetricDifferenceFriendsFirst.size()); Set<String> symmetricDifferenceEnemiesFirst = Sets.symmetricDifference( enemies, friends); assertEquals(4, symmetricDifferenceEnemiesFirst.size()); assertEquals(symmetricDifferenceFriendsFirst, symmetricDifferenceEnemiesFirst); ImmutableSet<String> immut = Sets.symmetricDifference(friends, enemies).immutableCopy(); HashSet<String> mut = Sets.symmetricDifference(friends, enemies) .copyInto(new HashSet<String>()); enemies.add("Dave"); assertEquals(3, symmetricDifferenceFriendsFirst.size()); assertEquals(4, immut.size()); assertEquals(4, mut.size()); immut = Sets.symmetricDifference(enemies, friends).immutableCopy(); mut = Sets.symmetricDifference(enemies, friends). copyInto(new HashSet<String>()); friends.add("Harry"); assertEquals(2, symmetricDifferenceEnemiesFirst.size()); assertEquals(3, immut.size()); assertEquals(3, mut.size()); } }
@Override public void session(Set<Principal> principals, Set<Object> attributes) throws AuthenticationException { Set<Role> allowedRoles = allAuthorizedRoles(principals); Set<Role> desiredRoles = principals.stream() .filter(DesiredRole.class::isInstance) .map(DesiredRole.class::cast) .map(DesiredRole::getName) .map(Role::new) .collect(Collectors.toSet()); Set<Role> unauthorizedRoles = Sets.difference(desiredRoles, allowedRoles) .copyInto(new HashSet<>()); if (!unauthorizedRoles.isEmpty()) { String description = unauthorizedRoles.size() == 1 ? unauthorizedRoles.iterator().next().toString() : unauthorizedRoles.stream().map(LoginAttribute::toString) .collect(Collectors.joining(",", "[", "]")); throw new AuthenticationException("unauthorized for " + description); } attributes.addAll(desiredRoles); Sets.difference(allowedRoles, desiredRoles).stream() .map(Role::getRole) .map(UnassertedRole::new) .forEach(attributes::add); }
@Test public void testSortedIntersectionReproCON_245() { Set<Long> a = Sets.newTreeSet(Arrays.<Long> asList(1424523725311000L, 1424523725341000L, 1424523725370000L, 1424523725421002L, 1424523725491000L, 1424523725514000L, 1424523725534000L, 1424523725565000L, 1424523725584003L, 1424523725605000L, 1424523725622002L, 1424523725641002L, 1424523725659002L, 1424523725676004L, 1424523725691000L, 1424523725710000L, 1424523725724000L, 1424523725738000L, 1424523725786002L, 1424523725801000L, 1424523725823002L, 1424523725841000L, 1424523725868000L, 1424523725895000L, 1424523725909000L, 1424523725924000L, 1424523725937002L, 1424523725963000L, 1424523725975002L, 1424523725987000L, 1424523725999003L, 1424523726012000L, 1424523726038000L, 1424523726050000L)); Set<Long> b = Sets.newTreeSet(Arrays.asList(1424523725341000L, 1424523725491000L, 1424523725514000L, 1424523725534000L, 1424523725584003L, 1424523725605000L, 1424523725641002L, 1424523725659002L, 1424523725691000L, 1424523725724000L, 1424523725753000L, 1424523725786002L, 1424523725801000L, 1424523725823002L, 1424523725841000L, 1424523725937002L, 1424523725963000L, 1424523725975002L, 1424523725987000L, 1424523725999003L, 1424523726012000L, 1424523726050000L)); Assert.assertEquals(TSets.intersection(a, b), Sets.intersection(a, b).copyInto(Sets.<Long> newHashSet())); }
@Override public synchronized void nodeChanged() throws Exception { Set<Mode> oldModes = _mode.getModeAsSet(); apply(_cache.getCurrentData()); Set<Mode> curModes = _mode.getModeAsSet(); // old cur down up // none,tls - tls = none // none,tls - none = tls // none - tls = none tls // tls - none = tls none // none - none,tls = tls // tls - none,tls = none Set<Mode> up = Sets.difference(curModes, oldModes).copyInto(new HashSet<>()); LOGGER.info("Following modes from CoreDomain are being brought up: [{}]", Joiner.on(',').join(up)); up.stream().forEach(u -> _reset.accept(u, State.BRING_UP)); Set<Mode> down = Sets.difference(oldModes, curModes).copyInto(new HashSet<>()); LOGGER.info("Following modes from CoreDomain are being taken down: [{}]", Joiner.on(',').join(down)); down.stream().forEach(d -> _reset.accept(d, State.TEAR_DOWN)); }
private Set<ApplicationRole> calculateRolesToBeAdded(ApplicationUser user, Set<String> groupsToBeAdded) { if(log.isTraceEnabled()) { log.trace("Calculating application access for {} with groups {}", user, groupsToBeAdded); } final Set<ApplicationRole> existingUserRoles = applicationRoleManager.getRolesForUser(user); final Set<ApplicationRole> rolesToBeAdded = findEffectiveApplicationsByGroups(Optional.ofNullable(user.getDirectoryId()), groupsToBeAdded); final Set<ApplicationRole> rolesToBeAddedToThisUser = Sets.difference(rolesToBeAdded, existingUserRoles).copyInto(new HashSet<>()); final Sets.SetView<ApplicationRole> effectiveRolesAfterAdd = Sets.union(existingUserRoles, rolesToBeAdded); //check whether user has access to any other application than core if (effectiveRolesAfterAdd.stream().anyMatch(r -> !r.getKey().equals(ApplicationKeys.CORE))) { rolesToBeAddedToThisUser.remove(applicationRoleManager.getRole(ApplicationKeys.CORE).getOrNull()); } return rolesToBeAddedToThisUser; }
public void testDifference() { Set<String> friends = Sets.newHashSet("Tom", "Joe", "Dave"); Set<String> enemies = Sets.newHashSet("Dick", "Harry", "Tom"); Set<String> goodFriends = Sets.difference(friends, enemies); assertEquals(2, goodFriends.size()); ImmutableSet<String> immut = Sets.difference(friends, enemies).immutableCopy(); HashSet<String> mut = Sets.difference(friends, enemies).copyInto(new HashSet<String>()); enemies.add("Dave"); assertEquals(1, goodFriends.size()); assertEquals(2, immut.size()); assertEquals(2, mut.size()); }
public void testIntersection() { Set<String> friends = Sets.newHashSet("Tom", "Joe", "Dave"); Set<String> enemies = Sets.newHashSet("Dick", "Harry", "Tom"); Set<String> frenemies = Sets.intersection(friends, enemies); assertEquals(1, frenemies.size()); ImmutableSet<String> immut = Sets.intersection(friends, enemies).immutableCopy(); HashSet<String> mut = Sets.intersection(friends, enemies).copyInto(new HashSet<String>()); enemies.add("Joe"); assertEquals(2, frenemies.size()); assertEquals(1, immut.size()); assertEquals(1, mut.size()); }
public static LinkedHashSet<String> intersectPinsSets(PsseRegister psseReg1, PsseRegister psseReg2) { LinkedHashSet<String> retSet = new LinkedHashSet<>(); return Sets.difference(Sets.intersection(psseReg1.pins, psseReg2.pins), modelsPinsToBeIgnored).copyInto(retSet); }
public void testUnion() { Set<String> all = Sets.union(friends, enemies); assertEquals(5, all.size()); ImmutableSet<String> immut = Sets.union(friends, enemies).immutableCopy(); HashSet<String> mut = Sets.union(friends, enemies).copyInto(new HashSet<String>()); enemies.add("Buck"); assertEquals(6, all.size()); assertEquals(5, immut.size()); assertEquals(5, mut.size()); }
@Test public void testUnion() { Set<Integer> a = Sets.newHashSet(); Set<Integer> b = Sets.newHashSet(); populate(a); populate(b); Assert.assertEquals(TSets.union(a, b), Sets.union(a, b).copyInto(Sets.<Integer> newHashSet())); }
@Test public void testMixedIntersection() { Set<Integer> a = Sets.newTreeSet(); Set<Integer> b = Sets.newHashSet(); populate(a); populate(b); Assert.assertEquals(TSets.intersection(a, b), Sets.intersection(a, b).copyInto(Sets.<Integer> newHashSet())); }
@Test public void testIntersection() { Set<Integer> a = Sets.newHashSet(); Set<Integer> b = Sets.newHashSet(); populate(a); populate(b); Assert.assertEquals(TSets.intersection(a, b), Sets.intersection(a, b).copyInto(Sets.<Integer> newHashSet())); }
@Test public void testSortedIntersection() { Set<Integer> a = Sets.newTreeSet(); Set<Integer> b = Sets.newTreeSet(); populate(a); populate(b); Assert.assertEquals(TSets.intersection(a, b), Sets.intersection(a, b).copyInto(Sets.<Integer> newHashSet())); }
public void testSymmetricDifference() { Set<String> friends = Sets.newHashSet("Tom", "Joe", "Dave"); Set<String> enemies = Sets.newHashSet("Dick", "Harry", "Tom"); Set<String> symmetricDifferenceFriendsFirst = Sets.symmetricDifference(friends, enemies); assertEquals(4, symmetricDifferenceFriendsFirst.size()); Set<String> symmetricDifferenceEnemiesFirst = Sets.symmetricDifference(enemies, friends); assertEquals(4, symmetricDifferenceEnemiesFirst.size()); assertEquals(symmetricDifferenceFriendsFirst, symmetricDifferenceEnemiesFirst); ImmutableSet<String> immut = Sets.symmetricDifference(friends, enemies).immutableCopy(); HashSet<String> mut = Sets.symmetricDifference(friends, enemies).copyInto(new HashSet<String>()); enemies.add("Dave"); assertEquals(3, symmetricDifferenceFriendsFirst.size()); assertEquals(4, immut.size()); assertEquals(4, mut.size()); immut = Sets.symmetricDifference(enemies, friends).immutableCopy(); mut = Sets.symmetricDifference(enemies, friends).copyInto(new HashSet<String>()); friends.add("Harry"); assertEquals(2, symmetricDifferenceEnemiesFirst.size()); assertEquals(3, immut.size()); assertEquals(3, mut.size()); } }