/** * Mutates the input map by removing entries which do not have keys in the new backing data, as extracted with * the keyExtractor. * @param map the map to mutate. * @param newBackingData the backing data to retain. * @param keyExtractor the function to extract keys from the backing data. * @param <K> type of the key in the input map. * @param <V> type of the values in the input map. * @param <T> type of the keys in the new baking data. */ public static <K, V, T> void trimToList( Map<K,V> map, List<T> newBackingData, Function<T,K> keyExtractor ) { Set<K> retainedKeys = newBackingData.stream().map( keyExtractor ).collect( Collectors.toSet() ); trimToList( map, retainedKeys ); }
/** * Mutates the input map by removing entries which do not have keys in the new backing data, as extracted with * the keyExtractor. * @param map the map to mutate. * @param newBackingData the backing data to retain. * @param keyExtractor the function to extract keys from the backing data. * @param <K> type of the key in the input map. * @param <V> type of the values in the input map. * @param <T> type of the keys in the new backing data. */ public static <K, V, T> void trimToFlattenedList( Map<K,V> map, List<T> newBackingData, Function<T,Stream<K>> keyExtractor ) { Set<K> retainedKeys = newBackingData.stream().flatMap( keyExtractor ).collect( Collectors.toSet() ); trimToList( map, retainedKeys ); }
@Override public void setUsers( ListSnapshot<User> usersSnapshot ) throws InvalidArgumentsException { for ( User user : usersSnapshot.values() ) { assertValidUsername( user.name() ); } synchronized ( this ) { users.clear(); this.users.addAll( usersSnapshot.values() ); this.lastLoaded.set( usersSnapshot.timestamp() ); trimToList( usersByName, users, User::name ); for ( User user : users ) { usersByName.put( user.name(), user ); } } }
/** * Mutates the input map by removing entries which do not have keys in the new backing data, as extracted with * the keyExtractor. * @param map the map to mutate. * @param newBackingData the backing data to retain. * @param keyExtractor the function to extract keys from the backing data. * @param <K> type of the key in the input map. * @param <V> type of the values in the input map. * @param <T> type of the keys in the new baking data. */ public static <K, V, T> void trimToList( Map<K,V> map, List<T> newBackingData, Function<T,K> keyExtractor ) { Set<K> retainedKeys = newBackingData.stream().map( keyExtractor ).collect( Collectors.toSet() ); trimToList( map, retainedKeys ); }
/** * Mutates the input map by removing entries which do not have keys in the new backing data, as extracted with * the keyExtractor. * @param map the map to mutate. * @param newBackingData the backing data to retain. * @param keyExtractor the function to extract keys from the backing data. * @param <K> type of the key in the input map. * @param <V> type of the values in the input map. * @param <T> type of the keys in the new backing data. */ public static <K, V, T> void trimToFlattenedList( Map<K,V> map, List<T> newBackingData, Function<T,Stream<K>> keyExtractor ) { Set<K> retainedKeys = newBackingData.stream().flatMap( keyExtractor ).collect( Collectors.toSet() ); trimToList( map, retainedKeys ); }
@Override public void setUsers( ListSnapshot<User> usersSnapshot ) throws InvalidArgumentsException { for ( User user : usersSnapshot.values() ) { assertValidUsername( user.name() ); } synchronized ( this ) { users.clear(); this.users.addAll( usersSnapshot.values() ); this.lastLoaded.set( usersSnapshot.timestamp() ); trimToList( usersByName, users, User::name ); for ( User user : users ) { usersByName.put( user.name(), user ); } } }
@Override public void setRoles( ListSnapshot<RoleRecord> rolesSnapshot ) throws InvalidArgumentsException { for ( RoleRecord role : rolesSnapshot.values() ) { assertValidRoleName( role.name() ); } synchronized ( this ) { roles.clear(); this.roles.addAll( rolesSnapshot.values() ); this.lastLoaded.set( rolesSnapshot.timestamp() ); trimToList( rolesByName, roles, RoleRecord::name ); trimToFlattenedList( rolesByUsername, roles, r -> r.users().stream() ); for ( RoleRecord role : roles ) { rolesByName.put( role.name(), role ); populateUserMap( role ); } } }