Java Code Examples for org.apache.commons.collections4.CollectionUtils#containsAll()
The following examples show how to use
org.apache.commons.collections4.CollectionUtils#containsAll() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CollectionCompareTests.java From java_in_examples with Apache License 2.0 | 6 votes |
private static void testContainsAll() { Collection<String> collection1 = Lists.newArrayList("a1", "a2", "a3", "a1"); Collection<String> collection2 = Lists.newArrayList("a1", "a2", "a3", "a1"); Iterable<String> iterable1 = collection1; Iterable<String> iterable2 = collection2; MutableCollection<String> mutableCollection1 = FastList.newListWith("a1", "a2", "a3", "a1"); MutableCollection<String> mutableCollection2 = FastList.newListWith("a1", "a2", "a3", "a1"); // Check full equals with two collections boolean jdk = collection1.containsAll(collection2); // using JDK boolean guava = Iterables.elementsEqual(iterable1, iterable2); // using guava boolean apache = CollectionUtils.containsAll(collection1, collection2); // using Apache boolean gs = mutableCollection1.containsAll(mutableCollection2); // using GS System.out.println("containsAll = " + jdk + ":" + guava + ":" + apache + ":" + gs); // print containsAll = true:true:true:true }
Example 2
Source File: CollectionCompareTests.java From java_in_examples with Apache License 2.0 | 6 votes |
private static void testContainsAll() { Collection<String> collection1 = Lists.newArrayList("a1", "a2", "a3", "a1"); Collection<String> collection2 = Lists.newArrayList("a1", "a2", "a3", "a1"); Iterable<String> iterable1 = collection1; Iterable<String> iterable2 = collection2; MutableCollection<String> mutableCollection1 = FastList.newListWith("a1", "a2", "a3", "a1"); MutableCollection<String> mutableCollection2 = FastList.newListWith("a1", "a2", "a3", "a1"); // Проверить полное соответствие двух коллекций boolean jdk = collection1.containsAll(collection2); // c помощью JDK boolean guava = Iterables.elementsEqual(iterable1, iterable2); // с помощью guava boolean apache = CollectionUtils.containsAll(collection1, collection2); // c помощью Apache boolean gs = mutableCollection1.containsAll(mutableCollection2); // c помощью GS System.out.println("containsAll = " + jdk + ":" + guava + ":" + apache + ":" + gs); // напечатает containsAll = true:true:true:true }
Example 3
Source File: ZkBarrierForVersionUpgrade.java From samza with Apache License 2.0 | 6 votes |
@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 = State.valueOf(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.toString()); // 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); }); } }
Example 4
Source File: ContentPageValidator.java From entando-components with GNU Lesser General Public License v3.0 | 6 votes |
private void checkReferencingContents(IPage page, Set<String> pageGroups, BaseAction action) throws ApsSystemException { if (pageGroups.contains(Group.FREE_GROUP_NAME)) { return; } List<String> referencingContent = ((PageUtilizer) this.getContentManager()).getPageUtilizers(page.getCode()); if (null != referencingContent) { for (String contentId : referencingContent) { Content content = this.getContentManager().loadContent(contentId, true); if (null == content) { continue; } Set<String> contentGroups = this.getContentGroups(content); /* containsAll(Collection<?> coll1, Collection<?> coll2) Returns true iff all elements of coll2 are also contained in coll1. */ boolean check = CollectionUtils.containsAll(pageGroups, contentGroups); if (!check) { action.addFieldError("extraGroups", action.getText("error.page.contentRef.incompatibleGroups", new String[]{contentId, content.getDescription(), contentGroups.toString()})); } } } }
Example 5
Source File: ContentPageValidator.java From entando-components with GNU Lesser General Public License v3.0 | 6 votes |
private void checkPublishedContent(Content content, Set<String> pageGroups, BaseAction action) throws ApsSystemException { if (null == content) { return; } Set<String> contentGroups = this.getContentGroups(content); if (contentGroups.contains(Group.FREE_GROUP_NAME)) { return; } /* containsAll(Collection<?> coll1, Collection<?> coll2) Returns true iff all elements of coll2 are also contained in coll1. */ boolean check = CollectionUtils.containsAll(contentGroups, pageGroups); if (!check) { action.addFieldError("extraGroups", action.getText("error.page.publishedContents.incompatibleGroups", new String[]{content.getId(), content.getDescription(), contentGroups.toString()})); } }
Example 6
Source File: SymbolicLinkValidator.java From entando-components with GNU Lesser General Public License v3.0 | 6 votes |
protected AttributeFieldError checkContentDest(SymbolicLink symbLink, Content content) { Content linkedContent = null; try { linkedContent = this.getContentManager().loadContent(symbLink.getContentDest(), true); } catch (Throwable e) { throw new RuntimeException("Errore in caricamento contenuto " + symbLink.getContentDest(), e); } if (null == linkedContent) { return new AttributeFieldError(null, ICmsAttributeErrorCodes.INVALID_CONTENT, null); } Set<String> linkedContentGroups = this.extractContentGroups(linkedContent); if (linkedContentGroups.contains(Group.FREE_GROUP_NAME)) { return null; } Set<String> linkingContentGroups = this.extractContentGroups(content); boolean check = CollectionUtils.containsAll(linkedContentGroups, linkingContentGroups); if (!check) { return new AttributeFieldError(null, ICmsAttributeErrorCodes.INVALID_CONTENT_GROUPS, null); } return null; }
Example 7
Source File: ContentListHelperIntegrationTest.java From entando-components with GNU Lesser General Public License v3.0 | 5 votes |
public void testGetContents_3() throws Throwable { String newContentId = null; String pageCode = "pagina_1"; int frame = 1; try { List<String> userGroupCodes = new ArrayList<>(); userGroupCodes.add(Group.ADMINS_GROUP_NAME); List<String> contents = this.contentManager.loadPublicContentsId("ART", null, null, userGroupCodes); this.setUserOnSession("admin"); RequestContext reqCtx = this.valueRequestContext(pageCode, frame, null, null); MockContentListTagBean bean = new MockContentListTagBean(); bean.setContentType("ART"); String cacheKey = ContentListHelper.buildCacheKey(bean, reqCtx); assertNull(this.springCacheManager.getCache(ICacheInfoManager.DEFAULT_CACHE_NAME).get(cacheKey)); List<String> extractedContents = this.helper.getContentsId(bean, reqCtx); assertEquals(contents.size(), extractedContents.size()); CollectionUtils.containsAll(extractedContents, contents); assertNotNull(this.springCacheManager.getCache(ICacheInfoManager.DEFAULT_CACHE_NAME).get(cacheKey)); Content content = this.contentManager.createContentType("ART"); content.setDescription("Test Content"); content.setMainGroup(Group.ADMINS_GROUP_NAME); contentManager.insertOnLineContent(content); newContentId = content.getId(); assertNotNull(newContentId); assertNull(this.springCacheManager.getCache(ICacheInfoManager.DEFAULT_CACHE_NAME).get(cacheKey)); } catch (Throwable t) { throw t; } finally { this.setPageWidgets(pageCode, frame, null); this.deleteTestContent(newContentId); } }
Example 8
Source File: ListTools.java From o2oa with GNU Affero General Public License v3.0 | 4 votes |
public static <T> boolean containsAll(List<T> list, List<T> other) { if ((null == list) || (null == other)) { return false; } return CollectionUtils.containsAll(list, other); }