Java Code Examples for org.apache.commons.collections.CollectionUtils#containsAny()

The following examples show how to use org.apache.commons.collections.CollectionUtils#containsAny() . 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: RangerPolicyRetriever.java    From ranger with Apache License 2.0 6 votes vote down vote up
List<String> getUpdatedNames(final Map<Long, Map<String, String>> nameMappingContainer, final Long policyId, final List<String> namesToMap) {
	List<String>        ret           = null;
	Map<String, String> policyNameMap = nameMappingContainer.get(policyId);

	if (MapUtils.isNotEmpty(policyNameMap) && CollectionUtils.containsAny(policyNameMap.keySet(), namesToMap)) {
		ret = new ArrayList<>();

		for (String nameToMap : namesToMap) {
			String mappedName = policyNameMap.get(nameToMap);

			if (mappedName != null) {
				ret.add(mappedName);
			} else {
				ret.add(nameToMap);
			}
		}

	}

	return ret;
}
 
Example 2
Source File: ValidatorService.java    From axelor-open-suite with GNU Affero General Public License v3.0 6 votes vote down vote up
private void validateTab(String[] sheets, AdvancedImport advancedImport) throws AxelorException {
  if (sheets == null) {
    return;
  }
  List<String> sheetList = Arrays.asList(sheets);
  List<String> tabList =
      advancedImport
          .getFileTabList()
          .stream()
          .map(tab -> tab.getName())
          .collect(Collectors.toList());

  if (!CollectionUtils.containsAny(tabList, sheetList)) {
    throw new AxelorException(
        TraceBackRepository.CATEGORY_CONFIGURATION_ERROR,
        I18n.get(IExceptionMessage.ADVANCED_IMPORT_TAB_ERR));
  }
}
 
Example 3
Source File: HugeTraverser.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
public List<Id> joinPath(Node back) {
    // Get self path
    List<Id> path = this.path();

    // Get reversed other path
    List<Id> backPath = back.path();
    Collections.reverse(backPath);

    // Avoid loop in path
    if (CollectionUtils.containsAny(path, backPath)) {
        return ImmutableList.of();
    }

    // Append other path behind self path
    path.addAll(backPath);
    return path;
}
 
Example 4
Source File: SearchProcessor.java    From atlas with Apache License 2.0 5 votes vote down vote up
protected void filterWhiteSpaceClassification(List<AtlasVertex> entityVertices) {
    if (CollectionUtils.isNotEmpty(entityVertices)) {
        final Iterator<AtlasVertex> it              = entityVertices.iterator();
        final Set<String>           typeAndSubTypes = context.getClassificationTypeNames();

        while (it.hasNext()) {
            AtlasVertex  entityVertex        = it.next();
            List<String> classificationNames = AtlasGraphUtilsV2.getClassificationNames(entityVertex);

            if (CollectionUtils.isNotEmpty(classificationNames)) {
                if (typeAndSubTypes.isEmpty() || CollectionUtils.containsAny(classificationNames, typeAndSubTypes)) {
                    continue;
                }
            }

            List<String> propagatedClassificationNames = AtlasGraphUtilsV2.getPropagatedClassificationNames(entityVertex);

            if (CollectionUtils.isNotEmpty(propagatedClassificationNames)) {
                if (typeAndSubTypes.isEmpty() || CollectionUtils.containsAny(propagatedClassificationNames, typeAndSubTypes)) {
                    continue;
                }
            }

            it.remove();
        }
    }
}
 
Example 5
Source File: Mutant.java    From CodeDefenders with GNU Lesser General Public License v3.0 5 votes vote down vote up
public boolean doesRequireRecompilation() {
    // dummy game with id = -1 has null class, and this check cannot be implemented...
    GameClass cut = GameClassDAO.getClassForGameId(gameId);
    if(  cut == null ){
        cut = GameClassDAO.getClassForId(classId);
    }
    return CollectionUtils.containsAny(cut.getCompileTimeConstants(), getLines());
}
 
Example 6
Source File: Mutant.java    From CodeDefenders with GNU Lesser General Public License v3.0 5 votes vote down vote up
public boolean isCovered() {
    List<Test> tests = TestDAO.getValidTestsForGame(gameId, true);
    for (Test t : tests) {
        if (CollectionUtils.containsAny(t.getLineCoverage().getLinesCovered(), getLines()))
            return true;
    }
    return false;
}
 
Example 7
Source File: IpcSharedMemoryCrashDetectionSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testIgfsServerClientInteractionsUponClientKilling() throws Exception {
    // Run server endpoint.
    IpcSharedMemoryServerEndpoint srv = new IpcSharedMemoryServerEndpoint(U.defaultWorkDirectory());

    new IgniteTestResources().inject(srv);

    try {
        srv.start();

        info("Check that server gets correct exception upon client's killing.");

        info("Shared memory IDs before starting client endpoint: " + IpcSharedMemoryUtils.sharedMemoryIds());

        Collection<Integer> shmemIdsWithinInteractions = interactWithClient(srv, true);

        Collection<Integer> shmemIdsAfterInteractions = null;

        // Give server endpoint some time to make resource clean up. See IpcSharedMemoryServerEndpoint.GC_FREQ.
        for (int i = 0; i < 12; i++) {
            shmemIdsAfterInteractions = IpcSharedMemoryUtils.sharedMemoryIds();

            info("Shared memory IDs created within interaction: " + shmemIdsWithinInteractions);
            info("Shared memory IDs after killing client endpoint: " + shmemIdsAfterInteractions);

            if (CollectionUtils.containsAny(shmemIdsAfterInteractions, shmemIdsWithinInteractions))
                U.sleep(1000);
            else
                break;
        }

        assertFalse("List of shared memory IDs after killing client endpoint should not include IDs created " +
            "within server-client interactions.",
            CollectionUtils.containsAny(shmemIdsAfterInteractions, shmemIdsWithinInteractions));
    }
    finally {
        srv.close();
    }
}
 
Example 8
Source File: RangerPreAuthSecurityHandler.java    From ranger with Apache License 2.0 5 votes vote down vote up
public boolean isAPIAccessible(Set<String> associatedTabs) throws Exception {

		UserSessionBase userSession = ContextUtil.getCurrentUserSession();
		if (userSession != null) {
			sessionMgr.refreshPermissionsIfNeeded(userSession);
			if (userSession.getRangerUserPermission() != null) {
				CopyOnWriteArraySet<String> accessibleModules = userSession.getRangerUserPermission().getUserPermissions();
				if (CollectionUtils.containsAny(accessibleModules, associatedTabs)) {
					return true;
				}
			}
		}

		throw restErrorUtil.createRESTException(HttpServletResponse.SC_FORBIDDEN, "User is not allowed to access the API", true);
	}
 
Example 9
Source File: CubeDesc.java    From kylin with Apache License 2.0 5 votes vote down vote up
private Pair<Boolean, Set<String>> hasOverlap(ArrayList<Set<String>> dimsList, Set<String> Dims) {
    Set<String> existing = new HashSet<>();
    Set<String> overlap = new HashSet<>();
    for (Set<String> dims : dimsList) {
        if (CollectionUtils.containsAny(existing, dims)) {
            overlap.addAll(ensureOrder(CollectionUtils.intersection(existing, dims)));
        }
        existing.addAll(dims);
    }
    return new Pair<>(overlap.size() > 0, overlap);
}
 
Example 10
Source File: Test.java    From CodeDefenders with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Set<Mutant> getCoveredMutants(List<Mutant> mutants) {
    List<Integer> coverage = lineCoverage.getLinesCovered();
    Set<Mutant> coveredMutants = new TreeSet<>(Mutant.orderByIdAscending());

    for(Mutant m : mutants) {
        if(CollectionUtils.containsAny(coverage, m.getLines())) {
            coveredMutants.add(m);
        }
    }

    return coveredMutants;
}
 
Example 11
Source File: ServiceRESTUtil.java    From ranger with Apache License 2.0 5 votes vote down vote up
static private boolean removeUsersGroupsAndRolesFromPolicy(RangerPolicy policy, Set<String> users, Set<String> groups, Set<String> roles) {
	boolean policyUpdated = false;

	List<RangerPolicy.RangerPolicyItem> policyItems = policy.getPolicyItems();

	int numOfItems = policyItems.size();

	for(int i = 0; i < numOfItems; i++) {
		RangerPolicy.RangerPolicyItem policyItem = policyItems.get(i);

		if(CollectionUtils.containsAny(policyItem.getUsers(), users)) {
			policyItem.getUsers().removeAll(users);

			policyUpdated = true;
		}

		if(CollectionUtils.containsAny(policyItem.getGroups(), groups)) {
			policyItem.getGroups().removeAll(groups);

			policyUpdated = true;
		}

		if(CollectionUtils.containsAny(policyItem.getRoles(), roles)) {
			policyItem.getRoles().removeAll(roles);

			policyUpdated = true;
		}

		if(CollectionUtils.isEmpty(policyItem.getUsers()) && CollectionUtils.isEmpty(policyItem.getGroups()) && CollectionUtils.isEmpty(policyItem.getRoles())) {
			policyItems.remove(i);
			numOfItems--;
			i--;

			policyUpdated = true;
		}
	}

	return policyUpdated;
}
 
Example 12
Source File: CollectionStringContainAnyComparator.java    From spring-cloud-gray with Apache License 2.0 5 votes vote down vote up
@Override
public boolean test(Collection<String> src, Collection<String> another) {
    if (CollectionUtils.isEmpty(src)) {
        return false;
    }
    if (CollectionUtils.isEmpty(another)) {
        return false;
    }

    return CollectionUtils.containsAny(src, another);
}
 
Example 13
Source File: ReachabilityGraph.java    From systemds with Apache License 2.0 5 votes vote down vote up
private ArrayList<Pair<CutSet,Double>> evaluateCutSets(ArrayList<ArrayList<NodeLink>> candCS, ArrayList<ArrayList<NodeLink>> remain) {
	ArrayList<Pair<CutSet,Double>> cutSets = new ArrayList<>();
	
	for( ArrayList<NodeLink> cand : candCS ) {
		HashSet<NodeLink> probe = new HashSet<>(cand);
		
		//determine subproblems for cutset candidates
		HashSet<NodeLink> part1 = new HashSet<>();
		rCollectInputs(_root, probe, part1);
		HashSet<NodeLink> part2 = new HashSet<>();
		for( NodeLink rNode : cand )
			rCollectInputs(rNode, probe, part2);
		
		//select, score and create cutsets
		if( !CollectionUtils.containsAny(part1, part2) 
			&& !part1.isEmpty() && !part2.isEmpty()) {
			//score cutsets (smaller is better)
			double base = UtilFunctions.pow(2, _matPoints.size());
			double numComb = UtilFunctions.pow(2, cand.size());
			double score = (numComb-1)/numComb * base
				+ 1/numComb * UtilFunctions.pow(2, part1.size())
				+ 1/numComb * UtilFunctions.pow(2, part2.size());
			
			//construct cutset
			cutSets.add(Pair.of(new CutSet(
				cand.stream().map(p->p._p).toArray(InterestingPoint[]::new), 
				part1.stream().map(p->p._p).toArray(InterestingPoint[]::new), 
				part2.stream().map(p->p._p).toArray(InterestingPoint[]::new)), score));
		}
		else {
			remain.add(cand);
		}
	}
	
	return cutSets;
}
 
Example 14
Source File: ValueIsNotAnyOf.java    From onedev with MIT License 4 votes vote down vote up
@Override
public boolean matches(List<String> values) {
	return !CollectionUtils.containsAny(getValues(), values);
}
 
Example 15
Source File: RangerPolicyEngineImpl.java    From ranger with Apache License 2.0 4 votes vote down vote up
public boolean hasSuperGroup(Set<String> userGroups) {
	return userGroups != null && userGroups.size() > 0 && superGroups.size() > 0 && CollectionUtils.containsAny(userGroups, superGroups);
}
 
Example 16
Source File: RoleREST.java    From ranger with Apache License 2.0 4 votes vote down vote up
private boolean containsInvalidUser(List<String> users) {
    return CollectionUtils.isNotEmpty(users) && CollectionUtils.containsAny(users, INVALID_USERS);
}
 
Example 17
Source File: StudentListByDegreeDA.java    From fenixedu-academic with GNU Lesser General Public License v3.0 4 votes vote down vote up
static private boolean hasStudentStatuteType(final SearchStudentsByDegreeParametersBean searchBean,
        final Registration registration) {
    return CollectionUtils.containsAny(searchBean.getStudentStatuteTypes(), registration.getStudent()
            .getStatutesTypesValidOnAnyExecutionSemesterFor(searchBean.getExecutionYear()));
}
 
Example 18
Source File: IpcSharedMemoryCrashDetectionSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Ignore("https://issues.apache.org/jira/browse/IGNITE-1386")
@Test
public void testIgfsClientServerInteractionsUponServerKilling() throws Exception {
    Collection<Integer> shmemIdsBeforeInteractions = IpcSharedMemoryUtils.sharedMemoryIds();

    info("Shared memory IDs before starting server-client interactions: " + shmemIdsBeforeInteractions);

    Collection<Integer> shmemIdsWithinInteractions = interactWithServer();

    Collection<Integer> shmemIdsAfterInteractions = IpcSharedMemoryUtils.sharedMemoryIds();

    info("Shared memory IDs created within interaction: " + shmemIdsWithinInteractions);
    info("Shared memory IDs after server and client killing: " + shmemIdsAfterInteractions);

    if (!U.isLinux())
        assertTrue("List of shared memory IDs after server-client interactions should include IDs created within " +
            "client-server interactions.", shmemIdsAfterInteractions.containsAll(shmemIdsWithinInteractions));
    else
        assertFalse("List of shared memory IDs after server-client interactions should not include IDs created " +
            "(on Linux): within client-server interactions.",
            CollectionUtils.containsAny(shmemIdsAfterInteractions, shmemIdsWithinInteractions));

    ProcessStartResult srvStartRes = startSharedMemoryTestServer();

    try {
        // Give server endpoint some time to make resource clean up. See IpcSharedMemoryServerEndpoint.GC_FREQ.
        for (int i = 0; i < 12; i++) {
            shmemIdsAfterInteractions = IpcSharedMemoryUtils.sharedMemoryIds();

            info("Shared memory IDs after server restart: " + shmemIdsAfterInteractions);

            if (CollectionUtils.containsAny(shmemIdsAfterInteractions, shmemIdsWithinInteractions))
                U.sleep(1000);
            else
                break;
        }

        assertFalse("List of shared memory IDs after server endpoint restart should not include IDs created: " +
            "within client-server interactions.",
            CollectionUtils.containsAny(shmemIdsAfterInteractions, shmemIdsWithinInteractions));
    }
    finally {
        srvStartRes.proc().kill();

        srvStartRes.isKilledLatch().await();
    }
}
 
Example 19
Source File: OutboundMobilityCandidacyContestGroup.java    From fenixedu-academic with GNU Lesser General Public License v3.0 4 votes vote down vote up
private boolean intersect(final OutboundMobilityCandidacyContestGroup otherGroup) {
    return CollectionUtils.containsAny(getExecutionDegreeSet(), otherGroup.getExecutionDegreeSet());
}
 
Example 20
Source File: CubeDesc.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
public void validateAggregationGroups() {
    int index = 1;

    for (AggregationGroup agg : getAggregationGroups()) {
        if (agg.getIncludes() == null) {
            logger.error("Aggregation group " + index + " 'includes' field not set");
            throw new IllegalStateException("Aggregation group " + index + " includes field not set");
        }

        if (agg.getSelectRule() == null) {
            logger.error("Aggregation group " + index + " 'select_rule' field not set");
            throw new IllegalStateException("Aggregation group " + index + " select rule field not set");
        }

        Set<String> includeDims = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
        getDims(includeDims, agg.getIncludes());

        Set<String> mandatoryDims = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
        getDims(mandatoryDims, agg.getSelectRule().mandatoryDims);

        ArrayList<Set<String>> hierarchyDimsList = Lists.newArrayList();
        Set<String> hierarchyDims = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
        getDims(hierarchyDimsList, hierarchyDims, agg.getSelectRule().hierarchyDims);

        ArrayList<Set<String>> jointDimsList = Lists.newArrayList();
        Set<String> jointDims = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
        getDims(jointDimsList, jointDims, agg.getSelectRule().jointDims);

        if (!includeDims.containsAll(mandatoryDims) || !includeDims.containsAll(hierarchyDims)
                || !includeDims.containsAll(jointDims)) {
            List<String> notIncluded = Lists.newArrayList();
            final Iterable<String> all = Iterables
                    .unmodifiableIterable(Iterables.concat(mandatoryDims, hierarchyDims, jointDims));
            for (String dim : all) {
                if (includeDims.contains(dim) == false) {
                    notIncluded.add(dim);
                }
            }
            Collections.sort(notIncluded);
            logger.error(
                    "Aggregation group " + index + " Include dimensions not containing all the used dimensions");
            throw new IllegalStateException("Aggregation group " + index
                    + " 'includes' dimensions not include all the dimensions:" + notIncluded.toString());
        }

        if (CollectionUtils.containsAny(mandatoryDims, hierarchyDims)) {
            logger.warn("Aggregation group " + index + " mandatory dimensions overlap with hierarchy dimensions: "
                    + ensureOrder(CollectionUtils.intersection(mandatoryDims, hierarchyDims)));
        }
        if (CollectionUtils.containsAny(mandatoryDims, jointDims)) {
            logger.warn("Aggregation group " + index + " mandatory dimensions overlap with joint dimensions: "
                    + ensureOrder(CollectionUtils.intersection(mandatoryDims, jointDims)));
        }

        if (CollectionUtils.containsAny(hierarchyDims, jointDims)) {
            logger.error("Aggregation group " + index + " hierarchy dimensions overlap with joint dimensions");
            throw new IllegalStateException(
                    "Aggregation group " + index + " hierarchy dimensions overlap with joint dimensions: "
                            + ensureOrder(CollectionUtils.intersection(hierarchyDims, jointDims)));
        }

        if (hasSingleOrNone(hierarchyDimsList)) {
            logger.error("Aggregation group " + index + " require at least 2 dimensions in a hierarchy");
            throw new IllegalStateException(
                    "Aggregation group " + index + " require at least 2 dimensions in a hierarchy.");
        }
        if (hasSingleOrNone(jointDimsList)) {
            logger.error("Aggregation group " + index + " require at least 2 dimensions in a joint");
            throw new IllegalStateException(
                    "Aggregation group " + index + " require at least 2 dimensions in a joint");
        }

        Pair<Boolean, Set<String>> overlap = hasOverlap(hierarchyDimsList, hierarchyDims);
        if (overlap.getFirst() == true) {
            logger.error("Aggregation group " + index + " a dimension exist in more than one hierarchy: "
                    + ensureOrder(overlap.getSecond()));
            throw new IllegalStateException("Aggregation group " + index
                    + " a dimension exist in more than one hierarchy: " + ensureOrder(overlap.getSecond()));
        }

        overlap = hasOverlap(jointDimsList, jointDims);
        if (overlap.getFirst() == true) {
            logger.error("Aggregation group " + index + " a dimension exist in more than one joint: "
                    + ensureOrder(overlap.getSecond()));
            throw new IllegalStateException("Aggregation group " + index
                    + " a dimension exist in more than one joint: " + ensureOrder(overlap.getSecond()));
        }

        index++;
    }
}