Example usage for com.google.common.collect Iterables isEmpty

List of usage examples for com.google.common.collect Iterables isEmpty

Introduction

In this page you can find the example usage for com.google.common.collect Iterables isEmpty.

Prototype

public static boolean isEmpty(Iterable<?> iterable) 

Source Link

Document

Determines if the given iterable contains no elements.

Usage

From source file:org.apache.flex.compiler.internal.targets.AppSWFTarget.java

@Override
protected Iterable<ICompilerProblem> computeFatalProblems() throws InterruptedException {
    final Iterable<ICompilerProblem> fatalProblemsFromSuper = super.computeFatalProblems();
    if (!Iterables.isEmpty(fatalProblemsFromSuper))
        return fatalProblemsFromSuper;

    IResolvedQualifiersReference rootClassRef = getRootClassReference();
    if (rootClassRef == null)
        return ImmutableList.<ICompilerProblem>of(new ImproperlyConfiguredTargetProblem());

    String rootClassFileName = targetSettings.getRootSourceFileName();
    if (rootClassFileName == null)
        return ImmutableList.<ICompilerProblem>of(new ImproperlyConfiguredTargetProblem());

    Collection<ICompilationUnit> rootClassCompilationUnits = project.getCompilationUnits(rootClassFileName);
    assert rootClassCompilationUnits.isEmpty() || rootClassCompilationUnits.size() == 1;
    if (rootClassCompilationUnits.isEmpty())
        return ImmutableList.<ICompilerProblem>of(new FileNotFoundProblem(rootClassFileName));

    assert Iterables.getOnlyElement(
            rootClassCompilationUnits) != null : "The build should have been aborted before this point if there is no root class compilation unit.";

    IDefinition rootClassDefinition = rootClassRef.resolve(project);
    if (rootClassDefinition == null)
        return ImmutableList.<ICompilerProblem>of(
                new UnableToFindRootClassDefinitionProblem(targetSettings.getRootClassName()));

    return ImmutableList.<ICompilerProblem>of();
}

From source file:ezbake.data.graph.blueprints.visibility.VisibilityFilterElement.java

/**
 * Return true if the element's context has permission to remove the
 * element./* w ww. j  ava  2  s .  c om*/
 *
 * An element is removable if it and all of its property values are
 * writable.
 *
 * @return true if the element's context has permission to remove the
 * element
 */
protected boolean isRemovable() {
    if (!hasAnyPermission(Permission.WRITE)) {
        return false;
    }

    // Check that all of the properties are removable. We can remove the element only if we can remove all of its
    // properties.
    Set<String> propertyKeys = element.getPropertyKeys();
    for (String k : propertyKeys) {
        if (!isVisibilityKey(k)) {
            List<Map<String, Object>> values = element.getProperty(k);

            if (!Iterables.isEmpty(context.getPropertyFilter().reject(values, Permission.WRITE))) {
                return false;
            }
        }
    }

    return true;
}

From source file:ezbake.data.graph.blueprints.visibility.VisibilityFilterQuery.java

private <T extends Element> Predicate<T> hasKeyPredicate(final String key) {
    return new Predicate<T>() {
        @Override//from  w  ww  . j a  va  2  s . co m
        public boolean apply(T element) {
            Iterable<Map<String, Object>> values = permissionContext.getPropertyFilter()
                    .filter(element.getProperty(key), Permission.DISCOVER, Permission.READ);

            return values != null && !Iterables.isEmpty(values);
        }
    };
}

From source file:com.google.cloud.dataflow.sdk.coders.CoderProperties.java

/**
 * Verifies that for the given {@link Coder Coder<Iterable<T>>},
 * and value of type {@code Iterable<T>}, encoding followed by decoding yields an
 * equal value of type {@code Collection<T>}, in the given {@link Coder.Context}.
 *///from   ww  w .j  a v  a  2  s .  co  m
@SuppressWarnings("unchecked")
public static <T, IT extends Iterable<T>> void coderDecodeEncodeContentsInSameOrderInContext(Coder<IT> coder,
        Coder.Context context, IT value) throws Exception {
    Iterable<T> result = decodeEncode(coder, context, value);
    // Matchers.contains() requires at least one element
    if (Iterables.isEmpty(value)) {
        assertThat(result, emptyIterable());
    } else {
        // This is the only Matchers.contains() overload that takes literal values
        assertThat(result, contains((T[]) Iterables.toArray(value, Object.class)));
    }
}

From source file:com.tngtech.archunit.core.domain.JavaClasses.java

static JavaClasses of(Iterable<JavaClass> classes) {
    Map<String, JavaClass> mapping = new HashMap<>();
    for (JavaClass clazz : classes) {
        mapping.put(clazz.getName(), clazz);
    }/*from  w  w w  .  java2  s. co m*/
    JavaPackage defaultPackage = !Iterables.isEmpty(classes) ? getRoot(classes.iterator().next().getPackage())
            : JavaPackage.from(classes);
    return new JavaClasses(defaultPackage, mapping);
}

From source file:com.groupon.jenkins.buildtype.install_packages.InstallPackagesBuild.java

private Result runMultiConfigbuildRunner(final DynamicBuild dynamicBuild,
        final BuildConfiguration buildConfiguration, final BuildListener listener, Launcher launcher)
        throws InterruptedException, IOException {
    SubBuildScheduler subBuildScheduler = new SubBuildScheduler(dynamicBuild, this,
            new SubBuildScheduler.SubBuildFinishListener() {
                @Override/*w w w  .java  2  s  .com*/
                public void runFinished(DynamicSubBuild subBuild) throws IOException {
                    for (DotCiPluginAdapter plugin : buildConfiguration.getPlugins()) {
                        plugin.runFinished(subBuild, dynamicBuild, listener);
                    }
                }
            });

    try {
        Iterable<Combination> axisList = getAxisList(buildConfiguration).list();
        Result combinedResult = subBuildScheduler.runSubBuilds(getMainRunCombinations(axisList), listener);
        if (combinedResult.equals(Result.SUCCESS) && !Iterables.isEmpty(getPostBuildCombination(axisList))) {
            Result runSubBuildResults = subBuildScheduler.runSubBuilds(getPostBuildCombination(axisList),
                    listener);
            combinedResult = combinedResult.combine(runSubBuildResults);
        }
        dynamicBuild.setResult(combinedResult);
        return combinedResult;
    } finally {
        try {
            subBuildScheduler.cancelSubBuilds(listener.getLogger());
        } catch (Exception e) {
            // There is nothing much we can do at this point
            LOGGER.log(Level.SEVERE, "Failed to cancel subbuilds", e);
        }
    }
}

From source file:org.apache.flex.compiler.internal.targets.SWCTarget.java

@Override
public ISWC build(final Collection<ICompilerProblem> problems) {
    buildStarted();/*ww w  . java2 s.  c  o  m*/
    try {
        Iterable<ICompilerProblem> fatalProblems = getFatalProblems();
        if (!Iterables.isEmpty(fatalProblems)) {
            Iterables.addAll(problems, fatalProblems);
            return null;
        }

        setVersionInfo();
        final HashSet<IDefinition> definitions = new HashSet<IDefinition>();
        buildLibrarySWF(definitions, problems);
        addComponents(definitions);
        addFileEntriesToSWC(problems);

        return swc;
    } catch (BuildCanceledException bce) {
        return null;
    } catch (InterruptedException ie) {
        return null;
    } finally {
        buildFinished();
    }
}

From source file:com.facebook.presto.sql.ExpressionUtils.java

public static Expression combineDisjunctsWithDefault(Iterable<Expression> expressions,
        Expression emptyDefault) {
    requireNonNull(expressions, "expressions is null");

    // Flatten all the expressions into their component disjuncts
    expressions = Iterables.concat(Iterables.transform(expressions, ExpressionUtils::extractDisjuncts));

    // Strip out all false literal disjuncts
    expressions = Iterables.filter(expressions, not(Predicates.<Expression>equalTo(FALSE_LITERAL)));
    expressions = removeDuplicates(expressions);
    return Iterables.isEmpty(expressions) ? emptyDefault : or(expressions);
}

From source file:com.google.doubleclick.util.DoubleClickValidator.java

public boolean validate(final BidRequest request, final BidResponse.Builder response) {
    boolean hasBad = false;
    boolean hasEmpty = false;
    List<BidResponse.Ad.Builder> ads = response.getAdBuilderList();

    for (int iAd = 0; iAd < ads.size(); ++iAd) {
        final BidResponse.Ad.Builder ad = ads.get(iAd);
        List<BidResponse.Ad.AdSlot.Builder> adslots = ad.getAdslotBuilderList();

        if (adslots.isEmpty()) {
            hasEmpty = true;/*from   w ww  .j a  va2s.co m*/
            if (logger.isDebugEnabled()) {
                logger.debug("Ad #{} removed, clean but empty adslot", iAd);
            }
        } else {
            Iterable<BidResponse.Ad.AdSlot.Builder> filteredAdslots = ProtoUtils.filter(adslots,
                    new Predicate<BidResponse.Ad.AdSlot.Builder>() {
                        @Override
                        public boolean apply(BidResponse.Ad.AdSlot.Builder adslot) {
                            return validate(request, ad, adslot);
                        }
                    });

            if (filteredAdslots != adslots) {
                hasBad = true;
                ad.clearAdslot();
                if (Iterables.isEmpty(filteredAdslots)) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Ad #{} removed, all adslot values rejected", iAd);
                    }
                } else {
                    for (BidResponse.Ad.AdSlot.Builder filteredAdslot : filteredAdslots) {
                        ad.addAdslot(filteredAdslot);
                    }
                }
            }
        }
    }

    if (hasBad || hasEmpty) {
        List<BidResponse.Ad.Builder> adsNew = new ArrayList<>(ads.size());
        for (BidResponse.Ad.Builder ad : ads) {
            if (ad.getAdslotCount() != 0) {
                adsNew.add(ad);
            }
        }
        response.clearAd();
        for (BidResponse.Ad.Builder ad : adsNew) {
            response.addAd(ad);
        }
    }
    return hasBad;
}

From source file:org.eclipse.reqcycle.ocl.utils.OCLUtilities.java

/**
 * Gets operations that could be used to match uml elements to a data type. These operations
 * must have a specific name and signature (no parameter, return boolean).
 *///ww  w . ja v a2  s .c  o  m
public static Iterable<DefOperationCS> getMatchingOperations(final IRequirementType type,
        BaseResource resource) {
    Collection<DefOperationCS> operations = getOperations(resource);
    if (operations == null || Iterables.isEmpty(operations)) {
        return Collections.emptyList();
    }
    return Iterables.filter(operations, new Predicate<DefOperationCS>() {

        @Override
        public boolean apply(DefOperationCS arg0) {
            TypedRefCS operationReturnType = arg0.getOwnedType();
            if (!arg0.getParameters().isEmpty()) {
                return false;
            }
            if (operationReturnType instanceof PrimitiveTypeRefCS) {
                String returnType = ((PrimitiveTypeRefCS) operationReturnType).getName();
                if (!"Boolean".equals(returnType)) { //$NON-NLS-1$
                    return false;
                }
            }
            return arg0.getName().equalsIgnoreCase(getOperationRequiredName(type));
        }
    });
}