List of usage examples for java.util Set contains
boolean contains(Object o);
From source file:Main.java
/** * Returns an array of values as a union set of the two input arrays. * * @param <T>//from w w w . j av a 2s. c o m * @param values * @param newValues * @return the union of the two arrays */ @Deprecated public static <T> T[] addWithoutDuplicates(T[] values, T[] newValues) { Set<T> originals = new HashSet<>(values.length); for (T value : values) { originals.add(value); } List<T> newOnes = new ArrayList<>(newValues.length); for (T value : newValues) { if (originals.contains(value)) { continue; } newOnes.add(value); } T[] largerOne = (T[]) Array.newInstance(values.getClass().getComponentType(), values.length + newOnes.size()); System.arraycopy(values, 0, largerOne, 0, values.length); for (int i = values.length; i < largerOne.length; i++) { largerOne[i] = newOnes.get(i - values.length); } return largerOne; }
From source file:Main.java
/** * @param orig//from ww w .ja va 2s . c om * if null, return intersect */ public static Set<? extends Object> intersectSet(Set<? extends Object> orig, Set<? extends Object> intersect) { if (orig == null) return intersect; if (intersect == null || orig.isEmpty()) return Collections.emptySet(); Set<Object> set = new HashSet<Object>(orig.size()); for (Object p : orig) { if (intersect.contains(p)) set.add(p); } return set; }
From source file:io.wcm.wcm.commons.util.RunMode.java
/** * Checks if given run mode is active.//from w w w . jav a2 s . c o m * @param runModes Run modes for current instance * @param expectedRunModes Run mode(s) to check for * @return true if any of the given run modes is active */ public static boolean is(Set<String> runModes, String... expectedRunModes) { if (runModes != null && expectedRunModes != null) { for (String expectedRunMode : expectedRunModes) { if (runModes.contains(expectedRunMode)) { return true; } } } return false; }
From source file:com.zimbra.cs.service.util.ItemDataFile.java
static boolean skip(Set<MailItem.Type> types, MailItem.Type type) { return types != null && !types.contains(type); }
From source file:de.cgarbs.lib.json.JSONDataModel.java
/** * Copies the JSON data to the DataModel's attributs. * @param model the DataModel to write to * @param json the parsed JSON data to read * @throws JSONException when there is an error during the JSON conversion * @throws DataException when there is an error setting a value in die DataModel *///from w w w. j a v a2 s .c o m static void readFromJSON(final DataModel model, final Object json) throws JSONException, DataException { if (!(json instanceof Map)) { throw newJSONToJavaError("root element is no map"); } final Map<String, Object> jsonMap = (Map<String, Object>) json; final Object identifier = jsonMap.get(IDENTIFIER_FIELD); final Object version = jsonMap.get(VERSION_FIELD); final Object attributes = jsonMap.get(ATTRIBUTE_FIELD); // check null if (identifier == null) { throw newJSONToJavaError("identifier [" + IDENTIFIER_FIELD + "] is missing"); } if (version == null) { throw newJSONToJavaError("version [" + VERSION_FIELD + "] is missing"); } if (attributes == null) { throw newJSONToJavaError("attributes [" + ATTRIBUTE_FIELD + "] are missing"); } // check values if (!IDENTIFIER.equals(identifier)) { throw newJSONToJavaError("wrong identifier [" + IDENTIFIER_FIELD + "]: expected <" + IDENTIFIER + ">, but got <" + identifier.toString() + ">"); } if (!VERSION.equals(version)) { throw newJSONToJavaError("wrong version [" + VERSION_FIELD + "]: expected <" + VERSION + ">, but got <" + version.toString() + ">"); } if (!(attributes instanceof Map)) { throw newJSONToJavaError("wrong attributes [" + ATTRIBUTE_FIELD + "]: expected a <Map> but got a <" + attributes.getClass().toString() + ">"); } final Map<String, Object> attributeMap = (Map<String, Object>) attributes; final Set<String> validAttributes = model.getAttributeKeys(); for (final String key : attributeMap.keySet()) { if (validAttributes.contains(key)) { model.setValue(key, JSONAdapter.prepareForJava(attributeMap.get(key))); } } }
From source file:de.monticore.io.paths.IterablePath.java
/** * Creates a {@link Predicate} for (e.g.) filtering {@link Path} elements by the specified set of * file extensions./*w ww.j ava 2 s. co m*/ * * @param extensions * @return */ protected static Predicate<Path> getExtensionsPredicate(Set<String> extensions) { return path -> extensions.contains(FilenameUtils.getExtension(path.toString())); }
From source file:org.cloudfoundry.identity.uaa.login.test.ProfileActiveUtils.java
private static boolean isTestEnabledInThisEnvironment(ProfileValueSource profileValueSource, IfProfileActive ifProfileActive, UnlessProfileActive unlessProfileActive) { if (ifProfileActive == null && unlessProfileActive == null) { return true; }//from w w w .ja v a2 s . c o m List<String> blacklist = getBlacklist(unlessProfileActive); Set<String> activeProfiles = StringUtils .commaDelimitedListToSet(profileValueSource.get("spring.profiles.active")); boolean enabled = true; if (ifProfileActive != null && StringUtils.hasText(ifProfileActive.value())) { enabled = activeProfiles.contains(ifProfileActive.value()); } for (String profile : blacklist) { if (activeProfiles.contains(profile)) { enabled = false; continue; } } return enabled; }
From source file:br.com.suricattus.surispring.spring.security.util.SecurityUtil.java
/** * Method that checks if the user holds <b>any</b> of the given roles. * Returns <code>true, when the first match is found, <code>false</code> if * no match is found and also <code>false</code> if no roles are given * // www. j a v a2s . c o m * @param grantedRoles a comma seperated list of roles * @return true if any of the given roles are granted to the current user, false otherwise */ public static boolean hasAnyRole(final String grantedRoles) { Set<String> parsedAuthorities = parseAuthorities(grantedRoles); if (parsedAuthorities.isEmpty()) return false; Set<String> userAuthorities = getUserAuthorities(); for (String ga : parsedAuthorities) { if (userAuthorities.contains(ga)) return true; } return false; }
From source file:com.github.pmerienne.cf.testing.dataset.DatasetUtils.java
public static List<Rating> extractEval(List<Rating> ratings, double trainingPercent) { int evalSize = (int) (ratings.size() * (1.0 - trainingPercent)); List<Rating> eval = new ArrayList<>(evalSize); Set<Long> knownUsers = new HashSet<>(); Set<Long> knownItems = new HashSet<>(); Iterator<Rating> it = ratings.iterator(); while (it.hasNext() && eval.size() < evalSize) { Rating rating = it.next();/*from w w w .j a v a 2s .c om*/ if (knownUsers.contains(rating.i) && knownItems.contains(rating.j)) { eval.add(rating); it.remove(); } knownUsers.add(rating.i); knownItems.add(rating.j); } return eval; }
From source file:com.arpnetworking.jackson.BuilderDeserializer.java
private static void addTo(final Set<Type> visited, final Map<Class<?>, JsonDeserializer<?>> deserializerMap, final Type targetType) { if (visited.contains(targetType)) { return;/* w ww . j av a 2s . c o m*/ } visited.add(targetType); if (targetType instanceof Class<?>) { @SuppressWarnings("unchecked") final Class<Object> targetClass = (Class<Object>) targetType; try { // Look-up and register the builder for this class final Class<? extends Builder<? extends Object>> builderClass = getBuilderForClass(targetClass); deserializerMap.put(targetClass, BuilderDeserializer.of(builderClass)); LOGGER.info("Registered builder for class; builderClass=" + builderClass + " targetClass=" + targetClass); // Process all setters on the builder for (final Method method : builderClass.getMethods()) { if (isSetterMethod(builderClass, method)) { final Type setterArgumentType = method.getGenericParameterTypes()[0]; // Recursively register builders for each setter's type addTo(visited, deserializerMap, setterArgumentType); } } } catch (final ClassNotFoundException e) { // Log that the class is not build-able LOGGER.debug("Ignoring class without builder; targetClass=" + targetClass); } // Support for JsonSubTypes annotation if (targetClass.isAnnotationPresent(JsonSubTypes.class)) { final JsonSubTypes.Type[] subTypes = targetClass.getAnnotation(JsonSubTypes.class).value(); for (final JsonSubTypes.Type subType : subTypes) { addTo(visited, deserializerMap, subType.value()); } } // Support for JsonTypeInfo annotation // TODO(vkoskela): Support JsonTypeInfo classpath scan [MAI-116] } if (targetType instanceof ParameterizedType) { // Recursively register builders for each parameterized type final ParameterizedType targetParameterizedType = (ParameterizedType) targetType; final Type rawType = targetParameterizedType.getRawType(); addTo(visited, deserializerMap, rawType); for (final Type argumentActualType : targetParameterizedType.getActualTypeArguments()) { addTo(visited, deserializerMap, argumentActualType); } } }