@Test public void normalizingAddTo() { Set<String> realms = new HashSet<>(); realms.add("realm1"); realms.add("realm2"); String newRealm = "realm123"; assertFalse(RealmUtils.normalizingAddTo(realms, newRealm)); assertEquals(2, realms.size()); realms.clear(); realms.add("testRealm1"); realms.add("realm2"); newRealm = "test"; assertTrue(RealmUtils.normalizingAddTo(realms, newRealm)); assertEquals(2, realms.size()); }
public static boolean normalizingAddTo(final Set<String> realms, final String newRealm) { boolean dontAdd = false; Set<String> toRemove = new HashSet<>(); for (String realm : realms) { if (newRealm.startsWith(realm)) { dontAdd = true; } else if (realm.startsWith(newRealm)) { toRemove.add(realm); } } realms.removeAll(toRemove); if (!dontAdd) { realms.add(newRealm); } return !dontAdd; }
RealmUtils { public static boolean normalizingAddTo(final Set<String> realms, final String newRealm) { boolean dontAdd = false; Set<String> toRemove = new HashSet<>(); for (String realm : realms) { if (newRealm.startsWith(realm)) { dontAdd = true; } else if (realm.startsWith(newRealm)) { toRemove.add(realm); } } realms.removeAll(toRemove); if (!dontAdd) { realms.add(newRealm); } return !dontAdd; } }
RealmUtils { public static boolean normalizingAddTo(final Set<String> realms, final String newRealm) { boolean dontAdd = false; Set<String> toRemove = new HashSet<>(); for (String realm : realms) { if (newRealm.startsWith(realm)) { dontAdd = true; } else if (realm.startsWith(newRealm)) { toRemove.add(realm); } } realms.removeAll(toRemove); if (!dontAdd) { realms.add(newRealm); } return !dontAdd; } private  RealmUtils(); }
RealmUtils { public static boolean normalizingAddTo(final Set<String> realms, final String newRealm) { boolean dontAdd = false; Set<String> toRemove = new HashSet<>(); for (String realm : realms) { if (newRealm.startsWith(realm)) { dontAdd = true; } else if (realm.startsWith(newRealm)) { toRemove.add(realm); } } realms.removeAll(toRemove); if (!dontAdd) { realms.add(newRealm); } return !dontAdd; } private  RealmUtils(); static String getGroupOwnerRealm(final String realmPath, final String groupKey); static boolean normalizingAddTo(final Set<String> realms, final String newRealm); static Set<String> normalize(final Collection<String> realms); static Set<String> getEffective(final Set<String> allowedRealms, final String requestedRealm); }
RealmUtils { public static boolean normalizingAddTo(final Set<String> realms, final String newRealm) { boolean dontAdd = false; Set<String> toRemove = new HashSet<>(); for (String realm : realms) { if (newRealm.startsWith(realm)) { dontAdd = true; } else if (realm.startsWith(newRealm)) { toRemove.add(realm); } } realms.removeAll(toRemove); if (!dontAdd) { realms.add(newRealm); } return !dontAdd; } private  RealmUtils(); static String getGroupOwnerRealm(final String realmPath, final String groupKey); static boolean normalizingAddTo(final Set<String> realms, final String newRealm); static Set<String> normalize(final Collection<String> realms); static Set<String> getEffective(final Set<String> allowedRealms, final String requestedRealm);  }