Example usage for java.util LinkedHashSet add

List of usage examples for java.util LinkedHashSet add

Introduction

In this page you can find the example usage for java.util LinkedHashSet add.

Prototype

boolean add(E e);

Source Link

Document

Adds the specified element to this set if it is not already present (optional operation).

Usage

From source file:Main.java

public static <ELEMENT> LinkedHashSet<ELEMENT> newLinkedHashSet(ELEMENT... elements) {
    final LinkedHashSet<ELEMENT> set = newLinkedHashSetSized(elements.length);
    for (ELEMENT element : elements) {
        set.add(element);
    }// w  ww.  j  a  va2  s . c  o  m
    return set;
}

From source file:Main.java

public static <T, V extends T> LinkedHashSet<T> createLinkedHashSet(V... args) {
    if (args == null || args.length == 0) {
        return new LinkedHashSet<T>();
    } else {//from w w  w .j a  v a 2 s. com
        LinkedHashSet<T> set = new LinkedHashSet<T>(args.length);

        for (V v : args) {
            set.add(v);
        }
        return set;
    }
}

From source file:Main.java

public static <T> LinkedHashSet<T> getDuplicates(final Iterable<T> iterable) {
    LinkedHashSet<T> duplicates = new LinkedHashSet<>();
    Set<T> dupeChecker = new LinkedHashSet<>();
    iterable.forEach((m) -> {//from  w  ww.  jav  a2s  .  c  o m
        if (!dupeChecker.add(m)) {
            duplicates.add(m);
        }
    });
    return duplicates;
}

From source file:org.loklak.android.data.AbstractIndexEntry.java

@SuppressWarnings("unchecked")
public static LinkedHashSet<String> parseArrayList(Object l) {
    assert l == null || l instanceof String || l instanceof String[] || l instanceof Collection<?>;
    if (l == null)
        return new LinkedHashSet<String>();
    if (l instanceof String) {
        LinkedHashSet<String> a = new LinkedHashSet<String>();
        a.add((String) l);
        return a;
    }//ww  w .  j  a v  a 2  s  .c o m
    if (l instanceof String[]) {
        LinkedHashSet<String> a = new LinkedHashSet<String>();
        for (String s : ((String[]) l))
            if (s != null)
                a.add(s);
        return a;
    }
    if (l instanceof LinkedHashSet<?>) {
        LinkedHashSet<String> a = new LinkedHashSet<String>();
        for (String s : (LinkedHashSet<String>) l)
            if (s != null)
                a.add(s);
        return a;
    }
    if (l instanceof JSONArray) {
        LinkedHashSet<String> a = new LinkedHashSet<String>();
        JSONArray la = (JSONArray) l;
        for (int i = 0; i < la.length(); i++) {
            try {
                String s = la.getString(i);
                if (s != null)
                    a.add(s);
            } catch (JSONException e) {
            }
        }
        return a;
    }
    LinkedHashSet<String> a = new LinkedHashSet<String>();
    for (Object s : ((Collection<?>) l))
        if (s != null)
            a.add((String) s);
    return a;
}

From source file:org.loklak.objects.AbstractIndexEntry.java

@SuppressWarnings("unchecked")
public static LinkedHashSet<String> parseArrayList(Object l) {
    assert l == null || l instanceof String || l instanceof String[] || l instanceof Collection<?>
            || l instanceof JSONArray : "unexpected class in parseArrayList:" + l.getClass().getName();
    if (l == null)
        return new LinkedHashSet<String>();
    if (l instanceof String) {
        LinkedHashSet<String> a = new LinkedHashSet<>();
        a.add((String) l);
        return a;
    }/*from w w w  . j  a  v  a  2 s . c o  m*/
    if (l instanceof String[]) {
        LinkedHashSet<String> a = new LinkedHashSet<>();
        for (String s : ((String[]) l))
            if (s != null)
                a.add(s);
        return a;
    }
    if (l instanceof LinkedHashSet<?>) {
        LinkedHashSet<String> a = new LinkedHashSet<>();
        for (String s : (LinkedHashSet<String>) l)
            if (s != null)
                a.add(s);
        return a;
    }
    if (l instanceof JSONArray) {
        LinkedHashSet<String> a = new LinkedHashSet<String>();
        JSONArray la = (JSONArray) l;
        for (int i = 0; i < la.length(); i++) {
            try {
                String s = la.getString(i);
                if (s != null)
                    a.add(s);
            } catch (JSONException e) {
            }
        }
        return a;
    }
    LinkedHashSet<String> a = new LinkedHashSet<>();
    for (Object s : ((Collection<?>) l))
        if (s != null)
            a.add((String) s);
    return a;
}

From source file:com.offbynull.coroutines.instrumenter.asm.TypeUtils.java

private static LinkedHashSet<String> flattenHierarchy(ClassInformationRepository repo, String type) {
    Validate.notNull(repo);/* w  ww.  java2  s. co  m*/
    Validate.notNull(type);

    LinkedHashSet<String> ret = new LinkedHashSet<>();

    String currentType = type;
    while (true) {
        ret.add(currentType);

        ClassInformation classHierarchy = repo.getInformation(currentType); // must return a result
        Validate.isTrue(classHierarchy != null, "No parent found for %s", currentType);
        if (classHierarchy.getSuperClassName() == null) {
            break;
        }

        for (String interfaceType : classHierarchy.getInterfaces()) {
            ret.add(interfaceType);
        }

        currentType = classHierarchy.getSuperClassName();
    }

    return ret;
}

From source file:mitm.common.util.CollectionUtils.java

/**
 * Converts the collection to a Set of Strings by calling org.apache.commons.lang.ObjectUtils on each item of items. 
 * If items is null an empty Set will be returned (i.e., a non-null Set instance is always returned). If an item is 
 * null the item will be "nullString".// w  w  w. j  a v  a 2 s  . c  o m
 * 
 * @param items
 * @return
 */
public static LinkedHashSet<String> toStringSet(Collection<?> items, String nullString) {
    int size = items != null ? items.size() : 0;

    LinkedHashSet<String> set = new LinkedHashSet<String>(size);

    if (items != null) {
        for (Object obj : items) {
            set.add(ObjectUtils.toString(obj, nullString));
        }
    }

    return set;
}

From source file:com.docd.purefm.utils.BookmarksHelper.java

@NonNull
private static Set<String> getStorageBookmarks() {
    final LinkedHashSet<String> storages = new LinkedHashSet<>();
    for (final StorageHelper.StorageVolume v : Environment.getStorageVolumes()) {
        storages.add(v.file.getAbsolutePath());
    }/*from  w ww . j a v a2  s .c om*/
    return storages;
}

From source file:nl.systemsgenetics.functionenrichmentoftransqtls.CorrelateSumChi2ToPathways.java

public static LinkedHashSet<String> loadSignificantTerms(File significantTermsFile) throws IOException {

    LinkedHashSet<String> significantTerms = new LinkedHashSet<>();

    BufferedReader reader = new BufferedReader(new FileReader(significantTermsFile));

    String line;/*  w  w  w.  jav  a 2  s.  c  om*/
    while ((line = reader.readLine()) != null) {
        significantTerms.add(line);
    }

    return significantTerms;

}

From source file:dhbw.clippinggorilla.external.twitter.TwitterUtils.java

/**
 * @param includedTagsSet/*from  ww w  .  j  a va 2s .co  m*/
 * @param excludedTagsSet
 * @param sinceDate
 * @return Gets Tweets for Profile
 */
public static LinkedHashSet<Article> getArticlesFromTwitter(Set<String> includedTagsSet,
        Set<String> excludedTagsSet, LocalDateTime sinceDate) {
    Query query = queryBuilder(includedTagsSet, sinceDate);
    LinkedHashSet<Article> result = new LinkedHashSet<>();
    QueryResult tweets = searchTweets(query);

    for (Status status : tweets.getTweets()) {
        result.add(fillArticle(status));
    }
    return result;
}