List of usage examples for java.util Set contains
boolean contains(Object o);
From source file:com.palantir.ptoss.cinch.swing.JListWiringHarness.java
private static void updateListModel(JList list, List<?> newContents) { if (newContents == null) { newContents = ImmutableList.of(); }//from w ww. jav a2 s . c o m ListModel oldModel = list.getModel(); List<Object> old = Lists.newArrayListWithExpectedSize(oldModel.getSize()); for (int i = 0; i < oldModel.getSize(); i++) { old.add(oldModel.getElementAt(i)); } if (old.equals(newContents)) { return; } Object[] selected = list.getSelectedValues(); DefaultListModel listModel = new DefaultListModel(); for (Object obj : newContents) { listModel.addElement(obj); } list.setModel(listModel); List<Integer> newIndices = Lists.newArrayListWithCapacity(selected.length); Set<Object> selectedSet = Sets.newHashSet(selected); for (int i = 0; i < listModel.size(); i++) { if (selectedSet.contains(listModel.elementAt(i))) { newIndices.add(i); } } list.setSelectedIndices(ArrayUtils.toPrimitive(newIndices.toArray(new Integer[0]))); }
From source file:Main.java
/** * Returns <code>true</code> iff all elements of {@code coll2} are also contained * in {@code coll1}. The cardinality of values in {@code coll2} is not taken into account, * which is the same behavior as {@link Collection#containsAll(Collection)}. * <p>//from w w w.ja v a 2 s.c o m * In other words, this method returns <code>true</code> iff the * {@link #intersection} of <i>coll1</i> and <i>coll2</i> has the same cardinality as * the set of unique values from {@code coll2}. In case {@code coll2} is empty, {@code true} * will be returned. * <p> * This method is intended as a replacement for {@link Collection#containsAll(Collection)} * with a guaranteed runtime complexity of {@code O(n + m)}. Depending on the type of * {@link Collection} provided, this method will be much faster than calling * {@link Collection#containsAll(Collection)} instead, though this will come at the * cost of an additional space complexity O(n). * * @param coll1 the first collection, must not be null * @param coll2 the second collection, must not be null * @return <code>true</code> iff the intersection of the collections has the same cardinality * as the set of unique elements from the second collection * @since 4.0 */ public static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2) { if (coll2.isEmpty()) { return true; } else { final Iterator<?> it = coll1.iterator(); final Set<Object> elementsAlreadySeen = new HashSet<Object>(); for (final Object nextElement : coll2) { if (elementsAlreadySeen.contains(nextElement)) { continue; } boolean foundCurrentElement = false; while (it.hasNext()) { final Object p = it.next(); elementsAlreadySeen.add(p); if (nextElement == null ? p == null : nextElement.equals(p)) { foundCurrentElement = true; break; } } if (foundCurrentElement) { continue; } else { return false; } } return true; } }
From source file:Main.java
/** * Produce a new set/* www. ja v a 2s . c o 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; }
From source file:io.github.moosbusch.lumpi.util.FormUtil.java
public static Map<String, Class<?>> getPropertyTypesMap(final Class<?> type, Map<String, Set<Class<?>>> excludedProperties) { final Map<String, Class<?>> result = new HashMap<>(); PropertyDescriptor[] propDescs = PropertyUtils.getPropertyDescriptors(type); Map<String, Set<Class<?>>> excludedProps = excludedProperties; if (excludedProps != null) { for (PropertyDescriptor propDesc : propDescs) { Class<?> propertyType = propDesc.getPropertyType(); if (propertyType != null) { String propertyName = propDesc.getName(); if (excludedProps.containsKey(propertyName)) { Set<Class<?>> ignoredPropertyTypes = excludedProps.get(propertyName); if (!ignoredPropertyTypes.contains(type)) { Set<Class<?>> superTypes = LumpiUtil.getSuperTypes(type, false, true, true); for (Class<?> superType : superTypes) { if (ignoredPropertyTypes.contains(superType)) { result.put(propertyName, propertyType); break; }/*from ww w . java 2s . co m*/ } } } } } } return result; }
From source file:architecture.common.util.ClassUtils.java
/** * Finds all super classes and interfaces for a given class * // www.j av a 2s.com * @param cls * The class to scan * @param types * The collected related classes found */ public static void findAllTypes(Class cls, Set<Class> types) { if (cls == null) { return; } // check to ensure it hasn't been scanned yet if (types.contains(cls)) { return; } types.add(cls); findAllTypes(cls.getSuperclass(), types); for (int x = 0; x < cls.getInterfaces().length; x++) { findAllTypes(cls.getInterfaces()[x], types); } }
From source file:org.joinfaces.annotations.JsfCdiToSpring.java
static String deduceScopeName(Set<String> annotationTypes) { String result = null;// w w w . j ava2 s. com if (annotationTypes != null && !annotationTypes.isEmpty()) { if (annotationTypes.contains(javax.enterprise.context.RequestScoped.class.getName()) || annotationTypes.contains(javax.faces.bean.RequestScoped.class.getName())) { result = REQUEST; } else if (annotationTypes.contains(javax.enterprise.context.SessionScoped.class.getName()) || annotationTypes.contains(javax.faces.bean.SessionScoped.class.getName())) { result = SESSION; } else if (annotationTypes.contains(javax.enterprise.context.ApplicationScoped.class.getName()) || annotationTypes.contains(javax.faces.bean.ApplicationScoped.class.getName())) { result = SINGLETON; } else if (annotationTypes.contains(javax.faces.bean.NoneScoped.class.getName())) { result = PROTOTYPE; } else if (annotationTypes.contains(javax.faces.view.ViewScoped.class.getName()) || annotationTypes.contains(javax.faces.bean.ViewScoped.class.getName())) { result = VIEW; } else if (annotationTypes.contains(javax.enterprise.context.ConversationScoped.class.getName())) { result = SESSION; } } return result; }
From source file:Main.java
public static <E extends Enum<?>> Set<E> getAllExcluding(E elements[], E... excluding) { Set<E> exclude_set = new HashSet<E>(); for (E e : excluding) exclude_set.add(e);/*ww w.j a v a 2s .c o m*/ Set<E> elements_set = new HashSet<E>(); for (int i = 0; i < elements.length; i++) { if (!exclude_set.contains(elements[i])) elements_set.add(elements[i]); } // FOR return (elements_set); // Crappy java.... // Object new_elements[] = new Object[elements_set.size()]; // elements_set.toArray(new_elements); // return ((E[])new_elements); }
From source file:io.confluent.connect.elasticsearch.Mapping.java
/** * Check the whether a mapping exists or not for a type. * @param client The client to connect to Elasticsearch. * @param index The index to write to Elasticsearch. * @param type The type to check./* w ww . j a va2s. c o m*/ * @return Whether the type exists or not. */ public static boolean doesMappingExist(JestClient client, String index, String type, Set<String> mappings) throws IOException { if (mappings.contains(index)) { return true; } GetMapping getMapping = new GetMapping.Builder().addIndex(index).addType(type).build(); JestResult result = client.execute(getMapping); JsonObject resultJson = result.getJsonObject().getAsJsonObject(index); if (resultJson == null) { return false; } JsonObject typeJson = resultJson.getAsJsonObject(type); if (typeJson == null) { return false; } mappings.add(index); return true; }
From source file:com.huawei.streaming.cql.executor.ExecutorUtils.java
/** * ??// w w w . j a v a 2 s. c om * * ?join? * * ??From?To?? * @param transitions * @return */ public static List<OperatorTransition> getFirstTransitons(List<OperatorTransition> transitions) { List<OperatorTransition> res = new ArrayList<OperatorTransition>(); Set<String> froms = getFromTransitons(transitions); Set<String> tos = getToTransitons(transitions); for (String s : froms) { if (!tos.contains(s)) { res.addAll(getTransitonsByFromId(s, transitions)); } } return res; }
From source file:de.tudarmstadt.lt.nlkg.EvaluateArgs.java
static boolean predictEntailingContainedInNTopEntries(DT dt, String arg_l, String arg_r) { DT.Entry e = dt.get(arg_l, ntop);//from ww w. j av a2 s . com @SuppressWarnings("unchecked") Iterator<String> string_iter = IteratorUtils.transformedIterator(e.dtwords, new Transformer() { @Override public Object transform(Object input) { return ((Word) input).word; } }); Set<String> dtwords = new HashSet<String>( Arrays.asList((String[]) IteratorUtils.toArray(string_iter, String.class))); return dtwords.contains(arg_r); }