List of usage examples for java.util Set add
boolean add(E e);
From source file:com.thoughtworks.go.apiv4.agents.representers.UpdateRequestRepresenter.java
static String toCommaSeparatedString(JsonArray jsonArray) { if (jsonArray == null) { return null; }/*from w ww. j a v a 2s.c o m*/ final Set<String> list = new TreeSet<>(); for (JsonElement jsonElement : jsonArray) { list.add(jsonElement.getAsString()); } return String.join(",", list); }
From source file:Main.java
public static Set<Node> findElementsByTag(Set<Node> nodes, String tag) { final Set<Node> result = new HashSet<>(); for (Node child : nodes) { if (tag.equals(child.getNodeName())) { result.add(child); }//from w w w .jav a2 s . c om } return result; }
From source file:com.gistlabs.mechanize.document.html.JsoupDataUtil.java
/** Returns the all elements matching any of the given tags (case-insensitive). */ public static Elements findElementsByTag(Element element, String... tags) { List<Element> results = new ArrayList<Element>(); Set<String> tagSet = new HashSet<String>(); for (String tag : tags) tagSet.add(tag.toLowerCase()); filterElementsByTag(results, element, tagSet); return new Elements(results); }
From source file:graphs.Graphs.java
public static <V, E> String BreadthSearch(Graph<V, E> g) { StringBuilder b = new StringBuilder(); Queue<V> Qu = new LinkedList<V>(); Set<V> visited = new HashSet(); Set<V> found = new HashSet(); V start = (V) g.getVertices().toArray()[0]; Qu.add(start);// w w w . j ava2 s . c om found.add(start); while (!Qu.isEmpty()) { V vertex = Qu.remove(); for (V neighbor : g.getNeighbors(vertex)) { if (!found.contains(neighbor) && !visited.contains(neighbor)) { found.add(neighbor); Qu.add(neighbor); } } b.append(vertex.toString() + " "); visited.add(vertex); } return b.toString(); }
From source file:Main.java
public static Set<Integer> randomSetRange(int min, int max, int n) { Set<Integer> set = new HashSet<Integer>(); while (set.size() < n) { int num = (int) (Math.random() * (max - min)) + min; set.add(num); }//www .jav a 2 s . com return set; }
From source file:com.intuit.karate.http.apache.LoggingUtils.java
private static Collection<String> sortKeys(Header[] headers) { Set<String> keys = new TreeSet<>(); for (Header header : headers) { keys.add(header.getName()); }/*from www . j a v a2 s. c om*/ return keys; }
From source file:com.streamreduce.util.HashtagUtil.java
public static Set<String> getCriticalTags() { Set<String> critical = new HashSet<>(); critical.add("#critical"); return critical; }
From source file:de.tudarmstadt.ukp.wikipedia.util.GraphUtilities.java
public static Set<Integer> getRandomPageSubset(Iterable<Page> pages, int pResultSetSize) { Set<Integer> pageIDs = new HashSet<Integer>(); while (pages.iterator().hasNext()) { pageIDs.add(pages.iterator().next().getPageId()); }//from www . j a v a2s. co m return getRandomPageSubset(pageIDs, pResultSetSize); }
From source file:Main.java
public static Set<String> parseSeparetedStringSet(String inputString, String delim) { Set<String> ret = new TreeSet<String>(); String[] data = inputString.split(delim); for (String d : data) { ret.add(d.trim()); }/*from w ww .ja v a 2s . co m*/ return ret; }
From source file:StringUtil.java
/** * <p> Converts a string to a Set. Breaks the string to characters and store * each character in a Set./*from w w w. j a v a 2 s . co m*/ * * @param string the string to convert * @return a <code>Set</code> containing all characters in the text string parameter */ public static Set convertToSet(String string) { // Result hashset Set resultSet = new HashSet(); for (int i = 0; i < string.length(); i++) { resultSet.add(new Character(string.charAt(i))); } // Return result return resultSet; }