Example usage for java.util Set contains

List of usage examples for java.util Set contains

Introduction

In this page you can find the example usage for java.util Set contains.

Prototype

boolean contains(Object o);

Source Link

Document

Returns true if this set contains the specified element.

Usage

From source file:com.github.checkstyle.NotesBuilder.java

/**
 * Finds authors of the commits./*from   ww w . j  av a2  s.c om*/
 * @param commits current issue commits.
 * @return a list of authors who work on the current issue.
 */
private static Set<String> findCommitAuthors(Set<RevCommit> commits) {
    final Set<String> commitAuthors = new HashSet<>();
    for (RevCommit commit : commits) {
        final String author = commit.getAuthorIdent().getName();
        if (!commitAuthors.contains(author)) {
            commitAuthors.add(author);
        }
    }
    return commitAuthors;
}

From source file:io.fabric8.forge.rest.dto.UICommands.java

/**
 * Returns true if the given <code>javaType</code> class name should be considered a JSON DTO to return to the UI
 *///from  w ww.ja  va  2s  .  c  om
protected static boolean isJsonDTO(String javaType) {
    Set<String> jsonJavatypes = new HashSet<>(Arrays.asList("org.apache.maven.archetype.catalog.Archetype"));
    return javaType != null && jsonJavatypes.contains(javaType);
}

From source file:fr.mixit.android.io.JSONHandler.java

/**
 * Returns those id's from a {@link android.net.Uri} that were not found in a given set.
 *//*  w  w w .  j a  v a 2 s.  co m*/
protected static HashSet<String> getLostIds(Set<String> ids, Uri uri, String[] projection, int idColumnIndex,
        ContentResolver resolver) {
    final HashSet<String> lostIds = Sets.newHashSet();

    final Cursor cursor = resolver.query(uri, projection, null, null, null);
    try {
        while (cursor.moveToNext()) {
            final String id = cursor.getString(idColumnIndex);
            if (!ids.contains(id)) {
                lostIds.add(id);
            }
        }
    } finally {
        cursor.close();
    }

    if (!lostIds.isEmpty()) {
        Log.d(TAG, "Found " + lostIds.size() + " for " + uri.toString() + " that need to be removed.");
    }

    return lostIds;
}

From source file:org.eclipse.virgo.ide.jdt.internal.core.util.ClasspathUtils.java

/**
 * Updates the class path container on the given <code>javaProject</code>.
 *//*from   ww w.  j a v a2 s.c  om*/
public static IStatus updateClasspathContainer(IJavaProject javaProject,
        Set<IBundleManifestChangeListener.Type> types, IProgressMonitor monitor) {
    try {

        if (monitor.isCanceled()) {
            return Status.CANCEL_STATUS;
        }

        // only update if something relevant happened
        if (types.contains(IBundleManifestChangeListener.Type.IMPORT_BUNDLE)
                || types.contains(IBundleManifestChangeListener.Type.IMPORT_LIBRARY)
                || types.contains(IBundleManifestChangeListener.Type.IMPORT_PACKAGE)
                || types.contains(IBundleManifestChangeListener.Type.REQUIRE_BUNDLE)) {

            IClasspathContainer oldContainer = ClasspathUtils.getClasspathContainer(javaProject);
            if (oldContainer != null) {
                ServerClasspathContainer container = new ServerClasspathContainer(javaProject);

                container.refreshClasspathEntries();
                if (!Arrays.deepEquals(oldContainer.getClasspathEntries(), container.getClasspathEntries())) {
                    JavaCore.setClasspathContainer(ServerClasspathContainer.CLASSPATH_CONTAINER_PATH,
                            new IJavaProject[] { javaProject }, new IClasspathContainer[] { container },
                            monitor);
                }
            }
        }

        if (types.contains(IBundleManifestChangeListener.Type.EXPORT_PACKAGE)) {
            // Always try to update the depending projects because MANIFEST might have changed
            // without changes to the project's own class path
            updateClasspathContainerForDependingBundles(javaProject);
        }

    } catch (JavaModelException e) {
        JdtCorePlugin.log(e);
    }
    return Status.OK_STATUS;
}

From source file:br.com.caelum.vraptor.core.BaseComponents.java

private static void registerIfClassPresent(Set<Class<? extends Converter<?>>> components, String className,
        Class<? extends Converter<?>>... types) {
    if (components.contains(types[0])) {
        return;//from   w ww  . j a  v a 2 s . c  o m
    }
    try {
        Class.forName(className);
        for (Class<? extends Converter<?>> type : types) {
            components.add(type);
        }
    } catch (ClassNotFoundException e) {
        /*ok, don't register*/ }
}

From source file:edu.umd.umiacs.clip.tools.scor.WordVectorUtils.java

public static void enStem(String input, String output) {
    Set<String> allWords = new HashSet<>();
    List<String> lines = new ArrayList<>();
    lines(input).map(line -> line.split(" ")).filter(fields -> fields.length > 2)
            .map(fields -> Pair.of(fields[0].equals("</s>") ? fields[0] : LuceneUtils.enStem(fields[0]),
                    Stream.of(fields).skip(1).collect(joining(" "))))
            .filter(pair -> !pair.getLeft().isEmpty() && !pair.getLeft().contains(" ")
                    && !allWords.contains(pair.getLeft()))
            .peek(pair -> allWords.add(pair.getLeft())).map(pair -> pair.getLeft() + " " + pair.getRight())
            .forEach(lines::add);/*  w  w w  . ja v  a2  s  .c  o m*/
    lines.add(0, lines.size() + " " + (lines.get(0).split(" ").length - 1));
    write(output, lines, REMOVE_OLD_FILE);
}

From source file:mitm.common.mail.EmailAddressUtils.java

/**
 * Returns true of search is contained in emails. The emails are canonicalized and checked
 * for validity before being compared./*from   w  w  w  .  j a  v a2 s .com*/
 */
public static boolean containsEmail(String search, Collection<String> emails) {
    String filteredSearch = canonicalizeAndValidate(search, true);

    if (filteredSearch == null || emails == null) {
        return false;
    }

    Set<String> filteredEmails = canonicalizeAndValidate(emails, true);

    return filteredEmails.contains(filteredSearch);
}

From source file:de.tudarmstadt.ukp.dkpro.tc.features.ngram.util.NGramUtils.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/*  w w w .  jav  a 2 s .  c o m*/
 * 
 * @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.
 */
public static boolean passesNgramFilter(List<String> tokenList, Set<String> stopwords,
        boolean filterPartialMatches) {
    List<String> filteredList = new ArrayList<String>();
    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:Main.java

public static String removeArgumentsFromUrl(String url, Set<String> keySet) {
    String[] splittedUrl = url.split("\\?");

    String baseUrl = splittedUrl[0];
    String argsString = "";
    if (splittedUrl.length > 1) {
        argsString = splittedUrl[1];/*  w ww.  j  a  v  a 2  s .co m*/
        String[] argsArray = argsString.split("&");
        ArrayList<String> cleanedArgList = new ArrayList<String>();
        for (String arg : argsArray) {
            String argKey = arg.split("=")[0];
            if (!keySet.contains(argKey)) {
                cleanedArgList.add(arg);
            } else {
                // this is one of the arguments we'd like to remove
            }
        }

        boolean firstArg = true;
        argsString = "";
        for (String cleanedArg : cleanedArgList) {
            // ok, so we have some arguments left. add these again to url
            if (!firstArg) {
                argsString += "&";
            }
            argsString += cleanedArg;
            firstArg = false;
        }
    }
    return baseUrl + (argsString.length() > 0 ? "?" + argsString : "");

}

From source file:de.tudarmstadt.ukp.dkpro.keyphrases.core.evaluator.util.EvaluatorUtils.java

/**
 * Sorts the keyphrases by score.//from w  w  w .  j a v a  2 s . co m
 * Filters duplicate keyphrases.
 * The keyphrase with the higher score is kept.
 *
 * @param keyphrasesCollection A list over keyphrases.
 * @param toLowercase If gold keys should be lowercased or not.
 *
 * @return A list of unique keyphrases in order of descending scores.
 */
public static List<Keyphrase> filterAndSortKeyphrases(Collection<Keyphrase> keyphrasesCollection,
        boolean toLowercase) {

    List<Keyphrase> keyphrases = new ArrayList<Keyphrase>(keyphrasesCollection);

    // sort the keyphrases
    Collections.sort(keyphrases, new KeyphraseScoreComparator());

    // filter the keyphrases
    List<Keyphrase> filteredKeyphrases = new ArrayList<Keyphrase>();
    Set<String> uniqueKeyphrases = new HashSet<String>();
    for (Keyphrase keyphrase : keyphrases) {
        String keyphraseString = toLowercase ? keyphrase.getKeyphrase().toLowerCase()
                : keyphrase.getKeyphrase();

        if (keyphraseString.length() == 0) {
            continue;
        }

        if (!uniqueKeyphrases.contains(keyphraseString)) {
            uniqueKeyphrases.add(keyphraseString);
            filteredKeyphrases.add(keyphrase);
        }
    }

    return filteredKeyphrases;
}