List of usage examples for java.util Collection contains
boolean contains(Object o);
From source file:eu.ggnet.dwoss.report.assist.ReportUtil.java
/** * Returns a Set of all Warrenty Positions in the Collection that is given to the method. * <p>/*from w ww. ja va 2s .co m*/ * A Warranty is in the Set of Reportable Warranty if * <ul> * <li>SingleRefence from Type {@link SingleReferenceType#WARRANTY} is not null</li> * <li>SingleReferenced Unit is in the reportable Amount of ReportLines</li> * <li>Reporting Date is after the from Parameter and before the till Parameter</li> * </ul> * <p> * @param warrentyLines all unreported Reportlines that represent warrenty. * @param unitLines all ReportLine's that are already in amount of Reportlines which should be reported. * @return all Warrentys which can be reported in this report. */ public static NavigableSet<ReportLine> filterWarrenty(Collection<ReportLine> warrentyLines, Collection<ReportLine> unitLines) { L.info("Warranties in filter: {}", warrentyLines); return warrentyLines.stream() .filter((t) -> t != null && t.getReference(WARRANTY) != null && (unitLines.contains(t.getReference(WARRANTY)) || !t.getReference(WARRANTY).getReports().isEmpty())) .collect(Collectors.toCollection(() -> new TreeSet<ReportLine>())); }
From source file:com.kylinolap.query.routing.QueryRouter.java
private static boolean isWeaklyMatchedWithAggregations(Collection<FunctionDesc> aggregations, Collection<TblColRef> metricColumns, CubeInstance cube) { CubeDesc cubeDesc = cube.getDescriptor(); Collection<FunctionDesc> cubeFuncs = cubeDesc.listAllFunctions(); boolean matched = true; for (FunctionDesc functionDesc : aggregations) { if (!cubeFuncs.contains(functionDesc)) { if (functionDesc.isCountDistinct())// optiq can not handle // distinct count matched = false;// w w w. jav a 2 s .c o m ParameterDesc param = functionDesc.getParameter(); if (param != null) { TblColRef col = findTblColByColumnName(metricColumns, param.getValue()); if (col == null || !cubeDesc.listDimensionColumnsIncludingDerived().contains(col)) { matched = false; } } else { matched = false; } } } return matched; }
From source file:Main.java
/** * Given two Collections, return the size of their union * @param firstCollection The first collection. <code>null</code> is allowed. * @param secondCollection The second collection. <code>null</code> is allowed. * @return//from www .j a va 2 s. c o m */ public static <E> int getUnionSize(Collection<? extends E> firstCollection, Collection<? extends E> secondCollection) { int firstSize = (firstCollection != null) ? firstCollection.size() : 0; int secondSize = (secondCollection != null) ? secondCollection.size() : 0; if (firstSize == 0) return secondSize; if (secondSize == 0) return firstSize; // determine the size of the union by iterating over the smaller collection int size; Collection<? extends E> iteratingCollection; Collection<? extends E> baseCollection; if (firstSize >= secondSize) { baseCollection = firstCollection; iteratingCollection = secondCollection; size = firstSize; } else { baseCollection = secondCollection; iteratingCollection = firstCollection; size = secondSize; } for (E currValue : iteratingCollection) { if (!baseCollection.contains(currValue)) { size++; } } return size; }
From source file:com.wavemaker.common.util.StringUtils.java
public static String getUniqueName(String name, Collection<String> names) { if (!names.contains(name)) { return name; }// ww w . j a va 2 s . co m for (int i = 2; i < Integer.MAX_VALUE; i++) { String newName = name + i; if (!names.contains(newName)) { return newName; } } throw new AssertionError("Cannot get unique name for " + name); }
From source file:edu.uci.ics.jung.algorithms.transformation.FoldingTransformer.java
/** * Converts <code>g</code> into a unipartite graph whose vertex set is the * vertices of <code>g</code>'s partition <code>p</code>. For vertices * <code>a</code> and <code>b</code> in this partition, the resultant * graph will include the edge <code>(a,b)</code> if the original graph * contains edges <code>(a,c)</code> and <code>(c,b)</code> for at least * one vertex <code>c</code>. * /*w w w .j a v a2s . c o m*/ * <p>The vertices of the new graph are the same as the vertices of the * appropriate partition in the old graph; the edges in the new graph are * created by the input edge <code>Factory</code>.</p> * * <p>If there is more than 1 such vertex <code>c</code> for a given pair * <code>(a,b)</code>, the type of the output graph will determine whether * it will contain parallel edges or not.</p> * * <p>This function will not create self-loops.</p> * * @param <V> vertex type * @param <E> input edge type * @param g input k-partite graph * @param p predicate specifying vertex partition * @param graph_factory factory used to create the output graph * @param edge_factory factory used to create the edges in the new graph * @return a copy of the input graph folded with respect to the input partition */ public static <V, E> Graph<V, E> foldKPartiteGraph(KPartiteGraph<V, E> g, Predicate<V> p, Factory<Graph<V, E>> graph_factory, Factory<E> edge_factory) { Graph<V, E> newGraph = graph_factory.create(); // get vertices for the specified partition Collection<V> vertices = g.getVertices(p); for (V v : vertices) { newGraph.addVertex(v); for (V s : g.getSuccessors(v)) { for (V t : g.getSuccessors(s)) { if (!vertices.contains(t) || t.equals(v)) continue; newGraph.addVertex(t); newGraph.addEdge(edge_factory.create(), v, t); } } } return newGraph; }
From source file:com.threewks.thundr.view.jsp.el.CollectionFunctions.java
/** * @param collectionOrArray a {@link Collection} or array of object * @param objectCollectionOrArray a single object, and array of objects or a {@link Collection} of objects * @return true if the first argument contains any of the elements in the second argument. If the second argument is an empty collection, returns true. if the second element is null, returns true * if a null is contained in the first argument. *//*w ww . j a v a 2s .c om*/ @SuppressWarnings("unchecked") public static boolean containsAny(Object collectionOrArray, Object objectCollectionOrArray) { Collection<Object> collection = toCollection(collectionOrArray); Collection<Object> asCollection = Cast.as(objectCollectionOrArray, Collection.class); if (asCollection == null) { asCollection = isArray(objectCollectionOrArray) ? Arrays.asList((Object[]) objectCollectionOrArray) : Collections.singleton(objectCollectionOrArray); } for (Object o : asCollection) { if (collection.contains(o)) { return true; } } return asCollection.isEmpty(); }
From source file:com.ocs.dynamo.domain.model.util.EntityModelUtil.java
/** * Compares two entities based on the entity model and reports a list of the differences * //from ww w.j a v a 2s.co m * @param oldEntity * the old entity * @param newEntity * the new entity * @param model * the entity model * @param entityModelFactory * @param messageService * the message service * @param ignore * the names of the fields to ignore */ public static List<String> compare(Object oldEntity, Object newEntity, EntityModel<?> model, EntityModelFactory entityModelFactory, MessageService messageService, String... ignore) { List<String> results = new ArrayList<>(); Set<String> toIgnore = new HashSet<>(); if (ignore != null) { toIgnore = Sets.newHashSet(ignore); } toIgnore.addAll(ALWAYS_IGNORE); String noValue = messageService.getMessage("ocs.no.value"); for (AttributeModel am : model.getAttributeModels()) { if ((AttributeType.BASIC.equals(am.getAttributeType()) || AttributeType.MASTER.equals(am.getAttributeType())) && !toIgnore.contains(am.getName())) { Object oldValue = ClassUtils.getFieldValue(oldEntity, am.getName()); Object newValue = ClassUtils.getFieldValue(newEntity, am.getName()); if (!ObjectUtils.equals(oldValue, newValue)) { String oldValueStr = TableUtils.formatPropertyValue(entityModelFactory, model, messageService, am.getName(), oldValue); String newValueStr = TableUtils.formatPropertyValue(entityModelFactory, model, messageService, am.getName(), newValue); results.add(messageService.getMessage("ocs.value.changed", am.getDisplayName(), oldValue == null ? noValue : oldValueStr, newValue == null ? noValue : newValueStr)); } } else if (AttributeType.DETAIL.equals(am.getAttributeType())) { Collection<?> ocol = (Collection<?>) ClassUtils.getFieldValue(oldEntity, am.getName()); Collection<?> ncol = (Collection<?>) ClassUtils.getFieldValue(newEntity, am.getName()); for (Object o : ncol) { if (!ocol.contains(o)) { results.add(messageService.getMessage("ocs.value.added", getDescription(o, am.getNestedEntityModel()), am.getDisplayName())); } } for (Object o : ocol) { if (!ncol.contains(o)) { results.add(messageService.getMessage("ocs.value.removed", getDescription(o, am.getNestedEntityModel()), am.getDisplayName())); } } for (Object o : ocol) { for (Object o2 : ncol) { if (o.equals(o2)) { List<String> nested = compare(o, o2, am.getNestedEntityModel(), entityModelFactory, messageService, ignore); results.addAll(nested); } } } } } return results; }
From source file:edu.uci.ics.jung.algorithms.transformation.FoldingTransformer.java
/** * Converts <code>g</code> into a unipartite graph whose vertices are the * vertices of <code>g</code>'s partition <code>p</code>, and whose edges * consist of collections of the intermediate vertices from other partitions. * For vertices//from w w w .j a va 2s . c o m * <code>a</code> and <code>b</code> in this partition, the resultant * graph will include the edge <code>(a,b)</code> if the original graph * contains edges <code>(a,c)</code> and <code>(c,b)</code> for at least * one vertex <code>c</code>. * * <p>The vertices of the new graph are the same as the vertices of the * appropriate partition in the old graph; the edges in the new graph are * collections of the intermediate vertices <code>c</code>.</p> * * <p>This function will not create self-loops.</p> * * @param <V> vertex type * @param <E> input edge type * @param g input k-partite graph * @param p predicate specifying vertex partition * @param graph_factory factory used to create the output graph * @return the result of folding g into unipartite graph whose vertices * are those of the <code>p</code> partition of g */ public static <V, E> Graph<V, Collection<V>> foldKPartiteGraph(KPartiteGraph<V, E> g, Predicate<V> p, Factory<Graph<V, Collection<V>>> graph_factory) { Graph<V, Collection<V>> newGraph = graph_factory.create(); // get vertices for the specified partition, copy into new graph Collection<V> vertices = g.getVertices(p); for (V v : vertices) { newGraph.addVertex(v); for (V s : g.getSuccessors(v)) { for (V t : g.getSuccessors(s)) { if (!vertices.contains(t) || t.equals(v)) continue; newGraph.addVertex(t); Collection<V> v_coll = newGraph.findEdge(v, t); if (v_coll == null) { v_coll = new ArrayList<V>(); newGraph.addEdge(v_coll, v, t); } v_coll.add(s); } } } return newGraph; }
From source file:org.opendatakit.persistence.table.OdkTablesUserInfoTable.java
public static synchronized final OdkTablesUserInfoTable getOdkTablesUserInfo(String uriUser, Set<GrantedAuthority> grants, CallingContext callingContext) throws ODKDatastoreException, ODKTaskLockException, ODKEntityPersistException, ODKOverQuotaException, PermissionDeniedException { Datastore ds = callingContext.getDatastore(); OdkTablesUserInfoTable prototype = OdkTablesUserInfoTable.assertRelation(callingContext); Log log = LogFactory.getLog(FileManifestManager.class); log.info("TablesUserPermissionsImpl: " + uriUser); RoleHierarchy roleHierarchy = (RoleHierarchy) callingContext.getHierarchicalRoleRelationships(); Collection<? extends GrantedAuthority> roles = roleHierarchy.getReachableGrantedAuthorities(grants); boolean hasSynchronize = roles .contains(new SimpleGrantedAuthority(GrantedAuthorityName.ROLE_SYNCHRONIZE_TABLES.name())); boolean hasSuperUser = roles .contains(new SimpleGrantedAuthority(GrantedAuthorityName.ROLE_SUPER_USER_TABLES.name())); boolean hasAdminister = roles .contains(new SimpleGrantedAuthority(GrantedAuthorityName.ROLE_ADMINISTER_TABLES.name())); if (hasSynchronize || hasSuperUser || hasAdminister) { String uriForUser = null; String externalUID = null; if (uriUser.equals(User.ANONYMOUS_USER)) { externalUID = User.ANONYMOUS_USER; uriForUser = User.ANONYMOUS_USER; } else {/*from w ww. ja v a 2 s .c om*/ RegisteredUsersTable user = RegisteredUsersTable.getUserByUri(uriUser, ds, callingContext.getCurrentUser()); // Determine the external UID that will identify this user externalUID = null; if (user.getUsername() != null) { externalUID = SecurityConsts.USERNAME_COLON + user.getUsername(); } uriForUser = uriUser; } OdkTablesUserInfoTable odkTablesUserInfo = null; odkTablesUserInfo = OdkTablesUserInfoTable.getCurrentUserInfo(uriForUser, callingContext); if (odkTablesUserInfo == null) { // // GAIN LOCK OdkTablesLockTemplate tablesUserPermissions = new OdkTablesLockTemplate(externalUID, ODKTablesTaskLockType.TABLES_USER_PERMISSION_CREATION, OdkTablesLockTemplate.DelayStrategy.SHORT, callingContext); try { tablesUserPermissions.acquire(); // attempt to re-fetch the record. // If this succeeds, then we had multiple suitors; the other one beat // us. odkTablesUserInfo = OdkTablesUserInfoTable.getCurrentUserInfo(uriForUser, callingContext); if (odkTablesUserInfo != null) { return odkTablesUserInfo; } // otherwise, create a record odkTablesUserInfo = ds.createEntityUsingRelation(prototype, callingContext.getCurrentUser()); odkTablesUserInfo.setUriUser(uriForUser); odkTablesUserInfo.setOdkTablesUserId(externalUID); odkTablesUserInfo.persist(callingContext); return odkTablesUserInfo; } finally { tablesUserPermissions.release(); } } else { return odkTablesUserInfo; } } else { throw new PermissionDeniedException("User does not have access to ODK Tables"); } }
From source file:com.osource.base.web.interceptor.FileUploadInterceptor.java
/** * @param itemCollection - Collection of string items (all lowercase). * @param item - Item to search for. * @return true if itemCollection contains the item, false otherwise. *///from w w w. j a v a2s. co m private static boolean containsItem(Collection<String> itemCollection, String item) { return itemCollection.contains(item.toLowerCase()); }