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:com.intuit.tank.script.ScriptStepFactory.java

public static ScriptStep createLogic(String name, String script) {
    ScriptStep ret = new ScriptStep();
    ret.setType(ScriptConstants.LOGIC);//  w  ww.j av a 2 s  . c o  m
    ret.setComments("Logic Step: " + name);
    ret.setName(name);
    RequestData data = new RequestData();
    data.setType(ScriptConstants.LOGIC);
    data.setKey(ScriptConstants.SCRIPT);
    data.setValue(script);
    Set<RequestData> ds = new HashSet<RequestData>();
    ds.add(data);
    ret.setData(ds);
    return ret;
}

From source file:com.opengamma.integration.viewer.status.AggregateType.java

private static boolean hasDepulicateChar(String aggregateStrType) {
    char[] aggregateTypeChars = aggregateStrType.toCharArray();
    Set<Character> uniqueChars = Sets.newHashSet();
    for (Character character : aggregateTypeChars) {
        uniqueChars.add(character);
    }// w w w  .j a  v  a 2s. c o m
    return uniqueChars.size() != VALID_AGGRAGATION_CHARS.size();
}

From source file:Main.java

/**
 * Convert a String to a set of characters.
 * @param str The string to convert//w ww .  ja  v a  2 s.c  o  m
 * @return A set containing the characters in str. A empty set
 *    is returned if str is null.
 */
public static Set<Character> strToSet(String str) {
    Set<Character> set;

    if (str == null)
        return new HashSet<Character>();
    set = new HashSet<Character>(str.length());
    for (int i = 0; i < str.length(); i++)
        set.add(str.charAt(i));
    return set;
}

From source file:Main.java

public static <T> Set<T> getIntersectionValues(Collection<? extends T> colection1,
        Collection<? extends T> colection2) {

    Set<T> ret = new HashSet<T>();
    if (colection1 == null || colection2 == null)
        return ret;

    for (T value : colection1) {
        if (colection2.contains(value))
            ret.add(value);
    }/*  ww w . java2s  .  c o m*/
    return ret;
}

From source file:Main.java

public static Set<Node> getChildrenElements(Node node) {
    final Set<Node> result = new LinkedHashSet<>();

    for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
        if (child.getNodeType() != Node.TEXT_NODE) {
            result.add(child);
        }//from  w ww.j ava  2  s .  c  o m
    }

    return result;
}

From source file:com.linkedin.paldb.impl.GenerateTestData.java

public static Integer[] generateRandomIntKeys(int count, int range, long seed) {
    Random random = new Random(seed);
    Set<Integer> set = new HashSet<Integer>(count);
    while (set.size() < count) {
        set.add(random.nextInt(range));
    }//www . j ava  2s  .  c o m
    return set.toArray(new Integer[0]);
}

From source file:Main.java

public static <T> Set<? extends T> interSubtype(final Set<? extends T> a, final Set<? extends T> b) {
    if (a == b)//from  www .  j  av a  2 s  .c o m
        return a;
    else if (a == null)
        return b;
    else if (b == null)
        return a;
    else if (a.size() > b.size()) {
        return interSubtype(b, a);
    }

    final Set<T> res = new HashSet<T>();
    for (final T item : a) {
        if (b.contains(item))
            res.add(item);
    }
    return res;
}

From source file:de.tudarmstadt.ukp.dkpro.tc.features.ngram.meta.ChunkTripleMetaCollector.java

private static String getChunkString(JCas jcas, List<? extends Chunk> chunkList) {
    String chunkString = "";
    if (chunkList.size() > 0) {
        Chunk chunk = chunkList.get(0);//from ww  w  .  j  av  a  2s .co  m

        // get rightmost lemma in chunk
        List<Lemma> lemmas = JCasUtil.selectCovered(jcas, Lemma.class, chunk);

        Set<String> lemmaStrings = new HashSet<String>();
        for (Lemma lemma : lemmas) {
            lemmaStrings.add(lemma.getValue());
        }
        chunkString = StringUtils.join(lemmaStrings, "_");

        // if (lemmas.size() > 0) {
        // chunkString = lemmas.get(lemmas.size()-1).getCoveredText();
        // }
    }
    return chunkString;
}

From source file:eu.itesla_project.modules.topo.PrintSubstationTopoHistoryTool.java

private static Map<Set<TopoBus>, AtomicInteger> translate(Map<Set<TopoBus>, AtomicInteger> topos,
        ShortIdDictionary dict) {/*  w  ww  .  ja  v  a 2 s. c o  m*/
    Map<Set<TopoBus>, AtomicInteger> topos2 = new LinkedHashMap<>();
    for (Map.Entry<Set<TopoBus>, AtomicInteger> e : topos.entrySet()) {
        Set<TopoBus> topo = e.getKey();
        AtomicInteger count = e.getValue();
        Set<TopoBus> topo2 = new HashSet<>();
        for (TopoBus b : topo) {
            topo2.add(new TopoBus(
                    b.getEquipments().stream().map(s -> dict.getShortId(s)).collect(Collectors.toSet()),
                    b.getSubstation()));
        }
        topos2.put(topo2, count);
    }
    return topos2;
}

From source file:Main.java

/**
 * Produce a new set/*from w w  w .j a  va2 s.co  m*/
 * @param <T>
 * @param set1
 * @param set2
 * @return 
 */
public static <T> Set<T> intersect(Set<T> set1, Collection<T> set2) {
    Set<T> intersection = new HashSet<>(set1.size() * 4 / 3);
    for (T e : set2) {
        if (set1.contains(e)) {
            intersection.add(e);
        }
    }
    return intersection;
}