org.springframework.util.CollectionUtils.containsAny()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(10.5k)|赞(0)|评价(0)|浏览(681)

本文整理了Java中org.springframework.util.CollectionUtils.containsAny()方法的一些代码示例,展示了CollectionUtils.containsAny()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CollectionUtils.containsAny()方法的具体详情如下:
包路径:org.springframework.util.CollectionUtils
类名称:CollectionUtils
方法名:containsAny

CollectionUtils.containsAny介绍

[英]Return true if any element in ' candidates' is contained in ' source'; otherwise returns false.
[中]如果“候选”中的任何元素包含在“源”中,则返回true;否则返回false。

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testContainsAny() throws Exception {
  List<String> source = new ArrayList<>();
  source.add("abc");
  source.add("def");
  source.add("ghi");
  List<String> candidates = new ArrayList<>();
  candidates.add("xyz");
  candidates.add("def");
  candidates.add("abc");
  assertTrue(CollectionUtils.containsAny(source, candidates));
  candidates.remove("def");
  assertTrue(CollectionUtils.containsAny(source, candidates));
  candidates.remove("abc");
  assertFalse(CollectionUtils.containsAny(source, candidates));
}

代码示例来源:origin: spring-projects/spring-security

private boolean shouldRetrieveUserInfo(OidcUserRequest userRequest) {
  // Auto-disabled if UserInfo Endpoint URI is not provided
  if (StringUtils.isEmpty(userRequest.getClientRegistration().getProviderDetails()
    .getUserInfoEndpoint().getUri())) {
    return false;
  }
  // The Claims requested by the profile, email, address, and phone scope values
  // are returned from the UserInfo Endpoint (as described in Section 5.3.2),
  // when a response_type value is used that results in an Access Token being issued.
  // However, when no Access Token is issued, which is the case for the response_type=id_token,
  // the resulting Claims are returned in the ID Token.
  // The Authorization Code Grant Flow, which is response_type=code, results in an Access Token being issued.
  if (AuthorizationGrantType.AUTHORIZATION_CODE.equals(
    userRequest.getClientRegistration().getAuthorizationGrantType())) {
    // Return true if there is at least one match between the authorized scope(s) and UserInfo scope(s)
    return CollectionUtils.containsAny(userRequest.getAccessToken().getScopes(), this.userInfoScopes);
  }
  return false;
}

代码示例来源:origin: spring-projects/spring-security

.containsAny(userRequest.getAccessToken().getScopes(), userRequest.getClientRegistration().getScopes());

代码示例来源:origin: spring-projects/spring-integration

private void validateSupportedMethods() {
  if (this.requestPayloadType != null
      && CollectionUtils.containsAny(nonReadableBodyHttpMethods,
      Arrays.asList(getRequestMapping().getMethods()))) {
    if (logger.isWarnEnabled()) {
      logger.warn("The 'requestPayloadType' attribute will have no relevance for one " +
          "of the specified HTTP methods '" + nonReadableBodyHttpMethods + "'");
    }
  }
}

代码示例来源:origin: javamonkey/beetl2.0

/**
 * 测试source集合中是否包含candidates集任意元素
 *
 * @param source
 * @param candidates
 * @return 测试source集合中是否包含candidates集任意元素
 */
public boolean containsAny(Collection<?> source, Collection<?> candidates) {
  return CollectionUtils.containsAny(source, candidates);
}

代码示例来源:origin: com.ibeetl/beetl

/**
 * 测试source集合中是否包含candidates集任意元素
 *
 * @param source
 * @param candidates
 * @return 测试source集合中是否包含candidates集任意元素
 */
public boolean containsAny(Collection<?> source, Collection<?> candidates) {
  return CollectionUtils.containsAny(source, candidates);
}

代码示例来源:origin: anand1st/sshd-shell-spring-boot

public boolean matchesRole(Collection<String> userRoles) {
  if (roles.contains("*") || userRoles.contains("*")) {
    return true;
  }
  return CollectionUtils.containsAny(roles, userRoles);
}

代码示例来源:origin: Feature-Flip/flips

private boolean isAnyActiveProfileContainedInExpectedProfile(String[] expectedProfiles, String[] activeProfiles) {
    logger.info("SpringProfileFlipCondition: Expected profile(s) {}, active profile(s) {}", expectedProfiles, activeProfiles);
    return CollectionUtils.containsAny(asList(activeProfiles), asList(expectedProfiles));
  }
}

代码示例来源:origin: com.github.feature-flip/flips-core

private boolean isAnyActiveProfileContainedInExpectedProfile(String[] expectedProfiles, String[] activeProfiles) {
    logger.info("SpringProfileFlipCondition: Expected profile(s) {}, active profile(s) {}", expectedProfiles, activeProfiles);
    return CollectionUtils.containsAny(asList(activeProfiles), asList(expectedProfiles));
  }
}

代码示例来源:origin: org.springframework.integration/spring-integration-http

private void validateSupportedMethods() {
  if (this.requestPayloadType != null
      && CollectionUtils.containsAny(nonReadableBodyHttpMethods,
      Arrays.asList(getRequestMapping().getMethods()))) {
    if (logger.isWarnEnabled()) {
      logger.warn("The 'requestPayloadType' attribute will have no relevance for one " +
          "of the specified HTTP methods '" + nonReadableBodyHttpMethods + "'");
    }
  }
}

代码示例来源:origin: dhis2/dhis2-core

private boolean haveAuthority( User user, Collection<String> anyAuthorities )
{
  return containsAny( user.getUserCredentials().getAllAuthorities(), anyAuthorities );
}

代码示例来源:origin: org.flowable/flowable-dmn-engine

/**
 * none of the values of value must be in collection
 *
 * @return {@code true} if all elements of value are not within the collection,
 * {@code false} if at least one element of value is within the collection
 */
public static boolean noneOf(Object collection, Object value) {
  if (collection == null) {
    throw new IllegalArgumentException("collection cannot be null");
  }
  if (value == null) {
    throw new IllegalArgumentException("value cannot be null");
  }
  // collection to check against
  Collection targetCollection = getTargetCollection(collection, value);
  // elements to check
  if (DMNParseUtil.isParseableCollection(value)) {
    Collection valueCollection = DMNParseUtil.parseCollection(value, targetCollection);
    return !CollectionUtils.containsAny(targetCollection, valueCollection);
  } else if (DMNParseUtil.isJavaCollection(value)) {
    return !CollectionUtils.containsAny(targetCollection, (Collection) value);
  } else if (DMNParseUtil.isArrayNode(value)) {
    Collection valueCollection = DMNParseUtil.getCollectionFromArrayNode((ArrayNode) value);
    return !CollectionUtils.containsAny(targetCollection, valueCollection);
  } else {
    Object formattedValue = DMNParseUtil.getFormattedValue(value, targetCollection);
    return !targetCollection.contains(formattedValue);
  }
}

代码示例来源:origin: org.flowable/flowable-dmn-engine

/**
 * one of the values of value must be in collection
 *
 * @return {@code true} if at least one element of value is within the collection,
 * {@code false} if all elements of value are not within the collection
 */
public static boolean anyOf(Object collection, Object value) {
  if (collection == null) {
    throw new IllegalArgumentException("collection cannot be null");
  }
  if (value == null) {
    throw new IllegalArgumentException("value cannot be null");
  }
  // collection to check against
  Collection targetCollection = getTargetCollection(collection, value);
  // elements to check
  if (DMNParseUtil.isParseableCollection(value)) {
    Collection valueCollection = DMNParseUtil.parseCollection(value, targetCollection);
    return valueCollection != null && CollectionUtils.containsAny(targetCollection, valueCollection);
  } else if (DMNParseUtil.isJavaCollection(value)) {
    return CollectionUtils.containsAny(targetCollection, (Collection) value);
  } else if (DMNParseUtil.isArrayNode(value)) {
    Collection valueCollection = DMNParseUtil.getCollectionFromArrayNode((ArrayNode) value);
    return valueCollection != null && CollectionUtils.containsAny(targetCollection, valueCollection);
  } else {
    Object formattedValue = DMNParseUtil.getFormattedValue(value, targetCollection);
    return targetCollection.contains(formattedValue);
  }
}

代码示例来源:origin: com.alibaba.otter/shared.arbitrate

if (!CollectionUtils.containsAny(liveNodes, nids)) {
  logger.error("current live nodes:{} , but select nids:{} , result:{}", new Object[] { liveNodes, nids,
      CollectionUtils.containsAny(liveNodes, nids) });
  sendWarningMessage(pipeline.getId(), "can't restart by no select live node");
  return false;
if (!CollectionUtils.containsAny(liveNodes, nids)) {
  logger.error("current live nodes:{} , but extract nids:{} , result:{}", new Object[] { liveNodes, nids,
      CollectionUtils.containsAny(liveNodes, nids) });
  sendWarningMessage(pipeline.getId(), "can't restart by no extract live node");
  return false;
if (!CollectionUtils.containsAny(liveNodes, nids)) {
  logger.error("current live nodes:{} , but transform nids:{} , result:{}", new Object[] { liveNodes,
      nids, CollectionUtils.containsAny(liveNodes, nids) });
  sendWarningMessage(pipeline.getId(), "can't restart by no transform live node");
  return false;

代码示例来源:origin: org.sakaiproject.profile2/profile2-impl

CollectionUtils.containsAny(SYNOPTIC_TOOL_ID_MAP.get(homeToolId), toolIds)) {

代码示例来源:origin: org.alfresco/alfresco-repository

transformationOptions = opts;
    if (containsAny(subclassOptionNames, RESIZE_OPTIONS))
    boolean containsPaged = containsAny(subclassOptionNames, PAGED_OPTIONS);
    boolean containsCrop = containsAny(subclassOptionNames, CROP_OPTIONS);
    boolean containsTemporal = containsAny(subclassOptionNames, TEMPORAL_OPTIONS);
    if (containsPaged || containsCrop || containsTemporal)
ifSet(options, INCLUDE_CONTENTS, (v) ->opts.setIncludeEmbedded(Boolean.parseBoolean(v)));
if (containsAny(optionNames, LIMIT_OPTIONS))

代码示例来源:origin: Alfresco/alfresco-repository

transformationOptions = opts;
    if (containsAny(subclassOptionNames, RESIZE_OPTIONS))
    boolean containsPaged = containsAny(subclassOptionNames, PAGED_OPTIONS);
    boolean containsCrop = containsAny(subclassOptionNames, CROP_OPTIONS);
    boolean containsTemporal = containsAny(subclassOptionNames, TEMPORAL_OPTIONS);
    if (containsPaged || containsCrop || containsTemporal)
ifSet(options, INCLUDE_CONTENTS, (v) ->opts.setIncludeEmbedded(Boolean.parseBoolean(v)));
if (containsAny(optionNames, LIMIT_OPTIONS))

代码示例来源:origin: apache/servicemix-bundles

private boolean shouldRetrieveUserInfo(OidcUserRequest userRequest) {
  // Auto-disabled if UserInfo Endpoint URI is not provided
  if (StringUtils.isEmpty(userRequest.getClientRegistration().getProviderDetails()
    .getUserInfoEndpoint().getUri())) {
    return false;
  }
  // The Claims requested by the profile, email, address, and phone scope values
  // are returned from the UserInfo Endpoint (as described in Section 5.3.2),
  // when a response_type value is used that results in an Access Token being issued.
  // However, when no Access Token is issued, which is the case for the response_type=id_token,
  // the resulting Claims are returned in the ID Token.
  // The Authorization Code Grant Flow, which is response_type=code, results in an Access Token being issued.
  if (AuthorizationGrantType.AUTHORIZATION_CODE.equals(
    userRequest.getClientRegistration().getAuthorizationGrantType())) {
    // Return true if there is at least one match between the authorized scope(s) and UserInfo scope(s)
    return CollectionUtils.containsAny(userRequest.getAccessToken().getScopes(), this.userInfoScopes);
  }
  return false;
}

代码示例来源:origin: apache/servicemix-bundles

.containsAny(userRequest.getAccessToken().getScopes(), userRequest.getClientRegistration().getScopes());

相关文章