NetgroupCache { public static void add(String group, List<String> users) { for (String user : users) { Set<String> userGroups = userToNetgroupsMap.get(user); if (userGroups == null) { userGroups = Collections.newSetFromMap(new ConcurrentHashMap<String,Boolean>()); Set<String> currentSet = userToNetgroupsMap.putIfAbsent(user, userGroups); if (currentSet != null) { userGroups = currentSet; } } userGroups.add(group); } }  static void getNetgroups(final String user,
      List<String> groups); static List<String> getNetgroupNames(); static boolean isCached(String group); static void clear(); static void add(String group, List<String> users);  }
@Test public void testMembership() { List<String> users = new ArrayList<String>(); users.add(USER1); users.add(USER2); NetgroupCache.add(GROUP1, users); users = new ArrayList<String>(); users.add(USER1); users.add(USER3); NetgroupCache.add(GROUP2, users); verifyGroupMembership(USER1, 2, GROUP1); verifyGroupMembership(USER1, 2, GROUP2); verifyGroupMembership(USER2, 1, GROUP1); verifyGroupMembership(USER3, 1, GROUP2); }