Example usage for java.util Set add

List of usage examples for java.util Set add

Introduction

In this page you can find the example usage for java.util Set 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 <T> Set<T> asSet(T... args) {
    Set<T> result = new HashSet<T>();
    if (args != null) {
        for (T arg : args) {
            result.add(arg);
        }/*from  w w w  . ja  v  a 2  s  .  c  o  m*/
    }
    return result;
}

From source file:Main.java

public static void setFaceUri(String faceIdToAdd, String faceUri, String personId, Context context) {
    SharedPreferences faceIdUriMap = context.getSharedPreferences("FaceIdUriMap", Context.MODE_PRIVATE);

    SharedPreferences.Editor faceIdUriMapEditor = faceIdUriMap.edit();
    faceIdUriMapEditor.putString(faceIdToAdd, faceUri);
    faceIdUriMapEditor.commit();//www  .  j  a  va  2 s.co  m

    Set<String> faceIds = getAllFaceIds(personId, context);
    Set<String> newFaceIds = new HashSet<>();
    for (String faceId : faceIds) {
        newFaceIds.add(faceId);
    }
    newFaceIds.add(faceIdToAdd);
    SharedPreferences faceIdSet = context.getSharedPreferences(personId + "FaceIdSet", Context.MODE_PRIVATE);
    SharedPreferences.Editor faceIdSetEditor = faceIdSet.edit();
    faceIdSetEditor.putStringSet("FaceIdSet", newFaceIds);
    faceIdSetEditor.commit();
}

From source file:Main.java

/**
 * /*from   w w w  .ja  v a 2 s  .c  o  m*/
 * Turns a column of the resultset's value into Set
 * 
 * @param results
 * @param key
 *          key to get the value from the result set
 * @return null if results is null
 */
public static Set<String> turnMapResultToSet(List<? extends Map<?, ?>> results, String key) {

    if (results == null)
        return null;

    Set<String> set = new HashSet<String>(results.size());
    for (Map<?, ?> map : results) {
        set.add((String) map.get(key));
    }
    return set;
}

From source file:Main.java

/**
 * Method convertNodelistToSet//from  w w  w  .j  a va 2s  .c  o  m
 *
 * @param xpathNodeSet
 * @return the set with the nodelist
 */
public static Set convertNodelistToSet(NodeList xpathNodeSet) {

    if (xpathNodeSet == null) {
        return new HashSet();
    }

    int length = xpathNodeSet.getLength();
    Set set = new HashSet(length);

    for (int i = 0; i < length; i++) {
        set.add(xpathNodeSet.item(i));
    }

    return set;
}

From source file:Main.java

/**
 * Method convertNodelistToSet/*from  w ww . jav  a2  s . c  o  m*/
 *
 * @param xpathNodeSet
 * @return the set with the nodelist
 */
public static Set<Node> convertNodelistToSet(NodeList xpathNodeSet) {

    if (xpathNodeSet == null) {
        return new HashSet<Node>();
    }

    int length = xpathNodeSet.getLength();
    Set<Node> set = new HashSet<Node>(length);

    for (int i = 0; i < length; i++) {
        set.add(xpathNodeSet.item(i));
    }

    return set;
}

From source file:co.turnus.analysis.util.AnalysisUtil.java

public static int[] linspacei(int min, int max, int points) {
    Set<Integer> values = new LinkedHashSet<Integer>();
    values.add(min);
    for (double d : linspaced(min, max, points)) {
        values.add((int) Math.floor(d));
    }/*w  w  w. j  a va2  s.  c o m*/
    values.add(max);
    return ArrayUtils.toPrimitive(values.toArray(new Integer[0]));
}

From source file:com.khubla.cbean.serializer.impl.SimpleFieldSerializer.java

private static Set<Class<?>> getWrapperTypes() {
    final Set<Class<?>> ret = new HashSet<Class<?>>();
    ret.add(Boolean.class);
    ret.add(Character.class);
    ret.add(Byte.class);
    ret.add(Short.class);
    ret.add(Integer.class);
    ret.add(Long.class);
    ret.add(Float.class);
    ret.add(Double.class);
    ret.add(Void.class);
    return ret;//from   w  w  w  . j  ava2  s . co m
}

From source file:Main.java

/**
 * Returns all objects in list1 that are not in list2
 *
 * @param <T> Type of items in the collection
 * @param list1 First collection//from w  ww  . j  ava  2  s . c  o m
 * @param list2 Second collection
 * @return The collection difference list1 - list2
 */
public static <T> Set<T> diffAsSet(Collection<T> list1, Collection<T> list2) {
    Set<T> diff = new HashSet<T>();
    for (T t : list1) {
        if (!list2.contains(t)) {
            diff.add(t);
        }
    }
    return diff;
}

From source file:Main.java

/**
 * Ensures that all elements of the given set can be cast to a desired type.
 * /* ww  w .j a  v a  2s. co m*/
 * @param list the set to check
 * @param type the desired type
 * @return a set of the desired type
 * @throws ClassCastException if an element cannot be cast to the desired type
 */
@SuppressWarnings("unchecked")
public static <E> Set<E> checkSet(Set<?> set, Class<E> type) {
    if (DEBUG) {
        Set<E> copy = new HashSet<E>();
        for (Object element : set) {
            copy.add(type.cast(element));
        }
        return copy;
    }
    return (Set<E>) set;
}

From source file:Main.java

public static <E> Set<E> intersect(Set<E> a, Set<E> b) {
    Set<E> intersect = new HashSet<>();
    for (E entryA : a) {
        if (b.contains(entryA)) {
            intersect.add(entryA);
        }//  w ww.ja v a2  s  .  c  o  m
    }
    for (E entryB : b) {
        if (a.contains(entryB)) {
            intersect.add(entryB);
        }
    }
    return intersect;
}