List of usage examples for java.util Collection contains
boolean contains(Object o);
From source file:CollectionUtils.java
/** * Return <code>true</code> if any element in '<code>candidates</code>' is * contained in '<code>source</code>'; otherwise returns <code>false</code>. * @param source the source Collection// w ww. j av a 2s. c om * @param candidates the candidates to search for * @return whether any of the candidates has been found */ public static boolean containsAny(Collection source, Collection candidates) { if (isEmpty(source) || isEmpty(candidates)) { return false; } for (Iterator it = candidates.iterator(); it.hasNext();) { if (source.contains(it.next())) { return true; } } return false; }
From source file:com.shenit.commons.utils.CollectionUtils.java
/** * Check whether a value is in a collection * @param values// www.j a va 2 s .c o m * @param value * @return */ public static <T> boolean contains(Collection<T> values, T value) { return !ValidationUtils.isEmpty(values) && values.contains(value); }
From source file:Main.java
/** * Finds the best possible value out of the list of supported values * @param name name of the desired mode the values are searched for * @param supportedValues the supported values * @param desiredValues the desired values with descending priority * @return the best possible value//w w w .ja v a 2 s .com */ private static String findSettableValue(String name, Collection<String> supportedValues, String... desiredValues) { Log.i(TAG, "Requesting " + name + " value from among: " + Arrays.toString(desiredValues)); Log.i(TAG, "Supported " + name + " values: " + supportedValues); if (supportedValues != null) { for (String desiredValue : desiredValues) { if (supportedValues.contains(desiredValue)) { Log.i(TAG, "Can set " + name + " to: " + desiredValue); return desiredValue; } } } Log.i(TAG, "No supported values match"); return null; }
From source file:Main.java
public static boolean equalsSet(Collection c1, Collection c2) { boolean equals; if (c1 == null) { equals = (c2 == null);//from w w w. j ava 2 s .c o m } else if (c2 == null) { equals = false; } else if (c1.size() == c2.size()) { equals = true; Iterator iterC1 = c1.iterator(); while (equals && iterC1.hasNext()) { Object o1 = iterC1.next(); equals = c2.contains(o1); } } else { equals = false; } return equals; }
From source file:Main.java
private static String findSettableValue(String name, Collection<String> supportedValues, String... desiredValues) { // Log.i(TAG, "Requesting " + name + " value from among: " + Arrays.toString(desiredValues)); // Log.i(TAG, "Supported " + name + " values: " + supportedValues); if (supportedValues != null) { for (String desiredValue : desiredValues) { if (supportedValues.contains(desiredValue)) { // Log.i(TAG, "Can set " + name + " to: " + desiredValue); return desiredValue; }//from w ww . ja v a2 s . c o m } } // Log.i(TAG, "No supported values match"); return null; }
From source file:com.activegrid.runtime.data.util.DataServiceUtils.java
public static Object mergeForUpdate(Object source, Session session, DataServiceMetaData metaData, Collection<String> populatedProperties) { // load instance from db, and copy in values from client // ensure id has been set String idPropName = metaData.getIdPropertyName(source.getClass()); if (!populatedProperties.contains(idPropName)) { throw new DataServiceRuntimeException("id property \"" + idPropName + "\" must be set"); }/*from www . j a va 2s .c om*/ Object rtn = loadById(source, session, metaData); if (rtn == null) { throw new DataServiceRuntimeException("Failed to load instance to update"); } // add optimistic concurrency check here Collection<String> relatedPropertyNames = metaData.getRelPropertyNames(source.getClass()); Collection<String> handledPropertyPrefixes = new HashSet<String>(); for (String propertyName : populatedProperties) { int i = propertyName.indexOf(DataServiceConstants.PROP_SEP); if (i != -1) { propertyName = propertyName.substring(0, i); } if (handledPropertyPrefixes.contains(propertyName)) { continue; } Object clientValue = objectAccess.getProperty(source, propertyName); if (relatedPropertyNames.contains(propertyName)) { if (isRelatedMany(objectAccess.getPropertyType(source.getClass(), propertyName))) { continue; } handledPropertyPrefixes.add(propertyName); if (clientValue != null) { String prefix = propertyName + DataServiceConstants.PROP_SEP; List<String> populatedPropertiesForRelated = StringUtils .getItemsStartingWith(populatedProperties, prefix, true); clientValue = mergeForUpdate(clientValue, session, metaData, populatedPropertiesForRelated); } } objectAccess.setProperty(rtn, propertyName, clientValue); } return rtn; }
From source file:Main.java
public static String findSettableValue(String name, Collection<String> supportedValues, String... desiredValues) { Log.i(TAG, "Requesting " + name + " value from among: " + Arrays.toString(desiredValues)); Log.i(TAG, "Supported " + name + " values: " + supportedValues); if (supportedValues != null) { for (String desiredValue : desiredValues) { if (supportedValues.contains(desiredValue)) { Log.i(TAG, "Can set " + name + " to: " + desiredValue); return desiredValue; }/* w ww . ja v a 2 s . co m*/ } } Log.i(TAG, "No supported values match"); return null; }
From source file:at.jps.sanction.core.util.TokenTool.java
/** * @param list1/* w ww . j ava 2s . c o m*/ * ( uppercase entries presumed ! ) * @param list2 * @return number of elements contained in both lists */ public static int compareTokenLists(final Collection<String> list1, final Collection<String> list2) { int count = 0; for (final String element : list2) { if (list1.contains(element.toUpperCase())) { count++; } } return count; }
From source file:com.nextep.datadesigner.vcs.impl.VersionableSorter.java
private static void processItem(List<IVersionable<?>> sortedList, Map<IReference, IVersionable<?>> invRefMap, IVersionable<?> toAdd, Collection<IVersionable<?>> stack) { Collection<IReference> refs = toAdd.getReferenceDependencies(); Collection<IReference> ownReferences = toAdd.getReferenceMap().keySet(); // If the stack already contains the versionable to add, dependency deadloop ! // We stop the process here if (stack.contains(toAdd)) { log.warn("Deadloop found in schema inner dependencies: unsafe dependency resolution."); return;/* w w w.j a va2 s .c o m*/ } stack.add(toAdd); for (IReference r : refs) { final IVersionable<?> v = invRefMap.get(r); if (v != null && !sortedList.contains(v) && !ownReferences.contains(r) && toAdd.getReference() != r) { processItem(sortedList, invRefMap, v, stack); } } stack.remove(toAdd); // Might have already been imported if (!sortedList.contains(toAdd)) { sortedList.add(toAdd); } }
From source file:Main.java
private static String findSettableValue(String name, Collection<String> supportedValues, String... desiredValues) { Log.i(TAG, "Requesting " + name + " value from among: " + Arrays.toString(desiredValues)); Log.i(TAG, "Supported " + name + " values: " + supportedValues); if (supportedValues != null) { for (String desiredValue : desiredValues) { if (supportedValues.contains(desiredValue)) { Log.i(TAG, "Can set " + name + " to: " + desiredValue); return desiredValue; }//ww w. j a v a 2s . c om } } Log.i(TAG, "No supported values match"); return null; }