Java Code Examples for java.util.List.retainAll()

The following are Jave code examples for showing how to use retainAll() of the java.util.List class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: devoxxus-jhipster-microservices-demo   File: ProfileInfoResource.java   Source Code and License Vote up 6 votes
private String getRibbonEnv() {
    String[] activeProfiles = env.getActiveProfiles();
    String[] displayOnActiveProfiles = jHipsterProperties.getRibbon().getDisplayOnActiveProfiles();

    if (displayOnActiveProfiles == null) {
        return null;
    }

    List<String> ribbonProfiles = new ArrayList<>(Arrays.asList(displayOnActiveProfiles));
    List<String> springBootProfiles = Arrays.asList(activeProfiles);
    ribbonProfiles.retainAll(springBootProfiles);

    if (ribbonProfiles.size() > 0) {
        return ribbonProfiles.get(0);
    }
    return null;
}
 
Example 2
Project: premier-wherehows   File: DatasetDao.java   Source Code and License Vote up 6 votes
public static ObjectNode getCommonParents(String urnOne, String urnTwo) {
  ObjectNode result = Json.newObject();

  // get lists of parents for both urns
  List<String> oneParents = getParents(urnOne);
  List<String> twoParents = getParents(urnOne);

  // create a list to hold just the common parents
  List<String> commonParents = new ArrayList<>(oneParents);

  // retainAll() leaves commonParents with just the values in both lists
  commonParents.retainAll(twoParents);
  if (commonParents != null && commonParents.size() > 0) {
    result.put("return_code", 200);
    result.put("common_parents", commonParents.toString());
  } else {
    result.put("return_code", 404);
    result.put("error_message", "No common parents found");
  }

  return result;
}
 
Example 3
Project: yadaframework   File: YadaEmailService.java   Source Code and License Vote up 6 votes
private String[] purifyRecipients(String[] addresses, YadaEmailContent yadaEmailContent) {
	// Se <validEmail> esiste, mando solo se l'email è nella lista
	List<String> validEmail = config.getValidDestinationEmails();
	if (validEmail!=null && !validEmail.isEmpty()) {
		List<String> recipients = new ArrayList<String>(Arrays.asList(addresses)); // Il doppio passaggio serve perchè asList è fixed size
		// Tengo solo quelli validi
		if (recipients.retainAll(validEmail)) {
			// Alcuni sono stati rimossi. Logghiamo quelli rimossi
			List<String> invalidEmails = new ArrayList<String>(Arrays.asList(addresses)); // Il doppio passaggio serve perchè asList è fixed size
			invalidEmails.removeAll(validEmail);
			for (String address : invalidEmails) {
				log.warn("Email not authorized in configuration (not in <validEmail>). Skipping message for '{}' from='{}' subject='{}' body='{}'",
					new Object[]{address, yadaEmailContent.from, yadaEmailContent.subject, yadaEmailContent.body});
			}
		}
		return recipients.toArray(new String[0]);
	} else {
		return addresses;
	}
}
 
Example 4
Project: Equella   File: TLEGroupServiceImpl.java   Source Code and License Vote up 6 votes
/**
 * We are searching on a query string (on group name), or by user as member, or both.
 * If the user search is invoked, the boolean flag indicates if all parents of the group
 * are to be included in the result set
 */
@Override
public List<TLEGroup> search(String query, String userId, boolean allParents)
{
	if( Check.isEmpty(userId) )
	{
		return search(query);
	}
	else
	{
		List<TLEGroup> userGroups = getGroupsContainingUser(userId, allParents);
		if( Check.isEmpty(query) )
		{
			return userGroups;
		}
		else
		{
			List<TLEGroup> queryGroups = search(query);
			queryGroups.retainAll(userGroups);
			return queryGroups;
		}
	}
}
 
Example 5
Project: incubator-netbeans   File: NbBuildLogger.java   Source Code and License Vote up 6 votes
/**
 * Get those loggers interested in a given event.
 */
private Collection<AntLogger> getInterestedLoggersByEvent(AntEvent e) {
    File scriptLocation = e.getScriptLocation();
    String targetName = e.getTargetName();
    String taskName = e.getTaskName();
    int logLevel = e.getLogLevel();
    synchronized (this) { // #132945: <parallel> can deadlock if you block on event info here
        initInterestedLoggers();
        // Start with the smallest one and go down.
        interestedLoggersByVariousCriteria[0] = getInterestedLoggersByScript(scriptLocation);
        interestedLoggersByVariousCriteria[1] = getInterestedLoggersByTarget(targetName);
        interestedLoggersByVariousCriteria[2] = getInterestedLoggersByTask(taskName);
        interestedLoggersByVariousCriteria[3] = getInterestedLoggersByLevel(logLevel);
        Arrays.sort(interestedLoggersByVariousCriteria, INTERESTED_LOGGERS_SORTER);
        LOG.log(Level.FINEST, "getInterestedLoggersByVariousCriteria: event={0} loggers={1}", new Object[] {e, Arrays.asList(interestedLoggersByVariousCriteria)});
        // XXX could probably be even a bit more efficient by iterating on the fly...
        // and by skipping the sorting which is probably overkill for a small number of a loggers (or hardcode the sort)
        List<AntLogger> loggers = new LinkedList<AntLogger>(interestedLoggersByVariousCriteria[0]);
        for (int i = 1; i < 4; i++) {
            loggers.retainAll(interestedLoggersByVariousCriteria[i]);
        }
        LOG.log(Level.FINEST, "getInterestedLoggersByEvent: event={0} loggers={1}", new Object[] {e, loggers});
        return loggers;
    }
}
 
Example 6
Project: incubator-netbeans   File: SortSuiteModules.java   Source Code and License Vote up 6 votes
private static <T> List<T> topologicalSort(Collection<T> c, Map<? super T, ? extends Collection<? extends T>> edges)
throws TopologicalSortException {
    Map<T,Boolean> finished = new HashMap<>();
    List<T> r = new ArrayList<>(Math.max(c.size(), 1));
    List<T> cRev = new ArrayList<>(c);
    Collections.reverse(cRev);

    Iterator<T> it = cRev.iterator();

    while (it.hasNext()) {
        List<T> cycle = visit(it.next(), edges, finished, r);

        if (cycle != null) {
            throw new TopologicalSortException("Cycle detected: " + cycle.toString());
        }
    }

    Collections.reverse(r);
    if (r.size() != c.size()) {
        r.retainAll(c);
    }

    return r;
}
 
Example 7
Project: incubator-netbeans   File: EvaluatorVisitor.java   Source Code and License Vote up 6 votes
@Override
public List<String> availableStrata() {
    List<String> mstrata = null;
    List<String> strata = null;
    for (ReferenceType t : types) {
        List<String> tstrata = t.availableStrata();
        if (strata == null) {
            strata = tstrata;
        } else if (!tstrata.containsAll(strata)) {
            if (mstrata == null) {
                mstrata = new ArrayList<String>(strata);
            }
            mstrata.retainAll(tstrata);
        }
    }
    if (mstrata != null) {
        return mstrata;
    } else {
        return strata;
    }
}
 
Example 8
Project: sentry   File: ProfileInfoResource.java   Source Code and License Vote up 6 votes
private String getRibbonEnv(String[] activeProfiles) {
    String[] displayOnActiveProfiles = jHipsterProperties.getRibbon().getDisplayOnActiveProfiles();

    if (displayOnActiveProfiles == null) {
        return null;
    }

    List<String> ribbonProfiles = new ArrayList<>(Arrays.asList(displayOnActiveProfiles));
    List<String> springBootProfiles = Arrays.asList(activeProfiles);
    ribbonProfiles.retainAll(springBootProfiles);

    if (ribbonProfiles.size() > 0) {
        return ribbonProfiles.get(0);
    }
    return null;
}
 
Example 9
Project: generator-jhipster-grpc   File: _ProfileInfoService.java   Source Code and License Vote up 5 votes
private String getRibbonEnv(String[] activeProfiles) {
    String[] displayOnActiveProfiles = jHipsterProperties.getRibbon().getDisplayOnActiveProfiles();
    if (displayOnActiveProfiles == null) {
        return null;
    }
    List<String> ribbonProfiles = new ArrayList<>(Arrays.asList(displayOnActiveProfiles));
    List<String> springBootProfiles = Arrays.asList(activeProfiles);
    ribbonProfiles.retainAll(springBootProfiles);
    if (!ribbonProfiles.isEmpty()) {
        return ribbonProfiles.get(0);
    }
    return null;
}
 
Example 10
Project: alfresco-core   File: CollectionUtils.java   Source Code and License Vote up 5 votes
/**
 * This method returns a new ArrayList which is the intersection of the two List parameters, based on {@link Object#equals(Object) equality}
 * of their elements.
 * The intersection list will contain elements in the order they have in list1 and any references in the resultant list will be
 * to elements within list1 also.
 * 
 * @return a new ArrayList whose values represent the intersection of the two Lists.
 */
public static <T> List<T> intersect(List<? extends T> list1, List<? extends T> list2)
{
    if (list1 == null || list1.isEmpty() || list2 == null || list2.isEmpty())
    {
        return Collections.emptyList();
    }
    
    List<T> result = new ArrayList<T>();
    result.addAll(list1);
    
    result.retainAll(list2);
    
    return result;
}
 
Example 11
Project: Armory   File: ProfileInfoResource.java   Source Code and License Vote up 5 votes
private String getRibbonEnv(String[] activeProfiles) {
    String[] displayOnActiveProfiles = jHipsterProperties.getRibbon().getDisplayOnActiveProfiles();
    if (displayOnActiveProfiles == null) {
        return null;
    }
    List<String> ribbonProfiles = new ArrayList<>(Arrays.asList(displayOnActiveProfiles));
    List<String> springBootProfiles = Arrays.asList(activeProfiles);
    ribbonProfiles.retainAll(springBootProfiles);
    if (!ribbonProfiles.isEmpty()) {
        return ribbonProfiles.get(0);
    }
    return null;
}
 
Example 12
Project: MTC_Labrat   File: ProfileInfoResource.java   Source Code and License Vote up 5 votes
private String getRibbonEnv(String[] activeProfiles) {
    String[] displayOnActiveProfiles = jHipsterProperties.getRibbon().getDisplayOnActiveProfiles();
    if (displayOnActiveProfiles == null) {
        return null;
    }
    List<String> ribbonProfiles = new ArrayList<>(Arrays.asList(displayOnActiveProfiles));
    List<String> springBootProfiles = Arrays.asList(activeProfiles);
    ribbonProfiles.retainAll(springBootProfiles);
    if (!ribbonProfiles.isEmpty()) {
        return ribbonProfiles.get(0);
    }
    return null;
}
 
Example 13
Project: codemotion-2017-taller-de-jhipster   File: ProfileInfoResource.java   Source Code and License Vote up 5 votes
private String getRibbonEnv(String[] activeProfiles) {
    String[] displayOnActiveProfiles = jHipsterProperties.getRibbon().getDisplayOnActiveProfiles();
    if (displayOnActiveProfiles == null) {
        return null;
    }
    List<String> ribbonProfiles = new ArrayList<>(Arrays.asList(displayOnActiveProfiles));
    List<String> springBootProfiles = Arrays.asList(activeProfiles);
    ribbonProfiles.retainAll(springBootProfiles);
    if (!ribbonProfiles.isEmpty()) {
        return ribbonProfiles.get(0);
    }
    return null;
}
 
Example 14
Project: devoxxus-jhipster-microservices-demo   File: ProfileInfoResource.java   Source Code and License Vote up 5 votes
private String getRibbonEnv(String[] activeProfiles) {
    String[] displayOnActiveProfiles = jHipsterProperties.getRibbon().getDisplayOnActiveProfiles();
    if (displayOnActiveProfiles == null) {
        return null;
    }
    List<String> ribbonProfiles = new ArrayList<>(Arrays.asList(displayOnActiveProfiles));
    List<String> springBootProfiles = Arrays.asList(activeProfiles);
    ribbonProfiles.retainAll(springBootProfiles);
    if (!ribbonProfiles.isEmpty()) {
        return ribbonProfiles.get(0);
    }
    return null;
}
 
Example 15
Project: incubator-netbeans   File: ComputeOverriders.java   Source Code and License Vote up 5 votes
private List<URL> reverseSourceRootsInOrder(CompilationInfo info, URL thisSourceRoot, FileObject thisSourceRootFO, Map<URL, List<URL>> sourceDeps, Map<URL, List<URL>> binaryDeps, Map<URL, List<URL>> rootPeers, boolean interactive) {
    if (reverseSourceRootsInOrderOverride != null) {
        return reverseSourceRootsInOrderOverride;
    }

    final Set<URL> sourceRootsSet = new HashSet<>();

    if (sourceDeps.containsKey(thisSourceRoot)) {
        sourceRootsSet.addAll(findReverseSourceRoots(thisSourceRoot, sourceDeps, rootPeers, info.getFileObject()));
    }
    for (URL binary : findBinaryRootsForSourceRoot(thisSourceRootFO, binaryDeps)) {
        final List<URL> deps = binaryDeps.get(binary);
        if (deps != null) {
            sourceRootsSet.addAll(deps);
        }
    }
    List<URL> sourceRoots;
    try {
        sourceRoots = new LinkedList<URL>(Utilities.topologicalSort(sourceDeps.keySet(), sourceDeps));
    } catch (TopologicalSortException ex) {
        if (interactive) {
            Exceptions.attachLocalizedMessage(ex,NbBundle.getMessage(GoToImplementation.class, "ERR_CycleInDependencies"));
            Exceptions.printStackTrace(ex);
        } else {
            LOG.log(Level.FINE, null, ex);
        }
        return null;
    }

    sourceRoots.retainAll(sourceRootsSet);

    Collections.reverse(sourceRoots);

    return sourceRoots;
}
 
Example 16
Project: cf-mta-deploy-service   File: UrisClassifier.java   Source Code and License Vote up 5 votes
public List<String> getDescriptorDefinedUris(DeployedMtaModule deployedModule) {
    if (deployedModule == null) {
        return Collections.emptyList();
    }
    List<String> allUris = getUrisWithoutScheme(deployedModule);
    List<String> descriptorDefinedUris = getDescriptorDefinedUrisOrDefault(deployedModule, allUris);
    descriptorDefinedUris.retainAll(allUris);
    return descriptorDefinedUris;
}
 
Example 17
Project: spring-io   File: ProfileInfoResource.java   Source Code and License Vote up 5 votes
private String getRibbonEnv(String[] activeProfiles) {
    String[] displayOnActiveProfiles = jHipsterProperties.getRibbon().getDisplayOnActiveProfiles();
    if (displayOnActiveProfiles == null) {
        return null;
    }
    List<String> ribbonProfiles = new ArrayList<>(Arrays.asList(displayOnActiveProfiles));
    List<String> springBootProfiles = Arrays.asList(activeProfiles);
    ribbonProfiles.retainAll(springBootProfiles);
    if (!ribbonProfiles.isEmpty()) {
        return ribbonProfiles.get(0);
    }
    return null;
}
 
Example 18
Project: hue   File: JoinDetector.java   Source Code and License Vote up 4 votes
private boolean getJoinByData() {
	logger.debug("Searching for a join by matching data..");
	try {
		ArrayList<String> l = Lists.newArrayList();
		ArrayList<String> r = Lists.newArrayList();
		for(int i =1; i<=left.getMetaData().getColumnCount(); i++){
			String lname = left.getMetaData().getColumnName(i);
			List<String> lvalues = Lists.newArrayList();
			left.beforeFirst();
			while(left.next()){
				lvalues.add(left.getString(i));
			}

			for(int j =1; j<=right.getMetaData().getColumnCount(); j++){
				String rname = right.getMetaData().getColumnName(j);
				List<String> rvalues = Lists.newArrayList();
				right.beforeFirst();
				while(right.next()){
					rvalues.add(right.getString(j));
				}
				List<String> rinter = Lists.newArrayList(rvalues);
				boolean thereAreSomeNoMatches = rinter.retainAll(lvalues);
				if(thereAreSomeNoMatches){
					double x = rinter.size()/(rvalues.size()*1.000);
					if(x > 0.1){
						l.add(lname);
						r.add(rname);
						break;
					}
				}else{
					l.add(lname);
					r.add(rname);
					break;
				}
			}
			if(l.size()>0) break;
		}
		if(l.size()>0){
			setCardinality(l,r);
			setFormula(l,r);
			return true;
		}else{
			return false;
		}

	} catch (SQLException e) {
		logger.error("Somethign went wrong while searching for a join"
				+ " between " + jd.getLeft() + " and " + jd.getRight() +"\n"+e.getMessage());
		return false;
	}

}
 
Example 19
Project: tomcat7   File: JSSESocketFactory.java   Source Code and License Vote up 4 votes
@Override
public String[] getEnableableCiphers(SSLContext context) {
    String requestedCiphersStr = endpoint.getCiphers();

    if (ALLOW_ALL_SUPPORTED_CIPHERS.equals(requestedCiphersStr)) {
        return context.getSupportedSSLParameters().getCipherSuites();
    }
    if ((requestedCiphersStr == null)
            || (requestedCiphersStr.trim().length() == 0)) {
        return defaultServerCipherSuites;
    }

    List<String> requestedCiphers = new ArrayList<String>();
    for (String rc : requestedCiphersStr.split(",")) {
        final String cipher = rc.trim();
        if (cipher.length() > 0) {
            requestedCiphers.add(cipher);
        }
    }
    if (requestedCiphers.isEmpty()) {
        return defaultServerCipherSuites;
    }
    List<String> ciphers = new ArrayList<String>(requestedCiphers);
    String[] supportedCipherSuiteArray = context.getSupportedSSLParameters().getCipherSuites();
    // The IBM JRE will accept cipher suites names SSL_xxx or TLS_xxx but
    // only returns the SSL_xxx form for supported cipher suites. Therefore
    // need to filter the requested cipher suites using both forms with an
    // IBM JRE.
    List<String> supportedCipherSuiteList;
    if (JreVendor.IS_IBM_JVM) {
        supportedCipherSuiteList = new ArrayList<String>(supportedCipherSuiteArray.length * 2);
        for (String name : supportedCipherSuiteArray) {
            supportedCipherSuiteList.add(name);
            if (name.startsWith("SSL")) {
                supportedCipherSuiteList.add("TLS" + name.substring(3));
            }
        }
    } else {
        supportedCipherSuiteList = Arrays.asList(supportedCipherSuiteArray);
    }
    ciphers.retainAll(supportedCipherSuiteList);

    if (ciphers.isEmpty()) {
        log.warn(sm.getString("jsse.requested_ciphers_not_supported",
                requestedCiphersStr));
    }
    if (log.isDebugEnabled()) {
        log.debug(sm.getString("jsse.enableable_ciphers", ciphers));
        if (ciphers.size() != requestedCiphers.size()) {
            List<String> skipped = new ArrayList<String>(requestedCiphers);
            skipped.removeAll(ciphers);
            log.debug(sm.getString("jsse.unsupported_ciphers", skipped));
        }
    }

    return ciphers.toArray(new String[ciphers.size()]);
}
 
Example 20
Project: incubator-netbeans   File: ScanStatement.java   Source Code and License Vote up 4 votes
public List<TreePathHandle> getUsedTypeVars() {
    List<TreePathHandle> ll = new ArrayList<TreePathHandle>(getTypeVarDefs());
    ll.retainAll(usedTypeVariables);
    return ll;
}