List of usage examples for com.google.common.collect Iterables any
public static <T> boolean any(Iterable<T> iterable, Predicate<? super T> predicate)
From source file:org.eclipse.sirius.diagram.sequence.ui.tool.internal.edit.validator.AbstractInteractionFrameValidator.java
/** * Performs all the computations required to validate the resizing, and * stores any important information which will be useful to actually execute * the resize if it is valid, like for example avoid contact with siblings. */// w w w. j a v a2s . com protected void validate() { valid = checkAndComputeRanges(); if (valid) { Collection<ISequenceEvent> finalParents = getFinalParentsWithAutoExpand(); Collection<ISequenceEvent> movableParents = Lists .newArrayList(Iterables.filter(finalParents, Predicates.not(unMove))); Collection<ISequenceEvent> fixedParents = Lists.newArrayList(Iterables.filter(finalParents, unMove)); if (movableParents.isEmpty() || !movedElements.containsAll(movableParents)) { valid = valid && Iterables.isEmpty(Iterables.filter(finalParents, invalidParents)); valid = valid && (!Iterables.any(finalParents, Predicates.instanceOf(Operand.class)) || finalParents.size() == 1); valid = valid && checkFinalRangeStrictlyIncludedInParents(movableParents); valid = valid && checkLocalSiblings(movableParents); } valid = valid && checkFinalRangeStrictlyIncludedInParents(fixedParents); valid = valid && checkLocalSiblings(fixedParents); } if (getRequestQuery().isResize()) { valid = valid && checkGlobalPositions(); } }
From source file:com.eucalyptus.cloudformation.resources.standard.TagHelper.java
public static void checkReservedEC2TemplateTags(List<EC2Tag> tags) throws ValidationErrorException { if (tags == null) return;//from w ww .j a v a 2 s . c o m List<String> tagNames = Lists.newArrayList(); for (EC2Tag tag : tags) { if (Iterables.any(reservedPrefixes, Strings.isPrefixOf(tag.getKey()))) { throw new ValidationErrorException( "Tag " + tag.getKey() + " uses a reserved prefix " + reservedPrefixes); } } }
From source file:com.isotrol.impe3.api.DevicesInPortal.java
/** * Filters the collection by device name use. * @param use Use to filter./*from w w w . j a v a2 s . c o m*/ * @return The filtered collection. */ public final DevicesInPortal filterByUse(DeviceNameUse use) { checkNotNull(use, "Device name use"); Predicate<DeviceInPortal> f = Predicates.compose(equalTo(use), DeviceInPortal.USE); if (Iterables.any(values(), f)) { return new Filter(this, f); } else { return EMPTY; } }
From source file:org.eclipse.xtend.core.jvmmodel.DispatchHelper.java
public boolean isDispatcherFunction(JvmOperation inferredOperation) { return Iterables.any(inferredOperation.eAdapters(), new Predicate<Object>() { @Override/*from w ww . j a v a2 s . co m*/ public boolean apply(Object input) { return input instanceof DispatcherMarker; } }); }
From source file:org.robotframework.ide.eclipse.main.plugin.model.RobotCodeHoldingElement.java
public boolean hasSettings() { return Iterables.any(calls, instanceOf(RobotDefinitionSetting.class)); }
From source file:org.terasology.manualLabor.processParts.ShapedBlockInputProcessPartCommonSystem.java
@ReceiveEvent public void validateInventoryItem(ProcessEntityIsInvalidForInventoryItemEvent event, EntityRef processEntity, ShapedBlockInputComponent shapedBlockInputComponent) { if (WorkstationInventoryUtils .getAssignedInputSlots(event.getWorkstation(), InventoryInputProcessPartCommonSystem.WORKSTATIONINPUTCATEGORY) .contains(event.getSlotNo()) && !Iterables.any(getInputItemsFilter(shapedBlockInputComponent).keySet(), x -> x.apply(event.getItem()))) { event.consume();// ww w . j ava2 s. c o m } }
From source file:org.gradle.model.internal.manage.schema.extract.ManagedImplTypeSchemaExtractionStrategySupport.java
public <R> ModelSchemaExtractionResult<R> extract(final ModelSchemaExtractionContext<R> extractionContext, ModelSchemaStore store, final ModelSchemaCache cache) { ModelType<R> type = extractionContext.getType(); Class<? super R> clazz = type.getRawClass(); if (isTarget(type)) { validateType(type, extractionContext); Iterable<Method> methods = Arrays.asList(clazz.getMethods()); if (!clazz.isInterface()) { methods = filterIgnoredMethods(methods); }// ww w . j av a 2 s . c o m ImmutableListMultimap<String, Method> methodsByName = Multimaps.index(methods, new Function<Method, String>() { public String apply(Method method) { return method.getName(); } }); ensureNoOverloadedMethods(extractionContext, methodsByName); List<ModelProperty<?>> properties = Lists.newLinkedList(); List<Method> handled = Lists.newArrayListWithCapacity(clazz.getMethods().length); ReturnTypeSpecializationOrdering returnTypeSpecializationOrdering = new ReturnTypeSpecializationOrdering(); for (String methodName : methodsByName.keySet()) { if (methodName.startsWith("get") && !methodName.equals("get")) { ImmutableList<Method> getterMethods = methodsByName.get(methodName); // The overload check earlier verified that all methods for are equivalent for our purposes // So, taking the first one with the most specialized return type is fine. Method sampleMethod = returnTypeSpecializationOrdering.max(getterMethods); boolean abstractGetter = Modifier.isAbstract(sampleMethod.getModifiers()); if (sampleMethod.getParameterTypes().length != 0) { throw invalidMethod(extractionContext, "getter methods cannot take parameters", sampleMethod); } Character getterPropertyNameFirstChar = methodName.charAt(3); if (!Character.isUpperCase(getterPropertyNameFirstChar)) { throw invalidMethod(extractionContext, "the 4th character of the getter method name must be an uppercase character", sampleMethod); } ModelType<?> returnType = ModelType.returnType(sampleMethod); String propertyNameCapitalized = methodName.substring(3); String propertyName = StringUtils.uncapitalize(propertyNameCapitalized); String setterName = "set" + propertyNameCapitalized; ImmutableList<Method> setterMethods = methodsByName.get(setterName); boolean isWritable = !setterMethods.isEmpty(); if (isWritable) { Method setter = setterMethods.get(0); if (!abstractGetter) { throw invalidMethod(extractionContext, "setters are not allowed for non-abstract getters", setter); } validateSetter(extractionContext, returnType, setter); handled.addAll(setterMethods); } if (abstractGetter) { ImmutableSet<ModelType<?>> declaringClasses = ImmutableSet .copyOf(Iterables.transform(getterMethods, new Function<Method, ModelType<?>>() { public ModelType<?> apply(Method input) { return ModelType.of(input.getDeclaringClass()); } })); boolean unmanaged = Iterables.any(getterMethods, new Predicate<Method>() { public boolean apply(Method input) { return input.getAnnotation(Unmanaged.class) != null; } }); properties.add(ModelProperty.of(returnType, propertyName, isWritable, declaringClasses, unmanaged)); } handled.addAll(getterMethods); } } Iterable<Method> notHandled = Iterables.filter(methodsByName.values(), Predicates.not(Predicates.in(handled))); // TODO - should call out valid getters without setters if (!Iterables.isEmpty(notHandled)) { throw invalidMethods(extractionContext, "only paired getter/setter methods are supported", notHandled); } Class<R> concreteClass = type.getConcreteClass(); final ModelSchema<R> schema = createSchema(extractionContext, store, type, properties, concreteClass); Iterable<ModelSchemaExtractionContext<?>> propertyDependencies = Iterables.transform(properties, new Function<ModelProperty<?>, ModelSchemaExtractionContext<?>>() { public ModelSchemaExtractionContext<?> apply(final ModelProperty<?> property) { return toPropertyExtractionContext(extractionContext, property, cache); } }); return new ModelSchemaExtractionResult<R>(schema, propertyDependencies); } else { return null; } }
From source file:org.netbeans.modules.android.grammars.AndroidLayoutGrammar.java
private void addAttrNames(String name, String prefix, NamedNodeMap existingAttributes, List<GrammarResult> list) { SortedMap<String, StyleableInfo> styleables = model.getStyleables(); StyleableInfo elementData = styleables != null ? styleables.get(name) : null; List<AttributeInfo> possibleAttributes = elementData != null ? elementData.getAttributeNames() : Lists.<AttributeInfo>newArrayList(); for (AttributeInfo attribute : possibleAttributes) { final String attrName = attribute.getName(); if (attribute.getName().startsWith(prefix) && existingAttributes.getNamedItem(attribute.getName()) == null && !Iterables.any(list, new Predicate<GrammarResult>() { @Override/*w w w .j a v a 2s .c o m*/ public boolean apply(GrammarResult input) { return input.getNodeName().equals(attrName); } })) { list.add(new SimpleAttr(attrName, attribute.getDescription())); } } }
From source file:me.emmy.db.MySQLLayer.java
private boolean tableExists() { // InputStream stream = MySQLLayer.class // .getResourceAsStream("/verifyTable.sql"); // String sql = String.format(new Scanner(stream).useDelimiter("\\A") // .next(), schema, playerTable.name()); boolean exists = Iterables.any(jdbc.query("show tables", StringMapper.instance), Predicates.equalTo(playerTable.name())); return exists; }
From source file:fr.aliacom.obm.utils.HelperServiceImpl.java
@Override public boolean attendeesContainsUser(List<Attendee> attendees, AccessToken token) { final String email = token.getUserEmail(); return Iterables.any(attendees, new Predicate<Attendee>() { @Override/* ww w.java 2 s.c o m*/ public boolean apply(Attendee attendee) { return attendee.getEmail().equalsIgnoreCase(email); } }); }