List of usage examples for java.util Collection contains
boolean contains(Object o);
From source file:com.projity.util.DataUtils.java
public static void extractObjectsOfClassFromNodeList(Collection result, Collection nodeList, Class objectClass) {/*from w ww .j a v a2 s. c o m*/ result.clear(); Iterator i = nodeList.iterator(); Object nodeObject; while (i.hasNext()) { nodeObject = ((Node) i.next()).getImpl(); nodeObject = DataUtils.extractObjectOfClass(nodeObject, objectClass); if (nodeObject != null) { if (!result.contains(nodeObject)) // only add if not already in there result.add(nodeObject); } } }
From source file:com.siemens.sw360.datahandler.common.CommonUtils.java
/** * Return true if and item is contained in a collection, false otherwise. Null objects make the function returns false *///from w ww . j a v a2s .c om public static <T> boolean contains(T item, Collection<T> collection) { return item != null && collection != null && collection.contains(item); }
From source file:info.magnolia.cms.beans.config.ContentRepository.java
/** * Get default workspace name/*from w ww. ja v a2 s . c om*/ * @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(repositoryId)) { return repositoryId; } return DEFAULT_WORKSPACE; }
From source file:com.kylinolap.query.routing.QueryRouter.java
private static void adjustOLAPContext(Collection<TblColRef> dimensionColumns, Collection<FunctionDesc> aggregations, // Collection<TblColRef> metricColumns, CubeInstance cube, Map<String, RelDataType> rewriteFields, OLAPContext olapContext) {//from w ww .ja v a2 s.co m CubeDesc cubeDesc = cube.getDescriptor(); Collection<FunctionDesc> cubeFuncs = cubeDesc.listAllFunctions(); Iterator<FunctionDesc> it = aggregations.iterator(); while (it.hasNext()) { FunctionDesc functionDesc = it.next(); if (!cubeFuncs.contains(functionDesc)) { // try to convert the metric to dimension to see if it works TblColRef col = findTblColByColumnName(metricColumns, functionDesc.getParameter().getValue()); functionDesc.setAppliedOnDimension(true); rewriteFields.remove(functionDesc.getRewriteFieldName()); if (col != null) { metricColumns.remove(col); dimensionColumns.add(col); olapContext.storageContext.addOtherMandatoryColumns(col); } logger.info("Adjust OLAPContext for " + functionDesc); } } }
From source file:Main.java
@SuppressWarnings("unchecked") public static <E> Collection<E> union(Collection<E> collectionA, Collection<E> collectionB) { Collection<E> collectionC = null; try {/*from ww w . j av a 2 s. co m*/ collectionC = collectionA.getClass().newInstance(); } catch (Exception e) { e.printStackTrace(); return collectionC; } Iterator<E> aIterator = collectionA.iterator(); Iterator<E> bIterator = collectionB.iterator(); while (aIterator.hasNext() || bIterator.hasNext()) { if (aIterator.hasNext()) { E ae = aIterator.next(); if (!collectionC.contains(ae)) { collectionC.add(ae); } } if (bIterator.hasNext()) { E be = bIterator.next(); if (!collectionA.contains(be) && !collectionC.contains(be)) { collectionC.add(be); } } } return collectionC; }
From source file:com.feilong.core.util.predicate.BeanPredicateUtil.java
/** * Contains predicate./*from w ww. j a v a 2s .c o m*/ * * <p> * {@link PropertyUtil#getProperty(Object, String)} <code>propertyName</code>,{@link java.util.Collection#contains(Object) * Collection.contains} ?<code>values</code>?. * </p> * * @param <T> * the generic type * @param <V> * the value type * @param propertyName * T??,Possibly indexed and/or nested name of the property to be modified,?? * <a href="../../bean/BeanUtil.html#propertyName">propertyName</a> * @param propertyValueList * the property value list * @return <code>propertyName</code> null, {@link NullPointerException}<br> * <code>propertyName</code> blank, {@link IllegalArgumentException}<br> * @see java.util.Collection#contains(Object) */ public static <T, V> Predicate<T> containsPredicate(final String propertyName, final Collection<V> propertyValueList) { return new BeanPredicate<T>(propertyName, new Predicate<V>() { @Override public boolean evaluate(V propertyValue) { return isNullOrEmpty(propertyValueList) ? false : propertyValueList.contains(propertyValue); } }); }
From source file:Main.java
/** * Collections are equals if they contain the same elements * independent of ordering./*from ww w.j a va2 s. c o m*/ * To this to be true, they must have the same number of elements. * Empty collections are equal. * * @param <T> * @param c1 * @param c2 * @return */ public static <T> boolean equalContents(Collection<? extends T> c1, Collection<? extends T> c2) { if (c1 == c2) { return true; } else if (c1.isEmpty() && c2.isEmpty()) { return true; } if (c1.size() != c2.size()) { return false; } if (!(c2 instanceof Set) && (c1 instanceof Set || c1.size() > c2.size())) { //swap Collection<? extends T> tmp = c1; c1 = c2; c2 = tmp; } for (T t : c1) { if (!c2.contains(t)) { return false; } } return true; }
From source file:com.samsung.sjs.theorysolver.TheorySolver.java
public static <Constraint, Model> void enumerateFixingSets(FixingSetFinder<Constraint> fixingSetFinder, Theory<Constraint, Model> theorySolver, Collection<Constraint> hardConstraints, Collection<Constraint> softConstraints, FixingSetListener<Constraint, Model> listener) { Collection<Constraint> constraints = new ArrayList<>(); Collection<Constraint> core = new ArrayList<>(); Collection<Constraint> fixingSet = new LinkedHashSet<>(); for (;;) {/*from ww w . j a va 2 s. com*/ if (fixingSetFinder.currentFixingSet(fixingSet, listener) == FixingSetListener.Action.STOP) { return; } constraints.addAll(hardConstraints); softConstraints.stream().filter(c -> !fixingSet.contains(c)).forEach(constraints::add); Either<Model, Collection<Constraint>> result = theorySolver.check(constraints); if (result.left != null) { if (listener.onFixingSet(result.left, fixingSet) == FixingSetListener.Action.STOP) { return; } fixingSetFinder.addCore( constraints.stream().filter(softConstraints::contains).collect(Collectors.toList())); } else { result.right.stream().filter(softConstraints::contains).forEach(core::add); if (listener.onCore(core) == FixingSetListener.Action.STOP) { return; } assert core.stream().allMatch(c -> !fixingSet.contains(c)); fixingSetFinder.addCore(core); } core.clear(); constraints.clear(); fixingSet.clear(); } }
From source file:com.wavemaker.runtime.data.util.DataServiceUtils.java
public static String operationToQueryName(String operationName, Collection<String> queryNames) { if (queryNames.contains(operationName)) { return operationName; }/*from w ww . ja v a 2 s.c o m*/ return StringUtils.upperCaseFirstLetter(operationName); }
From source file:com.imaginea.betterdocs.BetterDocsAction.java
private static MutableTreeNode getNodes(String projectName, Iterable<CodeInfo> codeInfoCollection) { DefaultMutableTreeNode node = new DefaultMutableTreeNode(projectName); Collection<String> fileNameSet = new HashSet<String>(); for (CodeInfo codeInfo : codeInfoCollection) { if (!fileNameSet.contains(codeInfo.getFileName())) { node.add(new DefaultMutableTreeNode(codeInfo)); fileNameSet.add(codeInfo.getFileName()); }//from w ww . ja v a 2s . c o m } return node; }