List of usage examples for com.google.common.collect Iterables isEmpty
public static boolean isEmpty(Iterable<?> iterable)
From source file:com.google.devtools.build.lib.skyframe.SkyframeLabelVisitorTestCase.java
/** * Returns the set of labels that were visited in the loading of the given starting labels. * Semantics are somewhat subtle in case of errors. The returned set always contains the starting * labels, even if they were not successfully loaded, but does not contain other unsuccessfully * loaded targets.//from w w w.jav a2s . c o m */ public static Set<Label> getVisitedLabels(Iterable<Label> startingLabels, SkyframeExecutor skyframeExecutor) throws InterruptedException { final WalkableGraph graph = new DelegatingWalkableGraph( ((InMemoryMemoizingEvaluator) skyframeExecutor.getEvaluatorForTesting()).getGraphForTesting()); List<SkyKey> startingKeys = new ArrayList<>(); for (Label label : startingLabels) { startingKeys.add(TransitiveTargetValue.key(label)); } Iterable<SkyKey> nodesToVisit = new ArrayList<>(startingKeys); Set<SkyKey> visitedNodes = new HashSet<>(); while (!Iterables.isEmpty(nodesToVisit)) { List<SkyKey> existingNodes = new ArrayList<>(); for (SkyKey key : nodesToVisit) { if (exists(key, graph) && graph.getValue(key) != null && visitedNodes.add(key)) { existingNodes.add(key); } } nodesToVisit = Iterables.filter(Iterables.concat(graph.getDirectDeps(existingNodes).values()), new Predicate<SkyKey>() { @Override public boolean apply(SkyKey skyKey) { return skyKey.functionName().equals(SkyFunctions.TRANSITIVE_TARGET); } }); } visitedNodes.addAll(startingKeys); return ImmutableSet.copyOf(Collections2.transform(visitedNodes, new Function<SkyKey, Label>() { @Override public Label apply(SkyKey skyKey) { return (Label) skyKey.argument(); } })); }
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); }/*from w w w . j a va2 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:com.facebook.presto.sql.ExpressionUtils.java
public static Function<Expression, Expression> expressionOrNullSymbols( final Predicate<Symbol>... nullSymbolScopes) { return expression -> { ImmutableList.Builder<Expression> resultDisjunct = ImmutableList.builder(); resultDisjunct.add(expression);/*from w w w. ja va 2 s.c om*/ for (Predicate<Symbol> nullSymbolScope : nullSymbolScopes) { Iterable<Symbol> symbols = filter(DependencyExtractor.extractUnique(expression), nullSymbolScope); if (Iterables.isEmpty(symbols)) { continue; } ImmutableList.Builder<Expression> nullConjuncts = ImmutableList.builder(); for (Symbol symbol : symbols) { nullConjuncts.add(new IsNullPredicate(new QualifiedNameReference(symbol.toQualifiedName()))); } resultDisjunct.add(and(nullConjuncts.build())); } return or(resultDisjunct.build()); }; }
From source file:eu.interedition.text.repository.JdbcStore.java
@Override public void deleteTexts(Iterable<Long> ids) { if (Iterables.isEmpty(ids)) { return;/* www. j a v a 2 s . c o m*/ } ResultSet rs = null; try { final Long[] idArray = Iterables.toArray(ids, Long.class); final List<Long> annotationIds = Lists.newLinkedList(); if (selectAnnotationsByTexts == null) { selectAnnotationsByTexts = connection .prepareStatement("select distinct at.annotation_id " + "from table(id bigint = ?) text " + "join interedition_text_annotation_target at on text.id = at.text_id"); } selectAnnotationsByTexts.setObject(1, idArray); rs = selectAnnotationsByTexts.executeQuery(); while (rs.next()) { annotationIds.add(rs.getLong(1)); } deleteAnnotations(annotationIds); if (deleteTexts == null) { deleteTexts = connection.prepareStatement("delete from interedition_text where id in " + "(select id from table(id bigint = ?) text)"); } deleteTexts.setObject(1, idArray); deleteTexts.executeUpdate(); txLog.textsRemoved(idArray); } catch (SQLException e) { throw Throwables.propagate(e); } finally { Database.closeQuietly(rs); } }
From source file:org.apache.aurora.scheduler.http.api.security.ShiroAuthorizingParamInterceptor.java
private static Iterable<JobKeyGetter> annotatedParameterGetters(Method method) { for (Method candidateMethod : getCandidateMethods(method)) { Parameter[] parameters = candidateMethod.getParameters(); ImmutableList.Builder<JobKeyGetter> jobKeyGetters = ImmutableList.builder(); for (int i = 0; i < parameters.length; i++) { Parameter param = parameters[i]; if (param.isAnnotationPresent(AuthorizingParam.class)) { Class<?> parameterType = param.getType(); @SuppressWarnings("unchecked") Optional<Function<Object, Optional<JobKey>>> jobKeyGetter = Optional.fromNullable( (Function<Object, Optional<JobKey>>) FIELD_GETTERS_BY_TYPE.get(parameterType)); if (!jobKeyGetter.isPresent()) { throw new UnsupportedOperationException("No " + JobKey.class.getName() + " field getter was supplied for " + parameterType.getName()); }//from w ww . j a va 2 s . co m jobKeyGetters.add(new JobKeyGetter(i, jobKeyGetter.get())); } } ImmutableList<JobKeyGetter> getters = jobKeyGetters.build(); if (!Iterables.isEmpty(getters)) { return getters; } } throw new UnsupportedOperationException("No parameter annotated with " + AuthorizingParam.class.getName() + " found on method " + method.getName() + " of " + method.getDeclaringClass().getName() + " or any of its superclasses."); }
From source file:org.eclipse.xtext.linking.lazy.LazyLinker.java
/** * @since 2.4 */ protected boolean hasLeafNodes(INode node) { return !Iterables.isEmpty(node.getLeafNodes()); }
From source file:org.jboss.as.console.client.v3.widgets.SuggestionResource.java
private void verifyTemplates(final Iterable<AddressTemplate> templates) { if (Iterables.isEmpty(templates)) { throw new IllegalArgumentException("Templates must not be empty in SuggestionResource,"); }//from w w w . java 2 s . c o m }
From source file:fr.inria.atlanmod.neoemf.data.blueprints.store.DirectWriteBlueprintsStore.java
@Override protected boolean isSetReference(PersistentEObject object, EReference eReference) { boolean returnValue = false; Vertex vertex = persistenceBackend.getVertex(object.id()); if (nonNull(vertex)) { returnValue = !Iterables.isEmpty(vertex.getVertices(Direction.OUT, eReference.getName())); }// ww w. ja va 2 s. co m return returnValue; }
From source file:org.cloudsmith.geppetto.pp.dsl.ui.editor.findrefs.ReferenceSearchResultContentProvider.java
public void descriptionsChanged(final Event event) { Display.getDefault().asyncExec(new Runnable() { public void run() { if (rootNodes != null) { for (Delta delta : event.getDeltas()) { if (!(delta.getNew() instanceof StatefulResourceDescription)) { for (Iterator<ReferenceSearchViewTreeNode> i = rootNodes.iterator(); i.hasNext();) { ReferenceSearchViewTreeNode rootNode = i.next(); if (((IResourceDescription) rootNode.getDescription()).getURI() .equals(delta.getUri())) { if (delta.getNew() == null) { i.remove(); viewer.remove(rootNode); break; }//from w w w. j a v a2 s . c o m Iterable<IReferenceDescription> newReferenceDescriptions = delta.getNew() .getReferenceDescriptions(); List<ReferenceSearchViewTreeNode> removedReferenceNodes = Lists.newArrayList(); for (ReferenceSearchViewTreeNode referenceNode : rootNode.getChildren()) { final IReferenceDescription refDesc = ((IReferenceDescription) referenceNode .getDescription()); final URI referenceSourceURI = refDesc.getSourceEObjectUri(); final URI referenceTargetURI = refDesc.getTargetEObjectUri(); if (Iterables.isEmpty(Iterables.filter(newReferenceDescriptions, new Predicate<IReferenceDescription>() { public boolean apply(IReferenceDescription input) { return input.getSourceEObjectUri() .equals(referenceSourceURI) && input.getTargetEObjectUri() .equals(referenceTargetURI); } }))) { removedReferenceNodes.add(referenceNode); } } for (ReferenceSearchViewTreeNode removedReferenceNode : removedReferenceNodes) { rootNode.removeChild(removedReferenceNode); } if (rootNode.getChildren().isEmpty()) { i.remove(); viewer.remove(rootNode); break; } viewer.remove(rootNode, Iterables.toArray(removedReferenceNodes, ReferenceSearchViewTreeNode.class)); } } } } } } }); }
From source file:com.github.rinde.rinsim.event.EventDispatcher.java
/** * {@inheritDoc}/*w w w .j a va2 s. c o m*/ */ @Override public void removeListener(Listener listener, Iterable<? extends Enum<?>> eventTypes) { synchronized (listeners) { if (Iterables.isEmpty(eventTypes)) { // remove all store keys in intermediate set to avoid concurrent // modifications final Set<Enum<?>> keys = new HashSet<>(listeners.keySet()); for (final Enum<?> eventType : keys) { if (listeners.containsEntry(eventType, listener)) { removeListener(listener, eventType); } } } else { for (final Enum<?> eventType : eventTypes) { checkNotNull(eventType, "event type to remove can not be null"); checkArgument(containsListener(listener, eventType), "The listener %s for the type %s cannot be removed because it " + "does not exist.", listener, eventType); if (dispatching.get() == 0) { listeners.remove(eventType, listener); } else { toRemove.put(eventType, listener); } } } } }