Example usage for com.google.common.collect Sets symmetricDifference

List of usage examples for com.google.common.collect Sets symmetricDifference

Introduction

In this page you can find the example usage for com.google.common.collect Sets symmetricDifference.

Prototype

public static <E> SetView<E> symmetricDifference(final Set<? extends E> set1, final Set<? extends E> set2) 

Source Link

Document

Returns an unmodifiable view of the symmetric difference of two sets.

Usage

From source file:org.artifactory.security.SecurityServiceImpl.java

/**
 * Validates that the edited given permission target is not different from the existing one. This method should be
 * called before an ACL is being modified by a non-sys-admin user
 *
 * @param newInfo Edited permission target
 * @throws AuthorizationException Thrown in case an unauthorized modification has occurred
 *//*from  w w w .  j  a v  a  2s.  co m*/
private void validateUnmodifiedPermissionTarget(PermissionTargetInfo newInfo) throws AuthorizationException {
    if (newInfo == null) {
        return;
    }

    AclInfo oldAcl = getAcl(newInfo);
    if (oldAcl == null) {
        return;
    }

    PermissionTargetInfo oldInfo = oldAcl.getPermissionTarget();
    if (oldInfo == null) {
        return;
    }

    Sets.SetView<String> excludes = Sets.symmetricDifference(Sets.newHashSet(oldInfo.getExcludes()),
            Sets.newHashSet(newInfo.getExcludes()));
    if (excludes != null && !excludes.isEmpty()) {
        alertModifiedField("excludes");
    }

    if (!oldInfo.getExcludesPattern().equals(newInfo.getExcludesPattern())) {
        alertModifiedField("excludes pattern");
    }

    Sets.SetView<String> includes = Sets.symmetricDifference(Sets.newHashSet(oldInfo.getIncludes()),
            Sets.newHashSet(newInfo.getIncludes()));
    if (includes != null && !includes.isEmpty()) {
        alertModifiedField("includes");
    }

    if (!oldInfo.getIncludesPattern().equals(newInfo.getIncludesPattern())) {
        alertModifiedField("includes pattern");
    }
    // make repo keys compatible with acl cached data
    List<String> compatibleRepoKeys = makeRemoteRepoKeysAclCompatible(newInfo.getRepoKeys());
    // validate repo keys data , make sure that old repo data and new repo data is the same
    Sets.SetView<String> repoKeys = Sets.symmetricDifference(Sets.newHashSet(oldInfo.getRepoKeys()),
            Sets.newHashSet(compatibleRepoKeys));
    if (repoKeys != null && !repoKeys.isEmpty()) {
        alertModifiedField("repositories");
    }
}