List of usage examples for java.util Collection contains
boolean contains(Object o);
From source file:com.facebook.TestUtils.java
public static void assertSamePermissions(final Collection<String> expected, final Collection<String> actual) { if (expected == null) { Assert.assertEquals(null, actual); } else {//ww w . ja v a 2 s . co m for (String p : expected) { Assert.assertTrue(actual.contains(p)); } for (String p : actual) { Assert.assertTrue(expected.contains(p)); } } }
From source file:ee.ioc.cs.vsle.ccl.PackageClassLoader.java
/** * Helper method for getWebStartClasspath() method. * Returns a local URL of a jar for the classpath. * If jar is a system lib, it is ignored. * @param url//from w w w. j a v a 2 s. c o m * @param systemLibs * @return */ private static URL getLocalJarURL(URL url, Collection<String> systemLibs) { String urlStrJar = getJarPath(url); //ignore if it is a system lib if (systemLibs.contains(urlStrJar)) return null; InputStream inputStreamJar = null; File tempJar; try { //check if the file is already local if (url.getPath().startsWith("file:")) return new File(urlStrJar).toURI().toURL(); JarFile jar = ((JarURLConnection) url.openConnection()).getJarFile(); inputStreamJar = new FileInputStream(jar.getName()); String strippedName = urlStrJar; int dotIndex = strippedName.lastIndexOf('.'); if (dotIndex >= 0) { strippedName = strippedName.substring(0, dotIndex); strippedName = strippedName.replace("/", File.separator); strippedName = strippedName.replace("\\", File.separator); int slashIndex = strippedName.lastIndexOf(File.separator); if (slashIndex >= 0) { strippedName = strippedName.substring(slashIndex + 1); } } tempJar = File.createTempFile(strippedName, ".jar"); tempJar.deleteOnExit(); FileUtils.copyInputStreamToFile(inputStreamJar, tempJar); return tempJar.toURI().toURL(); } catch (Exception ioe) { ioe.printStackTrace(); } finally { try { if (inputStreamJar != null) { inputStreamJar.close(); } } catch (IOException ioe) { } } return null; }
From source file:Main.java
public static <K> boolean isEquals(Collection<K> collection1, Collection<K> collection2) { if (collection1 == null && collection2 == null) { return true; }//from w ww .j av a2 s . co m if (collection1 == null || collection2 == null || collection1.size() != collection2.size()) { return false; } boolean result = true; Iterator<K> ite2 = collection2.iterator(); while (ite2.hasNext()) { if (!collection1.contains(ite2.next())) { result = false; break; } } return result; }
From source file:Main.java
/** * Returns a collection with the common elements in c1 and c2 * @param <T>/* w w w . j a va2 s. c o m*/ * @param c1 * @param c2 * @return */ public static <T> Collection<T> intersect(Collection<T> c1, Collection<T> c2) { if (c1.isEmpty() || c2.isEmpty()) { return Collections.emptySet(); } if (!(c2 instanceof Set) && (c1 instanceof Set || c1.size() > c2.size())) { //swap Collection<T> tmp = c1; c1 = c2; c2 = tmp; } Collection<T> result = new HashSet<T>(); for (T obj : c1) { if (c2.contains(obj)) { result.add(obj); } } return result; }
From source file:com.trilemon.boss.infra.base.util.TopApiUtils.java
public static List<Item> getItems(List<Item> items, Collection<Long> numIids) { List<Item> filerItems = Lists.newArrayList(); for (Item item : items) { if (numIids.contains(item.getNumIid())) { filerItems.add(item);/*from www . j a v a2s . c om*/ } } return filerItems; }
From source file:com.hihframework.core.utils.CollectionUtils.java
/** * ?ID?,???.//from w ww. j av a 2 s . com * http?????idhibernate??????? * ? * ???ID?,ID?ID??. * * @param collection * ?? * @param checkedIds * ? * @param idName * ID?? * @param clazz * ? */ public static <T, ID> void mergeByCheckedIds(Collection<T> collection, Collection<ID> checkedIds, String idName, Class<T> clazz) throws Exception { if (checkedIds == null) { collection.clear(); return; } Iterator<T> it = collection.iterator(); while (it.hasNext()) { T obj = it.next(); if (checkedIds.contains(PropertyUtils.getProperty(obj, idName))) { checkedIds.remove(PropertyUtils.getProperty(obj, idName)); } else { it.remove(); } } for (ID id : checkedIds) { T obj = clazz.newInstance(); PropertyUtils.setProperty(obj, idName, id); collection.add(obj); } }
From source file:Main.java
@SuppressWarnings("unchecked") public static void mergeNestedMap(Map<Object, Object> baseMap, Map<Object, Object> overrideMap, boolean overrideEmpty) { if (baseMap == null || overrideMap == null) return;/*ww w . java 2 s . c o m*/ for (Map.Entry<Object, Object> entry : overrideMap.entrySet()) { Object key = entry.getKey(); Object value = entry.getValue(); if (baseMap.containsKey(key)) { if (value == null) { if (overrideEmpty) baseMap.put(key, null); } else { if (value instanceof CharSequence) { if (overrideEmpty || ((CharSequence) value).length() > 0) baseMap.put(key, value); } else if (value instanceof Map) { Object baseValue = baseMap.get(key); if (baseValue != null && baseValue instanceof Map) { mergeNestedMap((Map) baseValue, (Map) value, overrideEmpty); } else { baseMap.put(key, value); } } else if (value instanceof Collection) { Object baseValue = baseMap.get(key); if (baseValue != null && baseValue instanceof Collection) { Collection baseCol = (Collection) baseValue; Collection overrideCol = (Collection) value; for (Object overrideObj : overrideCol) { // NOTE: if we have a Collection of Map we have no way to merge the Maps without knowing the 'key' entries to use to match them if (!baseCol.contains(overrideObj)) baseCol.add(overrideObj); } } else { baseMap.put(key, value); } } else { // NOTE: no way to check empty, if not null not empty so put it baseMap.put(key, value); } } } else { baseMap.put(key, value); } } }
From source file:grails.plugin.searchable.internal.util.GrailsDomainClassUtils.java
/** * Is the given GrailsDomainClass with an inheritance hierarchy with the given collection? * @param grailsDomainClass the grails domain class * @param grailsDomainClasses the collection of grails domain classes * @return true if the given class is within a hierarchy: it has super or sub-classes *//*from w w w . j a va 2s.c o m*/ public static boolean isWithinInhertitanceHierarchy(GrailsDomainClass grailsDomainClass, Collection grailsDomainClasses) { if (getSuperClass(grailsDomainClass, grailsDomainClasses) != null) { return true; } for (Iterator iter = grailsDomainClass.getSubClasses().iterator(); iter.hasNext();) { Object o = iter.next(); if (grailsDomainClasses.contains(o)) { return true; } } return false; }
From source file:net.geoprism.localization.LocaleManager.java
@SuppressWarnings("unchecked") private static Locale getBestFitLocale(Locale _locale, Collection<Locale> _locales) { List<Locale> lookups = (List<Locale>) LocaleUtils.localeLookupList(_locale); for (Locale lookup : lookups) { if (_locales.contains(lookup)) { return lookup; }//from ww w . jav a 2 s . c om } // There is no best fit, return English as the default locale return Locale.ENGLISH; }
From source file:javadepchecker.Main.java
private static boolean depNeeded(String pkg, Collection<String> deps) throws IOException { for (String jarName : getPackageJars(pkg)) { JarFile jar = new JarFile(jarName); for (Enumeration<JarEntry> e = jar.entries(); e.hasMoreElements();) { String name = e.nextElement().getName(); if (deps.contains(name)) { return true; }/* ww w.ja v a2 s . c om*/ } } return false; }