本文整理了Java中org.apache.commons.collections4.CollectionUtils.containsAll()
方法的一些代码示例,展示了CollectionUtils.containsAll()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CollectionUtils.containsAll()
方法的具体详情如下:
包路径:org.apache.commons.collections4.CollectionUtils
类名称:CollectionUtils
方法名:containsAll
[英]Returns true
iff all elements of coll2 are also contained in coll1. The cardinality of values in coll2 is not taken into account, which is the same behavior as Collection#containsAll(Collection).
In other words, this method returns true
iff the #intersection of coll1 and coll2 has the same cardinality as the set of unique values from coll2. In case coll2 is empty, truewill be returned.
This method is intended as a replacement for Collection#containsAll(Collection)with a guaranteed runtime complexity of O(n + m). Depending on the type of Collection provided, this method will be much faster than calling Collection#containsAll(Collection) instead, though this will come at the cost of an additional space complexity O(n).
[中]如果coll1中还包含coll2的所有元素,则返回true
。coll2中的值的基数不被考虑,这与Collection#containsAll(Collection)的行为相同。
换句话说,如果coll1和coll2的#交集与coll2的唯一值集具有相同的基数,则此方法返回true
。如果coll2为空,将返回truel。
此方法旨在替代保证运行时复杂性为O(n+m)的Collection#containsAll(Collection)。根据提供的集合类型,此方法将比调用Collection#containsAll(Collection)快得多,尽管这将以额外的空间复杂性O(n)为代价。
代码示例来源:origin: metatron-app/metatron-discovery
@RequestMapping(value = "/auth/{domain}/permissions/check", method = RequestMethod.GET)
public ResponseEntity<Object> checkPermissions(@PathVariable String domain,
@RequestParam List<String> permissions) {
if(!"SYSTEM".equals(domain.toUpperCase())) {
throw new IllegalArgumentException("invalid domain name : " + domain);
}
Map<String, Object> result = Maps.newHashMap();
if(CollectionUtils.isNotEmpty(permissions)) {
List<String> userPerms = AuthUtils.getPermissions();
result.put("hasPermission", CollectionUtils.containsAll(userPerms, permissions));
} else {
result.put("hasPermission", false);
}
return ResponseEntity.ok(result);
}
代码示例来源:origin: metatron-app/metatron-discovery
/**
*
* @param workbookId
* @param workspaceId
* @return
*/
public boolean checkWorkBookCopyToWorkspace(String workbookId, String workspaceId) {
List<String> dataSourceIdInWorkbook = dataSourceRepository.findIdsByWorkbookInNotPublic(workbookId);
List<String> dataSourceIdInWorkspace = dataSourceRepository.findIdsByWorkspaceIn(workspaceId);
return CollectionUtils.containsAll(dataSourceIdInWorkspace, dataSourceIdInWorkbook);
}
代码示例来源:origin: apache/samza
@Override
public void doHandleChildChange(String barrierParticipantPath, List<String> participantIds) {
if (participantIds == null) {
LOG.info("Received notification with null participants for barrier: {}. Ignoring it.", barrierParticipantPath);
return;
}
LOG.info(String.format("Current participants in barrier version: %s = %s.", barrierVersion, participantIds));
LOG.info(String.format("Expected participants in barrier version: %s = %s.", barrierVersion, expectedParticipantIds));
// check if all the expected participants are in
if (participantIds.size() == expectedParticipantIds.size() && CollectionUtils.containsAll(participantIds, expectedParticipantIds)) {
debounceTimer.scheduleAfterDebounceTime(ACTION_NAME, 0, () -> {
String barrierStatePath = keyBuilder.getBarrierStatePath(barrierVersion);
State barrierState = zkUtils.getZkClient().readData(barrierStatePath);
if (Objects.equals(barrierState, State.NEW)) {
LOG.info(String.format("Expected participants has joined the barrier version: %s. Marking the barrier state: %s as %s.", barrierVersion, barrierStatePath, State.DONE));
zkUtils.writeData(barrierStatePath, State.DONE); // this will trigger notifications
} else {
LOG.debug(String.format("Barrier version: %s is at: %s state. Not marking barrier as %s.", barrierVersion, barrierState, State.DONE));
}
LOG.info("Unsubscribing child changes on the path: {} for barrier version: {}.", barrierParticipantPath, barrierVersion);
zkUtils.unsubscribeChildChanges(barrierParticipantPath, this);
});
}
}
}
代码示例来源:origin: org.apache.samza/samza-core
@Override
public void doHandleChildChange(String barrierParticipantPath, List<String> participantIds) {
if (participantIds == null) {
LOG.info("Received notification with null participants for barrier: {}. Ignoring it.", barrierParticipantPath);
return;
}
LOG.info(String.format("Current participants in barrier version: %s = %s.", barrierVersion, participantIds));
LOG.info(String.format("Expected participants in barrier version: %s = %s.", barrierVersion, expectedParticipantIds));
// check if all the expected participants are in
if (participantIds.size() == expectedParticipantIds.size() && CollectionUtils.containsAll(participantIds, expectedParticipantIds)) {
debounceTimer.scheduleAfterDebounceTime(ACTION_NAME, 0, () -> {
String barrierStatePath = keyBuilder.getBarrierStatePath(barrierVersion);
State barrierState = zkUtils.getZkClient().readData(barrierStatePath);
if (Objects.equals(barrierState, State.NEW)) {
LOG.info(String.format("Expected participants has joined the barrier version: %s. Marking the barrier state: %s as %s.", barrierVersion, barrierStatePath, State.DONE));
zkUtils.writeData(barrierStatePath, State.DONE); // this will trigger notifications
} else {
LOG.debug(String.format("Barrier version: %s is at: %s state. Not marking barrier as %s.", barrierVersion, barrierState, State.DONE));
}
LOG.info("Unsubscribing child changes on the path: {} for barrier version: {}.", barrierParticipantPath, barrierVersion);
zkUtils.unsubscribeChildChanges(barrierParticipantPath, this);
});
}
}
}
代码示例来源:origin: org.apache.samza/samza-core_2.11
@Override
public void doHandleChildChange(String barrierParticipantPath, List<String> participantIds) {
if (participantIds == null) {
LOG.info("Received notification with null participants for barrier: {}. Ignoring it.", barrierParticipantPath);
return;
}
LOG.info(String.format("Current participants in barrier version: %s = %s.", barrierVersion, participantIds));
LOG.info(String.format("Expected participants in barrier version: %s = %s.", barrierVersion, expectedParticipantIds));
// check if all the expected participants are in
if (participantIds.size() == expectedParticipantIds.size() && CollectionUtils.containsAll(participantIds, expectedParticipantIds)) {
debounceTimer.scheduleAfterDebounceTime(ACTION_NAME, 0, () -> {
String barrierStatePath = keyBuilder.getBarrierStatePath(barrierVersion);
State barrierState = zkUtils.getZkClient().readData(barrierStatePath);
if (Objects.equals(barrierState, State.NEW)) {
LOG.info(String.format("Expected participants has joined the barrier version: %s. Marking the barrier state: %s as %s.", barrierVersion, barrierStatePath, State.DONE));
zkUtils.writeData(barrierStatePath, State.DONE); // this will trigger notifications
} else {
LOG.debug(String.format("Barrier version: %s is at: %s state. Not marking barrier as %s.", barrierVersion, barrierState, State.DONE));
}
LOG.info("Unsubscribing child changes on the path: {} for barrier version: {}.", barrierParticipantPath, barrierVersion);
zkUtils.unsubscribeChildChanges(barrierParticipantPath, this);
});
}
}
}
代码示例来源:origin: org.apache.samza/samza-core_2.12
@Override
public void doHandleChildChange(String barrierParticipantPath, List<String> participantIds) {
if (participantIds == null) {
LOG.info("Received notification with null participants for barrier: {}. Ignoring it.", barrierParticipantPath);
return;
}
LOG.info(String.format("Current participants in barrier version: %s = %s.", barrierVersion, participantIds));
LOG.info(String.format("Expected participants in barrier version: %s = %s.", barrierVersion, expectedParticipantIds));
// check if all the expected participants are in
if (participantIds.size() == expectedParticipantIds.size() && CollectionUtils.containsAll(participantIds, expectedParticipantIds)) {
debounceTimer.scheduleAfterDebounceTime(ACTION_NAME, 0, () -> {
String barrierStatePath = keyBuilder.getBarrierStatePath(barrierVersion);
State barrierState = zkUtils.getZkClient().readData(barrierStatePath);
if (Objects.equals(barrierState, State.NEW)) {
LOG.info(String.format("Expected participants has joined the barrier version: %s. Marking the barrier state: %s as %s.", barrierVersion, barrierStatePath, State.DONE));
zkUtils.writeData(barrierStatePath, State.DONE); // this will trigger notifications
} else {
LOG.debug(String.format("Barrier version: %s is at: %s state. Not marking barrier as %s.", barrierVersion, barrierState, State.DONE));
}
LOG.info("Unsubscribing child changes on the path: {} for barrier version: {}.", barrierParticipantPath, barrierVersion);
zkUtils.unsubscribeChildChanges(barrierParticipantPath, this);
});
}
}
}
代码示例来源:origin: org.apache.samza/samza-core_2.10
@Override
public void doHandleChildChange(String barrierParticipantPath, List<String> participantIds) {
if (participantIds == null) {
LOG.info("Received notification with null participants for barrier: {}. Ignoring it.", barrierParticipantPath);
return;
}
LOG.info(String.format("Current participants in barrier version: %s = %s.", barrierVersion, participantIds));
LOG.info(String.format("Expected participants in barrier version: %s = %s.", barrierVersion, expectedParticipantIds));
// check if all the expected participants are in
if (participantIds.size() == expectedParticipantIds.size() && CollectionUtils.containsAll(participantIds, expectedParticipantIds)) {
debounceTimer.scheduleAfterDebounceTime(ACTION_NAME, 0, () -> {
String barrierStatePath = keyBuilder.getBarrierStatePath(barrierVersion);
State barrierState = zkUtils.getZkClient().readData(barrierStatePath);
if (Objects.equals(barrierState, State.NEW)) {
LOG.info(String.format("Expected participants has joined the barrier version: %s. Marking the barrier state: %s as %s.", barrierVersion, barrierStatePath, State.DONE));
zkUtils.writeData(barrierStatePath, State.DONE); // this will trigger notifications
} else {
LOG.debug(String.format("Barrier version: %s is at: %s state. Not marking barrier as %s.", barrierVersion, barrierState, State.DONE));
}
LOG.info("Unsubscribing child changes on the path: {} for barrier version: {}.", barrierParticipantPath, barrierVersion);
zkUtils.unsubscribeChildChanges(barrierParticipantPath, this);
});
}
}
}
代码示例来源:origin: metatron-app/metatron-discovery
&& CollectionUtils.containsAll(requiredKeys, projectionKeys)) {
return;
if (!CollectionUtils.containsAll(filterKeys, requiredKeys)) {
throw new IllegalArgumentException("Required Filter(" + StringUtils.join(requiredKeys, ",") + ") did not set.");
代码示例来源:origin: alien4cloud/alien4cloud
assertTrue(list instanceof List);
assertEquals(2, ((List) list).size());
assertTrue(CollectionUtils.containsAll((List) list, Lists.newArrayList("alien", "fastconnect")));
assertTrue(list instanceof List);
assertEquals(2, ((List) list).size());
assertTrue(CollectionUtils.containsAll((List) list, Lists.newArrayList("manual_alien", "manual_fastconnect")));
assertTrue(list instanceof List);
assertEquals(2, ((List) list).size());
assertTrue(CollectionUtils.containsAll((List) list, Lists.newArrayList("alien", "fastconnect")));
内容来源于网络,如有侵权,请联系作者删除!