Java 类org.apache.commons.collections4.SetUtils 实例源码

项目:simple-openid-provider    文件:DefaultTokenService.java   
@Override
public RefreshToken createRefreshToken(RefreshTokenRequest refreshTokenRequest) {
    Instant now = Instant.now();
    ClientID clientId = refreshTokenRequest.getClientId();
    Subject subject = refreshTokenRequest.getSubject();
    Scope scope = refreshTokenRequest.getScope();

    RefreshTokenContext context = this.refreshTokenStore.findByClientIdAndSubject(clientId, subject);

    if (context == null || !SetUtils.isEqualSet(context.getScope(), scope)) {
        if (context != null) {
            this.refreshTokenStore.revoke(context.getRefreshToken());
        }
        Instant expiry = (!this.refreshTokenLifetime.isZero() && !this.refreshTokenLifetime.isNegative())
                ? now.plus(this.refreshTokenLifetime)
                : null;
        context = new RefreshTokenContext(new RefreshToken(), clientId, subject, scope, expiry);
        this.refreshTokenStore.save(context);
    }

    return context.getRefreshToken();
}
项目:HCFCore    文件:AbstractSetValuedMap.java   
@Override
public boolean equals(Object other) {
    final Set<V> set = (Set<V>) getMapping();
    if (set == null) {
        return Collections.emptySet().equals(other);
    }
    if (!(other instanceof Set)) {
        return false;
    }
    Set<?> otherSet = (Set<?>) other;
    return SetUtils.isEqualSet(set, otherSet);
}
项目:HCFCore    文件:AbstractSetValuedMap.java   
@Override
public boolean equals(Object other) {
    final Set<V> set = (Set<V>) getMapping();
    if (set == null) {
        return Collections.emptySet().equals(other);
    }
    if (!(other instanceof Set)) {
        return false;
    }
    Set<?> otherSet = (Set<?>) other;
    return SetUtils.isEqualSet(set, otherSet);
}
项目:java-cloud-filesystem-provider    文件:CloudFileAttributesView.java   
/**
 * Sets ACL attributes for the file. Only {@link PublicPrivateCloudPermissionsPrincipal} is accepted in the ACL
 * permissions set by this class. Extend it to allow for storage of other ACL's. The set is first
 * {@link CloudAclEntrySet#optimise() optimised} before being set.
 * @param   cloudAclEntrySet    The ACL entry set for this file
 * @return  The ACL entries which could not be set.
 * @throws IOException 
 */
@SuppressWarnings("unchecked")
public Set<CloudAclEntry<?>> setAclFileAttributes(CloudAclEntrySet cloudAclEntrySet) throws IOException {
    checkAccess(WRITE_ACL_PERMS);

    // Optimise the entry set first
    cloudAclEntrySet.optimise();

    Set<CloudAclEntry<?>> validPrincipals =
        cloudAclEntrySet.stream().filter(e -> PublicPrivateCloudPermissionsPrincipal.class.isAssignableFrom(e.getPrincipalClass()))
            .collect(Collectors.toSet());
    // TODO: Reverse PublicPrivateCloudPermissionsPrincipal if the permission is DENY
    // TODO: Maybe add validation methods on the entry and principal?
    validPrincipals.forEach(pe -> context.getBlobStore().setBlobAccess(path.getContainerName(), path.getPathName(),
                ((PublicPrivateCloudPermissionsPrincipal)pe.getPrincipal()).getBlobAccess()));

    // If we got only a subset of the principals then log the invalid ones
    if (validPrincipals.size() < cloudAclEntrySet.size()) {
        Set<CloudAclEntry<?>> differences = SetUtils.difference(cloudAclEntrySet.getAclEntries(), validPrincipals);

        if (!differences.isEmpty()) {
            LOG.warn("Skipping unknown ACL's from the set: {}", differences);
            return differences;
        }
    }

    return Collections.EMPTY_SET;
}
项目:java-cloud-filesystem-provider    文件:CloudAclEntrySet.java   
/**
 * Finds all ACL's with any of the specified type and with <em>all</em> of the permissions
 * type.
 * @param aclOwner
 * @param type
 * @return
 */
public Set<CloudAclEntry<?>> findAclsOfTypeWithAllPermissions(Principal aclOwner, AclEntryType type,
        Set<AclEntryPermission> permissions) {
    return findAcls(a ->
        type.equals(a.getType()) &&
        aclOwner.equals(a.getPrincipal()) &&
        SetUtils.difference(permissions, a.getPermissions()).isEmpty());
}
项目:java-cloud-filesystem-provider    文件:CloudAclEntrySet.java   
/**
 * Finds all ACL's with any of the specified type and with <em>any</em> of the permissions
 * type.
 * @param aclOwner
 * @param type
 * @return
 */
public Set<CloudAclEntry<?>> findAclsOfTypeWithAnyPermissions(Principal aclOwner, AclEntryType type,
        Set<AclEntryPermission> permissions) {
    return findAcls(a ->
        type.equals(a.getType()) &&
        aclOwner.equals(a.getPrincipal()) &&
        SetUtils.difference(permissions, a.getPermissions()).size() < permissions.size());
}
项目:spring-boot    文件:MyCSVUtils.java   
/**
 * 获取所有行数据
 *
 * @param csvFile   csv 文件
 * @param duplicate 是否过滤重复行 。判断重复行的依据是各个单元格内容是否相同
 * @return
 * @throws IOException
 */
public static List<CSVRecord> getCSVRecords(File csvFile, boolean duplicate) throws IOException {

    List<CSVRecord> collection = CSVParser.parse(csvFile, MyCharsetUtils.detectEncoding(csvFile), CSVFormat.DEFAULT).getRecords();

    if (duplicate) {
        //    logger.info("in list");
        return collection;
    } else {
        //自定义了一个比较器,只比较单元格内容
        //    logger.info("in set.");
        Set set = new TreeSet(new Comparator<CSVRecord>() {
            @Override
            // record.toString() 方法输出为  CSVRecord [comment=null, mapping=null, recordNumber=55, values=[USDA, 美国农业部, 1]]
            // values 为各行的值
            public int compare(CSVRecord csv1, CSVRecord csv2) {
                String values1 = getCSVListValues(csv1).toString();
                String values2 = getCSVListValues(csv2).toString();
                return values1.compareTo(values2);
            }
        });

        //创建一个按照 参数 set 进行排序的空 set ,用法见 SetUtils
        Set set1 = SetUtils.orderedSet(set);
        //重新用 set 包装,去掉重复元素
        for (CSVRecord csvRecord : collection) {
            set1.add(csvRecord);
        }

        return new ArrayList<>(set1);
    }
}
项目:tcases    文件:TestCase.java   
public boolean equals( Object object)
{
TestCase other =
  object != null && object.getClass().equals( getClass())
  ? (TestCase) object
  : null;

return
  other != null
  && id_ == other.id_
  && SetUtils.isEqualSet( varBindings_, other.varBindings_);
}
项目:HCFCore    文件:AbstractSetValuedMap.java   
@Override
public int hashCode() {
    final Set<V> set = (Set<V>) getMapping();
    return SetUtils.hashCodeForSet(set);
}
项目:HCFCore    文件:AbstractSetValuedMap.java   
@Override
public int hashCode() {
    final Set<V> set = (Set<V>) getMapping();
    return SetUtils.hashCodeForSet(set);
}
项目:dhis2-core    文件:MonitoringJob.java   
@Override
@Transactional
public void execute( JobConfiguration jobConfiguration )
{
    notifier.clear( jobConfiguration ).notify( jobConfiguration, "Monitoring data" );

    MonitoringJobParameters monitoringJobParameters = (MonitoringJobParameters) jobConfiguration.getJobParameters();

    //TODO improve collection usage

    try
    {
        List<Period> periods;
        Collection<ValidationRule> validationRules;
        List<String> groupUIDs = monitoringJobParameters.getValidationRuleGroups();

        if ( groupUIDs.isEmpty() )
        {
            validationRules = validationRuleService
                .getValidationRulesWithNotificationTemplates();
        }
        else
        {
            validationRules = groupUIDs.stream()
                .map( ( uid ) -> validationRuleService.getValidationRuleGroup( uid ) )
                .filter( Objects::nonNull )
                .map( ValidationRuleGroup::getMembers )
                .filter( Objects::nonNull )
                .reduce( Sets.newHashSet(), SetUtils::union );
        }

        if ( monitoringJobParameters.getRelativeStart() != 0 && monitoringJobParameters.getRelativeEnd() != 0 )
        {
            Date startDate = DateUtils.getDateAfterAddition( new Date(), monitoringJobParameters.getRelativeStart() );
            Date endDate = DateUtils.getDateAfterAddition( new Date(), monitoringJobParameters.getRelativeEnd() );

            periods = periodService.getPeriodsBetweenDates( startDate, endDate );

            periods = ListUtils.union( periods, periodService.getIntersectionPeriods( periods ) );
        }
        else
        {
            periods = validationRules.stream()
                .map( ValidationRule::getPeriodType )
                .distinct()
                .map( ( vr ) -> Arrays.asList( vr.createPeriod(), vr.getPreviousPeriod( vr.createPeriod() ) ) )
                .reduce( Lists.newArrayList(), ListUtils::union );
        }

        ValidationAnalysisParams parameters = validationService
            .newParamsBuilder( validationRules, null, periods )
            .withIncludeOrgUnitDescendants( true )
            .withMaxResults( ValidationService.MAX_SCHEDULED_ALERTS )
            .withSendNotifications( monitoringJobParameters.isSendNotifications() )
            .withPersistResults( monitoringJobParameters.isPersistResults() )
            .build();

        validationService.validationAnalysis( parameters );

        notifier.notify( jobConfiguration, INFO, "Monitoring process done", true );
    }
    catch ( RuntimeException ex )
    {
        notifier.notify( jobConfiguration, ERROR, "Process failed: " + ex.getMessage(), true );

        messageService.sendSystemErrorNotification( "Monitoring process failed", ex );

        throw ex;
    }
}
项目:terminal-recall    文件:CollectionActionDispatcher.java   
public CollectionActionDispatcher(Collection<E> cache){
this.cache     =cache;
this.targets   =SetUtils.newIdentityHashSet();
   }
项目:HCFCore    文件:AbstractSetValuedMap.java   
/**
 * Removes all values associated with the specified key.
 * <p>
 * A subsequent <code>get(Object)</code> would return an empty set.
 *
 * @param key the key to remove values from
 * @return the <code>Set</code> of values removed, will return an empty,
 *   unmodifiable set for no mapping found.
 */
@Override
public Set<V> remove(Object key) {
    return SetUtils.emptyIfNull(getMap().remove(key));
}
项目:HCFCore    文件:AbstractSetValuedMap.java   
/**
 * Removes all values associated with the specified key.
 * <p>
 * A subsequent <code>get(Object)</code> would return an empty set.
 *
 * @param key the key to remove values from
 * @return the <code>Set</code> of values removed, will return an empty,
 *   unmodifiable set for no mapping found.
 */
@Override
public Set<V> remove(Object key) {
    return SetUtils.emptyIfNull(getMap().remove(key));
}
项目:spring-boot    文件:CollectionExamples.java   
/**
 * Set,过滤重复元素
 * 按照添加的顺序
 * Returns a set that maintains the order of elements that are added backed by the given set.
 * If an element is added twice, the order is determined by the first add. The order is observed through the iterator or toArray.
 * <p/>
 *
 * @param set
 * @return
 */
public Set getOrderSet(Set set) {
    // 创建一个按照 参数 set 元素放入顺序进行排序的空 set ,返回后需要按照需求添加元素
    return SetUtils.orderedSet(set);
}