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

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

Introduction

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

Prototype

@CheckReturnValue
public final boolean isEmpty() 

Source Link

Document

Determines whether this fluent iterable is empty.

Usage

From source file:org.sosy_lab.cpachecker.core.algorithm.bmc.CandidateInvariantConjunction.java

private static boolean areMatchingLocationInvariants(Iterable<? extends CandidateInvariant> pElements) {
    FluentIterable<? extends CandidateInvariant> elements = FluentIterable.from(pElements);
    if (elements.isEmpty()) {
        return false;
    }//from   w w  w. ja  v a2 s . com
    return elements.allMatch(lfi -> lfi instanceof LocationFormulaInvariant);
}

From source file:org.codeseed.common.config.PropertySources.java

/**
 * Returns a source which returns the first non-{@code null} value from a
 * series of sources./*  w w w  .ja  v  a 2  s.c  om*/
 *
 * @param sources
 *            the ordered sources to combine
 * @return property source that considers multiple sources
 */
public static PropertySource compose(Iterable<PropertySource> sources) {
    FluentIterable<PropertySource> s = FluentIterable.from(sources)
            .filter(Predicates.not(Predicates.equalTo(empty())));
    if (s.isEmpty()) {
        return empty();
    } else if (s.size() == 1) {
        return s.first().get();
    } else {
        return new CompositionSource(s.toList());
    }
}

From source file:org.obm.imap.sieve.commands.SieveGetScript.java

@Override
public void responseReceived(List<SieveResponse> rs) {
    if (commandSucceeded(rs)) {
        String data = rs.get(0).getData();
        Iterable<String> splitData = Splitter.on(SieveConstants.SPLIT_EXPR).split(data);
        FluentIterable<String> splitDataNoByteCount = FluentIterable.from(splitData).skip(1);
        FluentIterable<String> splitDataNoByteCountAndNoReturnCode = splitDataNoByteCount
                .limit(splitDataNoByteCount.size() - 1);
        if (!splitDataNoByteCountAndNoReturnCode.isEmpty()) {
            this.retVal = Joiner.on(SieveConstants.SEP).join(splitDataNoByteCountAndNoReturnCode) + "\r\n";
        } else {/*  ww  w .  ja  v a  2s  . com*/
            this.retVal = "";
        }
    } else {
        reportErrors(rs);
    }
    logger.info("returning a sieve script");
}

From source file:org.sosy_lab.cpachecker.util.cwriter.CExpressionInvariantExporter.java

/**
 * @return Mapping from line numbers to states associated with the given line.
 *///from   ww  w  .j a va  2  s.com
private Map<Integer, BooleanFormula> getInvariantsForFile(ReachedSet pReachedSet, String filename) {

    // One formula per reported state.
    Multimap<Integer, BooleanFormula> byState = HashMultimap.create();

    for (AbstractState state : pReachedSet) {

        CFANode loc = AbstractStates.extractLocation(state);
        if (loc != null && loc.getNumEnteringEdges() > 0) {
            CFAEdge edge = loc.getEnteringEdge(0);
            FileLocation location = edge.getFileLocation();
            FluentIterable<FormulaReportingState> reporting = AbstractStates.asIterable(state)
                    .filter(FormulaReportingState.class);

            if (location.getFileName().equals(filename) && !reporting.isEmpty()) {
                BooleanFormula reported = bfmgr
                        .and(reporting.transform(s -> s.getFormulaApproximation(fmgr)).toList());
                byState.put(location.getStartingLineInOrigin(), reported);
            }
        }
    }
    return Maps.transformValues(byState.asMap(), invariants -> bfmgr.or(invariants));
}

From source file:com.spectralogic.dsbrowser.gui.services.tasks.Ds3GetJob.java

private Ds3ClientHelpers.Job getJobFromIterator(final String bucketName, final FluentIterable<Ds3Object> obj)
        throws IOException {
    if (obj.isEmpty()) {
        return null;
    }/*w  w  w .  j  a  va  2  s .com*/
    final Ds3ClientHelpers.Job job = wrappedDs3Client.startReadJob(bucketName, obj)
            .withMaxParallelRequests(maximumNumberOfParallelThreads);
    if (Objects.nonNull(jobPriority)) {
        client.modifyJobSpectraS3(new ModifyJobSpectraS3Request(job.getJobId())
                .withPriority(com.spectralogic.ds3client.models.Priority.valueOf(jobPriority)));
    }
    return job;
}

From source file:ezbake.deployer.EzBakeDeployerHandler.java

protected <T> FluentIterable<T> expectMore(FluentIterable<T> rows) throws DeploymentException {
    if (rows.isEmpty()) {
        DeploymentException e = new DeploymentException("Can not find application:version provided");
        log.error("Error getting metadata for artifact", e);
        throw e;/*from  ww w . j av a  2  s  .  c o m*/
    }
    return rows;
}

From source file:com.facebook.buck.js.ReactNativeDeps.java

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, final BuildableContext buildableContext) {
    ImmutableList.Builder<Step> steps = ImmutableList.builder();

    final Path output = BuildTargets.getScratchPath(getBuildTarget(), "__%s/deps.txt");
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), output.getParent()));

    steps.add(new ShellStep(getProjectFilesystem().getRootPath()) {
        @Override//from www  . jav a2  s.co m
        protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) {
            ImmutableList.Builder<String> builder = ImmutableList.builder();

            builder.add(getResolver().getAbsolutePath(jsPackager).toString(), "list-dependencies",
                    platform.toString(),
                    getProjectFilesystem().resolve(getResolver().getAbsolutePath(entryPath)).toString(),
                    "--output", getProjectFilesystem().resolve(output).toString());

            if (packagerFlags.isPresent()) {
                builder.addAll(Arrays.asList(packagerFlags.get().split(" ")));
            }

            return builder.build();
        }

        @Override
        public String getShortName() {
            return "react-native-deps";
        }
    });

    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), outputDir));

    steps.add(new AbstractExecutionStep("hash_js_inputs") {
        @Override
        public int execute(ExecutionContext context) throws IOException {
            ImmutableList<Path> paths;
            try {
                paths = FluentIterable.from(getProjectFilesystem().readLines(output))
                        .transform(MorePaths.TO_PATH).transform(getProjectFilesystem().getRelativizer())
                        .toSortedList(Ordering.natural());
            } catch (IOException e) {
                context.logError(e, "Error reading output of the 'react-native-deps' step.");
                return 1;
            }

            FluentIterable<SourcePath> unlistedSrcs = FluentIterable.from(paths)
                    .transform(SourcePaths.toSourcePath(getProjectFilesystem()))
                    .filter(Predicates.not(Predicates.in(srcs)));
            if (!unlistedSrcs.isEmpty()) {
                context.logError(new RuntimeException(),
                        "Entry path '%s' transitively uses the following source files which were not "
                                + "included in 'srcs':\n%s",
                        entryPath, Joiner.on('\n').join(unlistedSrcs));
                return 1;
            }

            Hasher hasher = Hashing.sha1().newHasher();
            for (Path path : paths) {
                try {
                    hasher.putUnencodedChars(getProjectFilesystem().computeSha1(path));
                } catch (IOException e) {
                    context.logError(e, "Error hashing input file: %s", path);
                    return 1;
                }
            }

            String inputsHash = hasher.hash().toString();
            buildableContext.addMetadata(METADATA_KEY_FOR_INPUTS_HASH, inputsHash);
            getProjectFilesystem().writeContentsToPath(inputsHash, inputsHashFile);
            return 0;
        }
    });

    return steps.build();
}

From source file:com.google.api.tools.framework.aspects.naming.NameAbbreviationRule.java

@Override
public void run(ProtoElement element) {
    // This rule applies to all ProtoElements except file names.
    if (!(element instanceof ProtoFile)) {
        final String simpleName = element.getSimpleName();
        if (!Strings.isNullOrEmpty(simpleName)) {
            FluentIterable<String> usedLongNames = FluentIterable.from(NAME_ABBREVIATION_MAP.keySet())
                    .filter(new Predicate<String>() {
                        @Override
                        public boolean apply(String longName) {
                            return simpleName.toLowerCase().contains(longName);
                        }/*from  ww  w  . j  ava 2 s.c  om*/
                    });
            if (!usedLongNames.isEmpty()) {
                FluentIterable<String> abbreviationsToUse = usedLongNames
                        .transform(new Function<String, String>() {
                            @Override
                            @Nullable
                            public String apply(@Nullable String longName) {
                                return NAME_ABBREVIATION_MAP.get(longName);
                            }
                        });
                warning(element, "Use of full name(s) '%s' in '%s' is not recommended, use '%s' instead.",
                        Joiner.on(",").join(usedLongNames), element.getSimpleName(),
                        Joiner.on(",").join(abbreviationsToUse));
            }
        }
    }
}

From source file:org.pentaho.community.di.impl.provider.HorizontalLayout.java

@Override
public void applyLayout(Graph graph, int canvasWidth, int canvasHeight) {
    GremlinPipeline<Graph, Vertex> pipe = new GremlinPipeline<>(graph);
    List<Vertex> vertices = pipe.V().as("loop")
            // Set degree for each vertex
            .transform(new PipeFunction<Vertex, Iterable<Vertex>>() {
                @Override/*from   ww w.j a  va 2  s  . c om*/
                public Iterable<Vertex> compute(Vertex vertex) {
                    FluentIterable<Integer> degrees = FluentIterable.from(vertex.getVertices(Direction.IN))
                            .transform(GraphUtils.<Integer>getProperty(PROPERTY_COLUMN));

                    ImmutableList.Builder<Vertex> output = ImmutableList.builder();
                    // If no inputs, rank as 0
                    if (degrees.isEmpty()) {
                        vertex.setProperty(PROPERTY_COLUMN, 0);
                    } else {
                        // Find max degree of all inputs
                        Integer value = Ordering.natural().nullsLast().max(degrees);
                        if (value != null) {
                            vertex.setProperty(PROPERTY_COLUMN, value + 1);
                        } else {
                            output.addAll(vertex.getVertices(Direction.IN));
                        }
                    }
                    output.add(vertex);
                    return output.build();
                }
            }).scatter().cast(Vertex.class)
            .loop("loop", new PipeFunction<LoopPipe.LoopBundle<Vertex>, Boolean>() {
                @Override
                public Boolean compute(LoopPipe.LoopBundle<Vertex> argument) {
                    return !argument.getObject().getPropertyKeys().contains(PROPERTY_COLUMN);
                }
            }).dedup().groupBy(new PipeFunction<Vertex, Integer>() {
                @Override
                public Integer compute(Vertex vertex) {
                    return vertex.getProperty(PROPERTY_COLUMN);
                }
            }, new PipeFunction<Vertex, Vertex>() {
                @Override
                public Vertex compute(Vertex vertex) {
                    return vertex;
                }
            }, new PipeFunction<List<Vertex>, List<Vertex>>() {
                @Override
                public List<Vertex> compute(List<Vertex> group) {
                    int row = 0;
                    for (Vertex vertex : group) {
                        vertex.setProperty(PROPERTY_ROW, row++);
                    }
                    return group;
                }
            }).toList();

    int columnWidth = canvasWidth / 5;
    int rowWidth = canvasHeight / 8;
    for (Vertex vertex : vertices) {
        int column = vertex.getProperty(PROPERTY_COLUMN);
        int row = vertex.getProperty(PROPERTY_ROW);
        vertex.setProperty(GraphUtils.PROPERTY_X, columnWidth / 2 + column * columnWidth);
        vertex.setProperty(GraphUtils.PROPERTY_Y, rowWidth / 2 + row * rowWidth);
    }

    System.out.println(vertices);
}

From source file:com.google.errorprone.bugpatterns.PrivateConstructorForUtilityClass.java

@Override
public Description matchClass(ClassTree classTree, VisitorState state) {
    if (!classTree.getKind().equals(CLASS)) {
        return NO_MATCH;
    }//from ww w .ja va2 s . c om

    FluentIterable<? extends Tree> nonSyntheticMembers = FluentIterable.from(classTree.getMembers())
            .filter(Predicates.not(new Predicate<Tree>() {
                @Override
                public boolean apply(Tree tree) {
                    return tree.getKind().equals(METHOD) && isGeneratedConstructor((MethodTree) tree);
                }
            }));
    if (nonSyntheticMembers.isEmpty()) {
        return NO_MATCH;
    }
    boolean isUtilityClass = nonSyntheticMembers.allMatch(new Predicate<Tree>() {
        @Override
        public boolean apply(Tree tree) {
            switch (tree.getKind()) {
            case CLASS:
                return ((ClassTree) tree).getModifiers().getFlags().contains(STATIC);
            case METHOD:
                return ((MethodTree) tree).getModifiers().getFlags().contains(STATIC);
            case VARIABLE:
                return ((VariableTree) tree).getModifiers().getFlags().contains(STATIC);
            case BLOCK:
                return ((BlockTree) tree).isStatic();
            case ENUM:
            case ANNOTATION_TYPE:
            case INTERFACE:
                return true;
            default:
                throw new AssertionError("unknown member type:" + tree.getKind());
            }
        }
    });
    if (!isUtilityClass) {
        return NO_MATCH;
    }
    return describeMatch(classTree,
            addMembers(classTree, state, "private " + classTree.getSimpleName() + "() {}"));
}