List of usage examples for java.util Set contains
boolean contains(Object o);
From source file:com.vsthost.rnd.jdeoptim.utils.Utils.java
/** * Returns random elements from the set. * * @param set The set to be chosen from. * @param n The number of elements to be returned. * @param exclude Elements to be excluded. * @param randomGenerator The random number generator. * @return Random elements./*from ww w . jav a2s. co m*/ */ public static int[] pickRandom(int[] set, int n, int[] exclude, RandomGenerator randomGenerator) { // Create a set from excluded: final Set<Integer> toExclude = new HashSet<>(); Arrays.stream(exclude).forEach(toExclude::add); // Create set out of elements: int[] newSet = Arrays.stream(set).filter(e -> !toExclude.contains(e)).toArray(); // Shuffle the set: MathArrays.shuffle(newSet, randomGenerator); // Get n elements and return: return Arrays.copyOf(newSet, n); }
From source file:jenkins.AgentProtocolTest.java
public static void assertProtocols(Jenkins jenkins, boolean shouldBeEnabled, @CheckForNull String why, String... protocolNames) throws AssertionError { Set<String> agentProtocols = jenkins.getAgentProtocols(); List<String> failedChecks = new ArrayList<>(); for (String protocol : protocolNames) { if (shouldBeEnabled && !(agentProtocols.contains(protocol))) { failedChecks.add(protocol);/* www . j a va 2 s . c om*/ } if (!shouldBeEnabled && agentProtocols.contains(protocol)) { failedChecks.add(protocol); } } if (!failedChecks.isEmpty()) { String message = String.format("Protocol(s) are not %s: %s. %sEnabled protocols: %s", shouldBeEnabled ? "enabled" : "disabled", StringUtils.join(failedChecks, ','), why != null ? "Reason: " + why + ". " : "", StringUtils.join(agentProtocols, ',')); fail(message); } }
From source file:edu.jhu.hlt.parma.inference.transducers.WikipediaAliasReader.java
public static Set<String> find_cluster(String type, List<Set<String>> clusters) { for (Set<String> cluster : clusters) { if (cluster.contains(type)) { return cluster; }//from w ww .ja v a 2s .co m } // Should never get here return null; }
From source file:de.tudarmstadt.ukp.dkpro.argumentation.sequence.feature.lexical.LemmaNGramUtils.java
/** * An ngram (represented by the list of tokens) does not pass the stopword filter: * a) filterPartialMatches=true - if it contains any stopwords * b) filterPartialMatches=false - if it entirely consists of stopwords * * @param tokenList The list of tokens in a single ngram * @param stopwords The set of stopwords used for filtering * @param filterPartialMatches Whether ngrams where only parts are stopwords should also be filtered. For example, "United States of America" would be filtered, as it contains the stopword "of". * @return Whether the ngram (represented by the list of tokens) passes the stopword filter or not. *///from w w w . ja v a 2 s . c o m public static boolean passesNgramFilter(List<String> tokenList, Set<String> stopwords, boolean filterPartialMatches) { List<String> filteredList = new ArrayList<>(); for (String ngram : tokenList) { if (!stopwords.contains(ngram)) { filteredList.add(ngram); } } if (filterPartialMatches) { return filteredList.size() == tokenList.size(); } else { return filteredList.size() != 0; } }
From source file:com.xpn.xwiki.internal.store.hibernate.query.HqlQueryUtils.java
/** * @param column the {@link Column} to check * @return true if the passed {@link Column} is allowed *//*from www.ja va2s . com*/ private static boolean isColumnAllowed(Column column, Map<String, String> tables) { Set<String> fields = ALLOWED_FIELDS.get(getTableName(column.getTable(), tables)); return fields != null && fields.contains(column.getColumnName()); }
From source file:br.com.suricattus.surispring.spring.security.util.SecurityUtil.java
/** * Method that checks if <b>none</b> of the given roles is hold by the user. * Returns <code>true</code> if no roles are given, or none of the given * roles match the users roles. Returns <code>false</code> on the first * matching role./* w w w . j a v a2 s .c om*/ * * @param notGrantedRoles * a comma seperated list of roles * @return true if none of the given roles is granted to the current user, * false otherwise */ public static boolean hasNoRole(final String notGrantedRoles) { Set<String> parsedAuthorities = parseAuthorities(notGrantedRoles); if (parsedAuthorities.isEmpty()) return true; Set<String> userAuthorities = getUserAuthorities(); for (String notGrantedAuthority : parsedAuthorities) { if (userAuthorities.contains(notGrantedAuthority)) return false; } return true; }
From source file:io.wcm.caconfig.extensions.references.impl.ConfigurationReferenceProvider.java
/** * Build reference display name from path with: * - translating configuration names to labels * - omitting configuration bucket names * - insert additional spaces so long paths may wrap on multiple lines *//*from w w w . j a v a 2 s . c om*/ private static String getReferenceName(Page configPage, Map<String, ConfigurationMetadata> configurationMetadatas, Set<String> configurationBuckets) { List<String> pathParts = Arrays.asList(StringUtils.split(configPage.getPath(), "/")); return pathParts.stream().filter(name -> !configurationBuckets.contains(name)).map(name -> { ConfigurationMetadata configMetadata = configurationMetadatas.get(name); if (configMetadata != null && configMetadata.getLabel() != null) { return configMetadata.getLabel(); } else { return name; } }).collect(Collectors.joining(" / ")); }
From source file:br.com.suricattus.surispring.spring.security.util.SecurityUtil.java
/** * Method that checks if the user holds <b>all</b> of the given roles. * Returns <code>true</code>, iff the user holds all roles, * <code>false</code> if no roles are given or the first non-matching role * is found/*from w ww . j a v a 2 s . c o m*/ * * @param requiredRoles a comma seperated list of roles * @return true if all of the given roles are granted to the current user, * false otherwise or if no roles are specified at all. */ public static boolean hasAllRoles(final String requiredRoles) { Set<String> requiredAuthorities = parseAuthorities(requiredRoles); if (requiredAuthorities.isEmpty()) return false; Set<String> userAuthorities = getUserAuthorities(); for (String requiredAuthority : requiredAuthorities) { if (!userAuthorities.contains(requiredAuthority)) return false; } return true; }
From source file:net.openid.appauth.AdditionalParamsProcessor.java
static Map<String, String> extractAdditionalParams(JSONObject json, Set<String> builtInParams) throws JSONException { Map<String, String> additionalParams = new LinkedHashMap<>(); Iterator<String> keysIter = json.keys(); while (keysIter.hasNext()) { String key = keysIter.next(); if (!builtInParams.contains(key)) { additionalParams.put(key, json.get(key).toString()); }//w w w . j a v a2 s. c o m } return additionalParams; }
From source file:ai.grakn.graql.internal.gremlin.GraqlTraversal.java
private static double fragmentCost(Fragment fragment, double previousCost, Set<String> names) { if (names.contains(fragment.getStart())) { return fragment.fragmentCost(previousCost); } else {/* ww w . j ava2 s .c o m*/ // Restart traversal, meaning we are navigating from all vertices // The constant '1' cost is to discourage constant restarting, even when indexed return fragment.fragmentCost(NUM_VERTICES_ESTIMATE) * previousCost + 1; } }