Java Code Examples for org.apache.commons.collections4.CollectionUtils#union()
The following examples show how to use
org.apache.commons.collections4.CollectionUtils#union() .
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: PythonImportLookupStrategy.java From depends with MIT License | 6 votes |
@Override public Collection<Entity> getImportedRelationEntities(List<Import> importedNames, EntityRepo repo) { Collection<Entity> files = getImportedFiles(importedNames,repo); Collection<Entity> filescontainsTypes = this.getImportedTypes(importedNames, repo,new HashSet<>()).stream().map(e->{ return e.getAncestorOfType(FileEntity.class); }).filter(new Predicate<Entity>() { @Override public boolean test(Entity t) { return t!=null; } }).collect(Collectors.toSet()); return CollectionUtils.union(files, filescontainsTypes); }
Example 2
Source File: BasicEnforcePurposeStrategy.java From prebid-server-java with Apache License 2.0 | 6 votes |
public Collection<VendorPermission> allowedByTypeStrategy(int purposeId, TCString vendorConsent, Collection<VendorPermissionWithGvl> vendorsForPurpose, Collection<VendorPermissionWithGvl> excludedVendors, boolean isEnforceVendors) { logger.debug("Basic strategy used fo purpose {0}", purposeId); final List<VendorPermission> allowedVendorPermissions = vendorsForPurpose.stream() .map(VendorPermissionWithGvl::getVendorPermission) .filter(vendorPermission -> vendorPermission.getVendorId() != null) .filter(vendorPermission -> isAllowedBySimpleConsentOrLegitimateInterest(purposeId, vendorPermission.getVendorId(), isEnforceVendors, vendorConsent)) .collect(Collectors.toList()); return CollectionUtils.union(allowedVendorPermissions, toVendorPermissions(excludedVendors)); }
Example 3
Source File: FullEnforcePurposeStrategy.java From prebid-server-java with Apache License 2.0 | 6 votes |
public Collection<VendorPermission> allowedByTypeStrategy(int purposeId, TCString vendorConsent, Collection<VendorPermissionWithGvl> vendorsForPurpose, Collection<VendorPermissionWithGvl> excludedVendors, boolean isEnforceVendors) { final List<PublisherRestriction> publisherRestrictions = vendorConsent.getPublisherRestrictions().stream() .filter(publisherRestriction -> publisherRestriction.getPurposeId() == purposeId) .collect(Collectors.toList()); final List<VendorPermission> allowedExcluded = allowedExcludedVendorPermission(excludedVendors, publisherRestrictions); final Map<VendorPermissionWithGvl, RestrictionType> vendorPermissionToRestriction = mapVendorPermission( vendorsForPurpose, publisherRestrictions); final List<VendorPermission> allowedVendorPermissions = vendorPermissionToRestriction.entrySet().stream() .filter(permissionAndRestriction -> isAllowedByPublisherRestrictionAndFlexible(purposeId, isEnforceVendors, permissionAndRestriction.getKey(), vendorConsent, permissionAndRestriction.getValue())) .map(Map.Entry::getKey) .map(VendorPermissionWithGvl::getVendorPermission) .collect(Collectors.toList()); return CollectionUtils.union(allowedExcluded, allowedVendorPermissions); }
Example 4
Source File: NoEnforcePurposeStrategy.java From prebid-server-java with Apache License 2.0 | 6 votes |
public Collection<VendorPermission> allowedByTypeStrategy(int purposeId, TCString tcString, Collection<VendorPermissionWithGvl> vendorsForPurpose, Collection<VendorPermissionWithGvl> excludedVendors, boolean isEnforceVendors) { final IntIterable vendorConsent = tcString.getVendorConsent(); final IntIterable vendorLIConsent = tcString.getVendorLegitimateInterest(); final List<VendorPermission> allowedVendorPermissions = vendorsForPurpose.stream() .map(VendorPermissionWithGvl::getVendorPermission) .filter(vendorPermission -> vendorPermission.getVendorId() != null) .filter(vendorPermission -> isAllowedByVendorConsent(vendorPermission.getVendorId(), isEnforceVendors, vendorConsent, vendorLIConsent)) .collect(Collectors.toList()); return CollectionUtils.union(allowedVendorPermissions, toVendorPermissions(excludedVendors)); }
Example 5
Source File: FanInGraph.java From gocd with Apache License 2.0 | 6 votes |
@Deprecated public Collection<MaterialRevision> computeRevisionsForReporting(CaseInsensitiveString pipelineName, PipelineTimeline pipelineTimeline) { Pair<List<RootFanInNode>, List<DependencyFanInNode>> scmAndDepMaterialsChildren = getScmAndDepMaterialsChildren(); List<RootFanInNode> scmChildren = scmAndDepMaterialsChildren.first(); List<DependencyFanInNode> depChildren = scmAndDepMaterialsChildren.last(); if (depChildren.isEmpty()) { //No fanin required all are SCMs return null; } FanInGraphContext context = buildContext(pipelineTimeline); root.initialize(context); initChildren(depChildren, pipelineName, context); iterateAndMakeAllUniqueScmRevisionsForChildrenSame(depChildren, pipelineName, context); List<MaterialRevision> finalRevisionsForScmChildren = createFinalRevisionsForScmChildren(root.latestPipelineTimelineEntry(context), scmChildren, depChildren); List<MaterialRevision> finalRevisionsForDepChildren = createFinalRevisionsForDepChildren(depChildren); return CollectionUtils.union(finalRevisionsForScmChildren, finalRevisionsForDepChildren); }
Example 6
Source File: DGEMatrix.java From Drop-seq with MIT License | 5 votes |
/** * Merges two DGE matrixes together. This retains all columns in both experiments, and adds rows that are missing in either data set. * The missing values are set to <missingValue>. * If the two experiments have overlapping cell barcodes, throw an IllegalArgumentException. * @param other The other data set to merge with this one. * @return a new DGEMatrix containing the merge of the this with other. */ public DGEMatrix mergeDisjointCells (final DGEMatrix other) { Collection<String>overlap = CollectionUtils.intersection(this.getCellBarcodes(), other.getCellBarcodes()); if (!overlap.isEmpty()) { throw new IllegalArgumentException("The two matrixes have overlapping cell barcodes, this should not happen:" + overlap.toString()); } // merge the cell barcodes. List <String> cellBarcodes = new ArrayList<>(this.getCellBarcodes()); cellBarcodes.addAll(other.getCellBarcodes()); List<String> allGenes = new ArrayList<> (CollectionUtils.union(this.getGenes(), other.getGenes())); Collections.sort(allGenes); int numCellsThis=this.getCellBarcodes().size(); int numCellsOther=other.getCellBarcodes().size(); CRSMatrix m = new CRSMatrix(allGenes.size(), cellBarcodes.size()); for (int rowIdx=0; rowIdx<allGenes.size(); rowIdx++) { String g = allGenes.get(rowIdx); double [] thisExp = getExpressionWithNull(this.getExpression(g), 0, numCellsThis); double [] otherExp = getExpressionWithNull(other.getExpression(g), 0, numCellsOther); double [] expression = ArrayUtils.addAll(thisExp, otherExp); for (int columnIdx=0; columnIdx<expression.length; columnIdx++) if (expression[columnIdx]!=0) m.set(rowIdx, columnIdx, expression[columnIdx]); } return (new DGEMatrix(cellBarcodes, allGenes, m)); }
Example 7
Source File: DGEMatrix.java From Drop-seq with MIT License | 5 votes |
/** * Merges two DGE matrixes together. This retains all cell barcodes present in both experiments, and adds rows that are missing in either data set. * If cell barcodes are present in both experiments, their UMI counts per gene [rows of the matrix] are summed. * The missing values are set to <missingValue>. * @param other The other data set to merge with this one. * @return a new DGEMatrix containing the merge of the this with other. */ public DGEMatrix mergeWithCollapse (final DGEMatrix other) { // start with this data set's cell barcodes, find barcodes that are new to the 2nd matrix, and add those. List<String> cellBarcodes = new ArrayList<>(this.getCellBarcodes()); // get the other list of cell barcodes, remove cells from the first list. List<String> cellBarcodesOther = new ArrayList<>(other.getCellBarcodes()); cellBarcodesOther.removeAll(cellBarcodes); //merge results together cellBarcodes.addAll(cellBarcodesOther); // merge the genes. List<String> allGenes = new ArrayList<> (CollectionUtils.union(this.getGenes(), other.getGenes())); Collections.sort(allGenes); int numCellsThis=this.getCellBarcodes().size(); int numCellsOther=other.getCellBarcodes().size(); // for a donor, get their position in each array [can be null in one array but not both]. // return the expression value of the donor. // need a map from the donor name to the position in the array. CRSMatrix m = new CRSMatrix(allGenes.size(), cellBarcodes.size()); for (int rowIdx=0; rowIdx<allGenes.size(); rowIdx++) { String g = allGenes.get(rowIdx); double [] thisExp = getExpressionWithNull(this.getExpression(g), 0, numCellsThis); double [] otherExp = getExpressionWithNull(other.getExpression(g), 0, numCellsOther); double [] expression = getExpression(cellBarcodes, thisExp, otherExp, this.cellBarcodeMap, other.cellBarcodeMap); for (int columnIdx=0; columnIdx<expression.length; columnIdx++) if (expression[columnIdx]!=0) m.set(rowIdx, columnIdx, expression[columnIdx]); } return (new DGEMatrix(cellBarcodes, allGenes, m)); }
Example 8
Source File: CollectionCompareTests.java From java_in_examples with Apache License 2.0 | 5 votes |
private static void testUnion() { Set<String> set1 = Sets.newHashSet("a1", "a2"); Set<String> set2 = Sets.newHashSet("a4"); MutableSet<String> mutableSet1 = UnifiedSet.newSetWith("a1", "a2"); MutableSet<String> mutableSet2 = UnifiedSet.newSetWith("a4"); Collection<String> collection1 = set1; Collection<String> collection2 = set2; // Get join two collection Set<String> jdk = new HashSet<>(set1); // using JDK jdk.addAll(set2); Set<String> guava = Sets.union(set1, set2); // using guava Collection<String> apache = CollectionUtils.union(collection1, collection2); // using Apache Set<String> gs = mutableSet1.union(mutableSet2); // using GS System.out.println("union = " + jdk + ":" + guava + ":" + apache + ":" + gs); // print union = [a1, a2, a4]:[a1, a2, a4]:[a1, a2, a4]:[a1, a2, a4] }
Example 9
Source File: CollectionCompareTests.java From java_in_examples with Apache License 2.0 | 5 votes |
private static void testUnion() { Set<String> set1 = Sets.newHashSet("a1", "a2"); Set<String> set2 = Sets.newHashSet("a4"); MutableSet<String> mutableSet1 = UnifiedSet.newSetWith("a1", "a2"); MutableSet<String> mutableSet2 = UnifiedSet.newSetWith("a4"); Collection<String> collection1 = set1; Collection<String> collection2 = set2; // Получить объедение двух коллекций Set<String> jdk = new HashSet<>(set1); // c помощью JDK jdk.addAll(set2); Set<String> guava = Sets.union(set1, set2); // с помощью guava Collection<String> apache = CollectionUtils.union(collection1, collection2); // c помощью Apache Set<String> gs = mutableSet1.union(mutableSet2); // c помощью GS System.out.println("union = " + jdk + ":" + guava + ":" + apache + ":" + gs); // напечатает union = [a1, a2, a4]:[a1, a2, a4]:[a1, a2, a4]:[a1, a2, a4] }
Example 10
Source File: FanInGraph.java From gocd with Apache License 2.0 | 5 votes |
public MaterialRevisions computeRevisions(MaterialRevisions actualRevisions, PipelineTimeline pipelineTimeline) { assertAllDirectDependenciesArePresentInInput(actualRevisions, pipelineName); Pair<List<RootFanInNode>, List<DependencyFanInNode>> scmAndDepMaterialsChildren = getScmAndDepMaterialsChildren(); List<RootFanInNode> scmChildren = scmAndDepMaterialsChildren.first(); List<DependencyFanInNode> depChildren = scmAndDepMaterialsChildren.last(); if (depChildren.isEmpty()) { //No fanin required all are SCMs return actualRevisions; } FanInGraphContext context = buildContext(pipelineTimeline); root.initialize(context); initChildren(depChildren, pipelineName, context); if (fanInEventListener != null) { fanInEventListener.iterationComplete(0, depChildren); } iterateAndMakeAllUniqueScmRevisionsForChildrenSame(depChildren, pipelineName, context); List<MaterialRevision> finalRevisionsForScmChildren = createFinalRevisionsForScmChildren(root.latestPipelineTimelineEntry(context), scmChildren, depChildren); List<MaterialRevision> finalRevisionsForDepChildren = createFinalRevisionsForDepChildren(depChildren); return new MaterialRevisions(CollectionUtils.union(getMaterialsFromCurrentPipeline(finalRevisionsForScmChildren, actualRevisions), finalRevisionsForDepChildren)); }
Example 11
Source File: CombineMultipleCollectionsUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenUsingApacheCommons_whenConcatenatingUsingUnion_thenCorrect() { Collection<String> collectionA = asList("S", "T"); Collection<String> collectionB = asList("U", "V"); Iterable<String> combinedIterables = CollectionUtils.union(collectionA, collectionB); Collection<String> collectionCombined = Lists.newArrayList(combinedIterables); Assert.assertEquals(asList("S", "T", "U", "V"), collectionCombined); }
Example 12
Source File: CollectionUtilsSample.java From spring-boot with Apache License 2.0 | 4 votes |
/** * @param args */ @SuppressWarnings({ "unchecked"}) public static void main(String[] args) { // TODO Auto-generated method stub String[] arrayA = new String[] { "1", "2", "3", "3", "4", "5" }; String[] arrayB = new String[] { "3", "4", "4", "5", "6", "7" }; List<String> a = Arrays.asList(arrayA); List<String> b = Arrays.asList(arrayB); // === list //并集 Collection<String> l_union = CollectionUtils.union(a, b); //交集 Collection<String> l_intersection = CollectionUtils.intersection(a, b); //交集的补集 Collection<String> l_disjunction = CollectionUtils.disjunction(a, b); //集合相减 Collection<String> l_subtract = CollectionUtils.subtract(a, b); Collections.sort((List<String>) l_union); Collections.sort((List<String>) l_intersection); Collections.sort((List<String>) l_disjunction); Collections.sort((List<String>) l_subtract); // === set String[] arrayC = new String[] { "1", "2", "3", "4", "5" }; String[] arrayD = new String[] { "3", "4", "5", "6", "7" }; TreeSet<String> c = new TreeSet<String>(); CollectionUtils.addAll(c, arrayC); TreeSet<String> d = new TreeSet<String>(); CollectionUtils.addAll(d, arrayD); //并集 Collection<String> s_union = CollectionUtils.union(c, d); //交集 Collection<String> s_intersection = CollectionUtils.intersection(c, d); //交集的补集 Collection<String> s_disjunction = CollectionUtils.disjunction(c, d); //集合相减 Collection<String> s_subtract = CollectionUtils.subtract(c, d); // Collections.sort((List<String>) s_union); // Collections.sort((List<String>) s_intersection); // Collections.sort((List<String>) s_disjunction); // Collections.sort((List<String>) s_subtract); System.out.println("List ========="); System.out.println("A: " + ArrayUtils.toString(a.toArray())); System.out.println("B: " + ArrayUtils.toString(b.toArray())); System.out.println("--------------------------------------------"); System.out.println("List: Union(A, B) 并集 : " + ArrayUtils.toString(l_union.toArray())); System.out.println("List: Intersection(A, B) 交集 : " + ArrayUtils.toString(l_intersection.toArray())); System.out.println("List: Disjunction(A, B) 交集的补集: " + ArrayUtils.toString(l_disjunction.toArray())); System.out.println("List: Subtract(A, B) 集合相减 : " + ArrayUtils.toString(l_subtract.toArray())); System.out.println("Set ========="); System.out.println("C: " + ArrayUtils.toString(c.toArray())); System.out.println("D: " + ArrayUtils.toString(d.toArray())); System.out.println("--------------------------------------------"); System.out.println("Set: Union(C, D) 并集 : " + ArrayUtils.toString(s_union.toArray())); System.out.println("Set: Intersection(C, D) 交集 : " + ArrayUtils.toString(s_intersection.toArray())); System.out.println("Set: Disjunction(C, D) 交集的补集: " + ArrayUtils.toString(s_disjunction.toArray())); System.out.println("Set: Subtract(C, D) 集合相减 : " + ArrayUtils.toString(s_subtract.toArray())); }
Example 13
Source File: CollectionUtilsGuideUnitTest.java From tutorials with MIT License | 4 votes |
@Test public void givenTwoLists_whenUnioned_thenCheckElementPresentInResult() { Collection<Customer> union = CollectionUtils.union(list1, list2); assertTrue(union.contains(customer1)); assertTrue(union.contains(customer4)); }