List of usage examples for java.util Collection contains
boolean contains(Object o);
From source file:Main.java
/** * Appends value to collection. If value is collection all elements are added, if value is object it is simply * added. If skipDuplicates is set to true, objects already contained in the collection are not added again. Note * that element would be type casted to collection type. * /*w w w .j a va2 s. c o m*/ * @param data * is the collection to update - set, list, etc. Should be modifiable * @param value * is value of type T or {@link Collection} of elements of type T * @param skipDuplicates * whether to treat data as {@link Set}. Note if data is already {@link Set} parameter does not affect * the result. Note if data already contains duplicate elements they are not affected. * @return the updated data collection */ @SuppressWarnings("unchecked") public static <T> Collection<T> addValue(Collection<T> data, Object value, boolean skipDuplicates) { if (value instanceof Collection) { Collection<T> toBeAdded = (Collection<T>) value; if (skipDuplicates && !(data instanceof Set)) { Set<T> nonDuplicates = new LinkedHashSet<>(toBeAdded); nonDuplicates.removeAll(data); data.addAll(nonDuplicates); } else { data.addAll(toBeAdded); } } else if (value != null) { if (skipDuplicates && !(data instanceof Set) && data.contains(value)) { return data; } data.add((T) value); } return data; }
From source file:it.openutils.mgnlaws.magnolia.init.ClasspathContentRepository.java
/** * Get default workspace name./*from www .j av a 2 s. c o m*/ * @return default name if there are no workspaces defined or there is no workspace present with name "default", * otherwise return same name as repository name. */ public static String getDefaultWorkspace(String repositoryId) { RepositoryMapping mapping = getRepositoryMapping(repositoryId); if (mapping == null) { return DEFAULT_WORKSPACE; } Collection workspaces = mapping.getWorkspaces(); if (workspaces.contains(getMappedWorkspaceName(repositoryId))) { return repositoryId; } return DEFAULT_WORKSPACE; }
From source file:com.taobao.android.builder.tools.classinject.CodeInjectByJavassist.java
public synchronized static byte[] inject(ClassPool pool, String className, InjectParam injectParam) throws Exception { CtClass cc = pool.get(className);/*from www .ja v a 2 s. c om*/ cc.defrost(); if (className.equalsIgnoreCase("android.taobao.atlas.framework.FrameworkProperties") || className.equalsIgnoreCase("android.taobao.atlas.version.VersionKernal")) { if (StringUtils.isNotBlank(injectParam.version)) { CtClass ctClass = pool.get("java.lang.String"); CtField ctField = new CtField(ctClass, "version", cc); ctField.setModifiers(Modifier.PRIVATE); CtMethod ctMethod = CtNewMethod.getter("getVersion", ctField); ctMethod.setModifiers(Modifier.PUBLIC); CtField.Initializer initializer = CtField.Initializer.constant(injectParam.version); cc.addField(ctField, initializer); cc.addMethod(ctMethod); logger.info("[android.taobao.atlas.framework.FrameworkProperties] inject version " + injectParam.version); } addField(pool, cc, "bundleInfo", injectParam.bundleInfo); addField(pool, cc, "autoStartBundles", injectParam.autoStartBundles); addField(pool, cc, "preLaunch", injectParam.preLaunch); addField(pool, cc, "group", injectParam.group); addField(pool, cc, "outApp", String.valueOf(injectParam.outApp)); if (null != injectParam.outputFile) { Map output = new HashMap(); output.put("bundleInfo", JSON.parseArray(injectParam.bundleInfo)); output.put("autoStartBundles", injectParam.autoStartBundles); output.put("preLaunch", injectParam.preLaunch); output.put("group", injectParam.group); output.put("outApp", injectParam.outApp); FileUtils.write(injectParam.outputFile, JSON.toJSONString(output, true)); } } ClazzInjecter clazzInjecter = sInjecterMap.get(className); if (null != clazzInjecter) { Map<String, String> stringMap = clazzInjecter.getInjectFields(); if (!stringMap.isEmpty()) { for (String key : stringMap.keySet()) { addField(pool, cc, key, stringMap.get(key)); } } } if (!injectParam.removePreverify) { Collection<String> refClasses = cc.getRefClasses(); if (refClasses.contains("com.taobao.verify.Verifier")) { return cc.toBytecode(); } boolean flag = false; if (className.equalsIgnoreCase("com.ut.mini.crashhandler.IUTCrashCaughtListner")) { flag = true; } if (cc.isInterface()) { final CtClass defClass = pool.get(Class.class.getName()); CtField defField = new CtField(defClass, "_inject_field__", cc); defField.setModifiers(Modifier.STATIC | Modifier.PUBLIC | Modifier.FINAL); cc.addField(defField, CtField.Initializer.byExpr( "Boolean.TRUE.booleanValue()?java.lang.String.class:com.taobao.verify.Verifier" + ".class;")); } else { CtConstructor[] ctConstructors = cc.getDeclaredConstructors(); if (null != ctConstructors && ctConstructors.length > 0) { CtConstructor ctConstructor = ctConstructors[0]; ctConstructor.insertBeforeBody( "if(Boolean.FALSE.booleanValue()){java.lang.String.valueOf(com.taobao.verify.Verifier" + ".class);}"); } else { final CtClass defClass = pool.get(Class.class.getName()); CtField defField = new CtField(defClass, "_inject_field__", cc); defField.setModifiers(Modifier.STATIC); cc.addField(defField, CtField.Initializer .byExpr("Boolean.TRUE.booleanValue()?java.lang.String.class:com.taobao.verify" + ".Verifier.class;")); } } } return cc.toBytecode(); }
From source file:Main.java
private static void addImports(Attributes attrigutes, BundleDescription compositeDesc, ExportPackageDescription[] matchingExports) { ExportPackageDescription[] exports = compositeDesc.getExportPackages(); List systemExports = getSystemExports(matchingExports); if (exports.length == 0 && systemExports.size() == 0) return;// www .j a v a 2s . c o m StringBuffer importStatement = new StringBuffer(); Collection importedNames = new ArrayList(exports.length); int i = 0; for (; i < exports.length; i++) { if (i != 0) importStatement.append(','); importedNames.add(exports[i].getName()); getImportFrom(exports[i], importStatement); } for (Iterator iSystemExports = systemExports.iterator(); iSystemExports.hasNext();) { ExportPackageDescription systemExport = (ExportPackageDescription) iSystemExports.next(); if (!importedNames.contains(systemExport.getName())) { if (i != 0) importStatement.append(','); i++; importStatement.append(systemExport.getName()).append(ELEMENT_SEPARATOR) .append(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE).append('=') .append(Constants.SYSTEM_BUNDLE_SYMBOLICNAME); } } attrigutes.putValue(Constants.IMPORT_PACKAGE, importStatement.toString()); }
From source file:ml.shifu.core.util.CommonUtils.java
/** * Returns the element if it is in both collections. * - return null if any collection is null or empty * - return null if no element exists in both collections * * @param leftCol - left collection//from w w w . j av a2s .co m * @param rightCol - right collection * @return First element that are found in both collections * null if no elements in both collection or any collection is null or empty */ public static <T> T containsAny(Collection<T> leftCol, Collection<T> rightCol) { if (leftCol == null || rightCol == null || leftCol.isEmpty() || rightCol.isEmpty()) { return null; } for (T element : leftCol) { if (rightCol.contains(element)) { return element; } } return null; }
From source file:com.wavemaker.runtime.data.util.DataServiceUtils.java
private static Object mergeForInsert(Object source, Session session, DataServiceMetaData metaData, boolean isRoot, Collection<Object> handledInstances) { if (handledInstances.contains(source)) { return source; }//from w w w. j a v a2s .c o m Class<?> entityClass = getEntityClass(source.getClass()); String idPropName = metaData.getIdPropertyName(entityClass); Object idPropVal = objectAccess.getProperty(source, idPropName); if (idPropVal != null) { if (isRoot) { // MAV-2065 return source; } Object o = loadById(source, session, metaData); if (o != null) { handledInstances.add(o); return o; } } handledInstances.add(source); Collection<String> relatedPropertyNames = metaData.getRelPropertyNames(source.getClass()); for (String propertyName : relatedPropertyNames) { if (isRelatedMany(objectAccess.getPropertyType(source.getClass(), propertyName))) { continue; } Object clientValue = objectAccess.getProperty(source, propertyName); if (clientValue != null) { clientValue = mergeForInsert(clientValue, session, metaData, false, handledInstances); objectAccess.setProperty(source, propertyName, clientValue); } } return source; }
From source file:com.facebook.TestUtils.java
public static void assertSamePermissions(final Collection<String> expected, final AccessToken actual) { if (expected == null) { Assert.assertEquals(null, actual.getPermissions()); } else {/* w w w. j av a 2 s.c o m*/ for (String p : expected) { Assert.assertTrue(actual.getPermissions().contains(p)); } for (String p : actual.getPermissions()) { Assert.assertTrue(expected.contains(p)); } } }
From source file:org.nema.medical.mint.dcm2mint.ProcessImportDir.java
private static void findPlainFilesRecursive(final File targetFile, final Collection<File> resultFiles, final Collection<File> handledFiles) { if (handledFiles.contains(targetFile)) { //Need to check whether file has already been handled right away, as otherwise the file may get //accessed or deleted by someone else while we're looking at it. return;//from w w w . j a va2 s . com } //Skip DICOM files which are not completely stored by dcmrcv yet. if (targetFile.getName().endsWith(".part")) { return; } if (targetFile.isFile()) { resultFiles.add(targetFile); } else if (targetFile.isDirectory()) { for (final File subFile : targetFile.listFiles()) { findPlainFilesRecursive(subFile, resultFiles, handledFiles); } } else { throw new RuntimeException( "File " + targetFile.getAbsolutePath() + " is not a normal file and not a directory"); } }
From source file:net.sourceforge.fenixedu.applicationTier.Servico.manager.executionCourseManagement.SeperateExecutionCourse.java
private static void transferAttends(final ExecutionCourse originExecutionCourse, final ExecutionCourse destinationExecutionCourse) { final Collection<CurricularCourse> curricularCourses = destinationExecutionCourse .getAssociatedCurricularCoursesSet(); List<Attends> allAttends = new ArrayList<>(originExecutionCourse.getAttendsSet()); for (Attends attends : allAttends) { final Enrolment enrolment = attends.getEnrolment(); if (enrolment != null && curricularCourses.contains(enrolment.getCurricularCourse())) { attends.setDisciplinaExecucao(destinationExecutionCourse); }/*from w w w . java 2 s. com*/ } }
From source file:com.chiorichan.util.WebFunc.java
/** * Filters a map for the specified list of keys, removing keys that are not contained in the list. * Groovy example: def filteredMap = getHttpUtils().filter( unfilteredMap, ["keyA", "keyB", "someKey"], false ); * * @param data/* w ww. j a v a 2s . c o m*/ * The map that needs checking * @param allowedKeys * A list of keys allowed * @param caseSensitive * Will the key match be case sensitive or not * @return The resulting map of filtered data */ public static Map<String, Object> filter(Map<String, Object> data, Collection<String> allowedKeys, boolean caseSensitive) { Map<String, Object> newArray = new LinkedHashMap<String, Object>(); if (!caseSensitive) allowedKeys = StringFunc.toLowerCaseList(allowedKeys); for (Entry<String, Object> e : data.entrySet()) if (!caseSensitive && allowedKeys.contains(e.getKey().toLowerCase()) || allowedKeys.contains(e.getKey())) newArray.put(e.getKey(), e.getValue()); return newArray; }