List of usage examples for java.util HashSet add
public boolean add(E e)
From source file:com.facebook.TestUtils.java
private static boolean areEqual(final JSONObject expected, final JSONObject actual) { // JSONObject.equals does not do an order-independent comparison, so let's roll our own :( if (expected == actual) { return true; }/* ww w.j av a 2 s . co m*/ if ((expected == null) || (actual == null)) { return false; } final Iterator<String> expectedKeysIterator = expected.keys(); final HashSet<String> expectedKeys = new HashSet<String>(); while (expectedKeysIterator.hasNext()) { expectedKeys.add(expectedKeysIterator.next()); } final Iterator<String> actualKeysIterator = actual.keys(); while (actualKeysIterator.hasNext()) { final String key = actualKeysIterator.next(); if (!areEqual(expected.opt(key), actual.opt(key))) { return false; } expectedKeys.remove(key); } return expectedKeys.size() == 0; }
From source file:Main.java
/** * Returns a HashSet of values in a HashMap that match the specified Predicate. * @param map the HashMap to check against * @param condition the Predicate to check * @param <K> the type of the Key in the HashMap * @param <V> the type of the Value in the HashMap * @return a HashSet of values matching the predicate, empty HashSet if no results found * @throws IllegalArgumentException if HashMap or Predicate is null */// www. ja v a 2 s . c o m public static <K, V> HashSet<V> getValuesInHashMap(final HashMap<K, V> map, final Predicate<V> condition) { final HashSet<V> matchingValues = new HashSet<>(); if (map == null) throw new IllegalArgumentException("HashMap cannot be null!"); if (condition == null) throw new IllegalArgumentException("Predicate cannot be null!"); map.forEach((key, value) -> { if (condition.test(value)) matchingValues.add(value); }); return matchingValues; }
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.PushProjectDownRule.java
private static boolean pushNeededProjections(HashSet<LogicalVariable> toPush, Mutable<ILogicalOperator> opRef, IOptimizationContext context, ILogicalOperator initialOp) throws AlgebricksException { HashSet<LogicalVariable> allP = new HashSet<LogicalVariable>(); AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); VariableUtilities.getLiveVariables(op, allP); HashSet<LogicalVariable> toProject = new HashSet<LogicalVariable>(); for (LogicalVariable v : toPush) { if (allP.contains(v)) { toProject.add(v); }/*from w ww . j av a 2 s.c o m*/ } if (toProject.equals(allP)) { // projection would be redundant, since we would project everything // but we can try with the children boolean push = false; if (pushThroughOp(toProject, opRef, initialOp, context).first) { push = true; } return push; } else { return pushAllProjectionsOnTopOf(toProject, opRef, context, initialOp); } }
From source file:edu.isistan.carcha.util.Utils.java
/** * Extract the T annotation as a String list and remove duplicates. * * @param <T> the generic type/* w w w . j ava2 s . c o m*/ * @param filename the filename * @param tsd the TypeSystems * @param type the type * @return the string list of coveredtext by the T annotations without duplicates * @throws UIMAException the uIMA exception * @throws IOException Signals that an I/O exception has occurred. */ public static <T extends Annotation> List<String> extractCoveredTextAnnotations(String filename, final Class<T> type) throws UIMAException, IOException { JCas jCas = JCasFactory.createJCas(filename, CARCHA_TYPE_SYSTEM); List<String> ret = new ArrayList<String>(); HashSet<String> hs = new HashSet<String>(); for (Annotation c : JCasUtil.select(jCas, type)) { hs.add(c.getCoveredText()); } ret.addAll(hs); return ret; }
From source file:gemlite.core.api.logic.LogicServices.java
/*** * //from w w w .j ava 2s .c om * @param regionName * @param beanName * @param userArgs * @param simpleFilter * @return */ public final static RemoteResult createRequestWithFilter(String regionName, String beanName, Object userArgs, Object simpleFilter) { HashSet<Object> set = null; if (simpleFilter != null) { set = new HashSet<>(); set.add(simpleFilter); } return createRequestWithFilter(regionName, beanName, userArgs, set); }
From source file:gov.nih.nci.caintegrator.application.lists.ajax.CommonListFunctions.java
public static String createGenericListWithSession(ListType type, ListSubType listSubType, List<String> list, String name, ListValidator lv, HttpSession session) { //no duplicates HashSet<String> h = new HashSet<String>(); for (int i = 0; i < list.size(); i++) h.add(list.get(i).trim()); List<String> cleanList = new ArrayList<String>(); for (String n : h) { cleanList.add(n);// w ww. ja v a 2s .c om } String success = "fail"; ListManager um = ListManager.getInstance(); try { UserList mylist = um.createList(type, name, cleanList, lv); if (listSubType != null) { mylist.setListSubType(listSubType); mylist.setListOrigin(ListOrigin.Custom); } else { mylist.setListOrigin(ListOrigin.Custom); } UserListBeanHelper ulbh = new UserListBeanHelper(session); ulbh.addList(mylist); success = "pass"; } catch (Exception e) { } return success; }
From source file:gov.nih.nci.caintegrator.application.lists.ajax.CommonListFunctions.java
public static String createGenericList(ListType type, List<String> list, String name, ListValidator lv) { //no duplicates HashSet<String> h = new HashSet<String>(); for (int i = 0; i < list.size(); i++) h.add(list.get(i).trim()); List<String> cleanList = new ArrayList<String>(); for (String n : h) { cleanList.add(n);//w w w. j a va2 s. c om } String success = "fail"; ListManager um = ListManager.getInstance(); try { UserList mylist = um.createList(type, name, cleanList, lv); //set the sub-type to custom mylist.setListOrigin(ListOrigin.Custom); //only works thru DWR UserListBeanHelper ulbh = new UserListBeanHelper(); if (ulbh != null) { ulbh.addList(mylist); success = "pass"; } } catch (Exception e) { // TODO: handle exception } return success; }
From source file:gov.nih.nci.caintegrator.application.lists.ajax.CommonListFunctions.java
public static String createGenericList(ListType type, ListSubType listSubType, List<String> list, String name, ListValidator lv) {/*from ww w .j av a 2s. c om*/ //no duplicates HashSet<String> h = new HashSet<String>(); for (int i = 0; i < list.size(); i++) h.add(list.get(i).trim()); List<String> cleanList = new ArrayList<String>(); for (String n : h) { cleanList.add(n); } String success = "fail"; ListManager um = ListManager.getInstance(); try { UserList mylist = um.createList(type, name, cleanList, lv); if (listSubType != null) { mylist.setListSubType(listSubType); mylist.setListOrigin(ListOrigin.Custom); } else { mylist.setListOrigin(ListOrigin.Custom); } //only works thru DWR UserListBeanHelper ulbh = new UserListBeanHelper(); if (ulbh != null) { ulbh.addList(mylist); success = "pass"; } } catch (Exception e) { } return success; }
From source file:com.netcrest.pado.tools.pado.util.PadoShellUtil.java
/** * Returns an array of full paths determined by parsing all paths arguments * found in the specified commandLine. Duplicates are ignored. * /*from w ww . j a v a2 s.c o m*/ * @param padoShell * PadoShell instance * @param commandLine * Command line with path arguments. * @return null if paths are not found in the specified commandLine. */ @SuppressWarnings("unchecked") public final static String[] getFullPaths(PadoShell padoShell, CommandLine commandLine) { List<String> argList = (List<String>) commandLine.getArgList(); if (argList.size() <= 1) { return null; } HashSet<String> set = new HashSet<String>(argList.size()); for (int i = 1; i < argList.size(); i++) { String path = argList.get(i); set.add(padoShell.getFullPath(path)); } String fullPaths[] = set.toArray(new String[set.size()]); return fullPaths; }
From source file:fastcall.FArrayUtils.java
/** * Return sorted unique array of string/* w ww . j a va2 s. c o m*/ * @param input * @return */ public static String[] getUniqueStringArray(String[] input) { HashSet<String> t = new HashSet(); for (int i = 0; i < input.length; i++) { t.add(input[i]); } String[] result = t.toArray(new String[t.size()]); Arrays.sort(result); return result; }