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.pedra.storefront.util.MetaSanitizerUtil.java

/**
 * Takes a List of KeywordModels and returns a comma separated list of keywords as String.
 * //from   w w  w  .j av  a 2  s .  co m
 * @param keywords
 *           List of KeywordModel objects
 * @return String of comma separated keywords
 */
public static String sanitizeKeywords(final List<KeywordModel> keywords) {
    if (keywords != null && !keywords.isEmpty()) {
        // Remove duplicates
        final Set<String> keywordSet = new HashSet<String>(keywords.size());
        for (final KeywordModel kw : keywords) {
            keywordSet.add(kw.getKeyword());
        }

        // Format keywords, join with comma
        final StringBuilder stringBuilder = new StringBuilder();
        for (final String kw : keywordSet) {
            stringBuilder.append(kw).append(',');
        }
        if (stringBuilder.length() > 0) {
            // Remove last comma
            return stringBuilder.substring(0, stringBuilder.length() - 1);
        }
    }
    return "";
}

From source file:com.taobao.common.tedis.support.matcher.MatcherManager.java

private static Set<String> normalize(String str) {
    Pattern pattern = Pattern.compile("([\u4e00-\u9fa5a-z0-9]+)");
    Matcher matcher = pattern.matcher(str.toLowerCase());
    Set<String> result = new HashSet<String>();
    while (matcher.find()) {
        result.add(matcher.group());
    }//from   w ww . j  a  v a 2s. co  m
    return result;
}

From source file:com.epam.cme.storefront.util.MetaSanitizerUtil.java

/**
 * Takes a List of KeywordModels and returns a comma separated list of keywords as String.
 * // www  .  j  a v  a 2  s.c  o  m
 * @param keywords
 *            List of KeywordModel objects
 * @return String of comma separated keywords
 */
public static String sanitizeKeywords(final List<KeywordModel> keywords) {
    if (keywords != null && !keywords.isEmpty()) {
        // Remove duplicates
        final Set<String> keywordSet = new HashSet<String>(keywords.size());
        for (final KeywordModel kw : keywords) {
            keywordSet.add(kw.getKeyword());
        }

        // Format keywords, join with comma
        final StringBuilder sb = new StringBuilder();
        for (final String kw : keywordSet) {
            sb.append(kw).append(',');
        }
        if (sb.length() > 0) {
            // Remove last comma
            return sb.substring(0, sb.length() - 1);
        }
    }
    return "";
}

From source file:com.intuit.tank.script.ScriptStepFactory.java

public static ScriptStep createThinkTime(String minTime, String maxTime) {
    ScriptStep think = new ScriptStep();
    think.setType(ScriptConstants.THINK_TIME);

    RequestData minRD = new RequestData();
    minRD.setType(ScriptConstants.THINK_TIME);
    minRD.setKey(ScriptConstants.MIN_TIME);
    minRD.setValue(minTime);/*from ww  w. j  av a  2  s  . c  o m*/

    RequestData maxRD = new RequestData();
    maxRD.setType(ScriptConstants.THINK_TIME);
    maxRD.setKey(ScriptConstants.MAX_TIME);
    maxRD.setValue(maxTime);

    Set<RequestData> ds = new HashSet<RequestData>();
    ds.add(minRD);
    ds.add(maxRD);
    think.setData(ds);
    think.setComments("ThinkTime " + minRD.getValue() + "-" + maxRD.getValue());

    return think;
}

From source file:dumpsection.util.Util.java

public static Set<Integer> stringArrayToUnsignedIntegerSet(String[] src, int radix) {
    Set<Integer> x = new HashSet<>();
    List<String> ls = new ArrayList<>();
    ls.addAll(Arrays.asList(src));
    for (String s : ls) {
        try {/*from   w w w .  j a v a2  s. co m*/
            x.add(Integer.parseUnsignedInt(s, radix));
        } catch (NumberFormatException e) {
            throw e;
        }
    }
    return Collections.unmodifiableSet(x);
}

From source file:org.eel.kitchen.jsonschema.ref.JsonPointerTest.java

private static Iterator<Object[]> nodeToDataProvider(final JsonNode node) {
    final Map<String, JsonNode> map = JacksonUtils.nodeToMap(node);

    final Set<Object[]> set = Sets.newHashSet();

    for (final Map.Entry<String, JsonNode> entry : map.entrySet())
        set.add(new Object[] { entry.getKey(), entry.getValue() });

    return set.iterator();
}

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

public static double[] linspaced(double min, double max, int points) {
    Set<Double> values = new LinkedHashSet<Double>();
    double current = min;
    double delta = (max - min) / ((double) points - 1);
    do {/*from w ww .  ja  v  a  2  s. co m*/
        values.add(current);
        current += delta;

    } while (current < (max + delta / 2));
    return ArrayUtils.toPrimitive(values.toArray(new Double[0]));
}

From source file:gobblin.util.DatasetFilterUtils.java

public static Set<String> filter(Set<String> topics, List<Pattern> blacklist, List<Pattern> whitelist) {
    Set<String> result = Sets.newHashSet();
    for (String topic : topics) {
        if (survived(topic, blacklist, whitelist)) {
            result.add(topic);
        }// w w w.  j  av a 2 s  . c  o  m
    }
    return result;
}

From source file:Main.java

/**
 * Converts an array of chars to a Set of Characters.
 *
 * @param array the contents of the new Set
 * @return a Set containing the elements in the array
 *///w  w w .  j  av a2s.  c o  m
public static Set<Character> arrayToSet(char... array) {
    Set<Character> toReturn;

    if (array == null) {
        return new HashSet<Character>();
    }
    toReturn = new HashSet<Character>(array.length);
    for (char c : array) {
        toReturn.add(c);
    }
    return toReturn;
}

From source file:ch.systemsx.cisd.openbis.generic.server.business.bo.common.EntityListingTestUtils.java

private static <T extends CodeRecord> Set<Long> extractVOIds(List<T> items) {
    Set<Long> ids = new HashSet<Long>();
    for (T item : items) {
        ids.add(item.id);
    }//w ww.j  a  v a 2  s  . c  o  m
    return ids;
}