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

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

Introduction

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

Prototype

@GwtIncompatible("Class.isInstance")
@CheckReturnValue
public final <T> FluentIterable<T> filter(Class<T> type) 

Source Link

Document

Returns the elements from this fluent iterable that are instances of class type .

Usage

From source file:org.sosy_lab.cpachecker.cpa.smg.refiner.SMGCEGARUtils.java

public static SMGPrecision extractSMGPrecision(final ARGReachedSet pReached, ARGState state) {
    FluentIterable<Precision> precisions = Precisions.asIterable(pReached.asReachedSet().getPrecision(state));

    precisions = precisions.filter((Precision prec) -> {
        return prec instanceof SMGPrecision;
    });/*  w  w w . j  a va  2 s.c om*/

    return (SMGPrecision) Iterables.getOnlyElement(precisions);
}

From source file:google.registry.flows.EppXmlTransformer.java

/**
 * Unmarshal bytes into Epp classes.// w  w w .  j  a  v a2  s.  co m
 *
 * @param clazz type to return, specified as a param to enforce typesafe generics
 * @see <a href="http://errorprone.info/bugpattern/TypeParameterUnusedInFormals">TypeParameterUnusedInFormals</a>
 */
public static <T> T unmarshal(Class<T> clazz, byte[] bytes) throws EppException {
    try {
        return INPUT_TRANSFORMER.unmarshal(clazz, new ByteArrayInputStream(bytes));
    } catch (XmlException e) {
        // If this XmlException is wrapping a known type find it. If not, it's a syntax error.
        FluentIterable<Throwable> causalChain = FluentIterable.from(Throwables.getCausalChain(e));
        if (!(causalChain.filter(IpVersionMismatchException.class).isEmpty())) {
            throw new IpAddressVersionMismatchException();
        }
        if (!(causalChain.filter(WrongProtocolVersionException.class).isEmpty())) {
            throw new UnimplementedProtocolVersionException();
        }
        if (!(causalChain.filter(InvalidRepoIdException.class).isEmpty())) {
            throw new InvalidRepoIdEppException();
        }
        if (!(causalChain.filter(UnknownCurrencyException.class).isEmpty())) {
            throw new UnknownCurrencyEppException();
        }
        throw new GenericSyntaxErrorException(e.getMessage());
    }
}

From source file:com.facebook.buck.apple.Flavors.java

/**
 * Propagate a build target's flavors in a certain domain to a list of other build targets.
 *
 * @param domain the flavor domain to be propagated.
 * @param buildTarget the build target containing the flavors to be propagated
 * @param deps list of BuildTargetPaths to propagate the flavors to. If a target already contains
 *     one or more flavors in domain, it is left unchanged.
 * @return the list of BuildTargetPaths with any flavors propagated.
 *//*from w w w  . j av a 2s.c om*/
public static FluentIterable<BuildTarget> propagateFlavorsInDomainIfNotPresent(FlavorDomain<?> domain,
        BuildTarget buildTarget, FluentIterable<BuildTarget> deps) {
    if (domain.containsAnyOf(buildTarget.getFlavors())) {
        FluentIterable<BuildTarget> targetsWithFlavorsAlready = deps.filter(containsFlavors(domain)::test);

        FluentIterable<BuildTarget> targetsWithoutFlavors = deps.filter(containsFlavors(domain).negate()::test);

        deps = targetsWithFlavorsAlready
                .append(propagateFlavorDomains(buildTarget, ImmutableSet.of(domain), targetsWithoutFlavors));
    }

    return deps;
}

From source file:com.facebook.buck.apple.AbstractAppleNativeTargetBuildRuleDescriptions.java

private static FluentIterable<TargetNode<AppleNativeTargetDescriptionArg>> filterAppleNativeTargetNodes(
        FluentIterable<TargetNode<?>> fluentIterable) {
    return fluentIterable.filter(new Predicate<TargetNode<?>>() {
        @Override//from ww  w . j  av  a  2s  .  com
        public boolean apply(TargetNode<?> input) {
            return ImmutableSet.of(AppleBinaryDescription.TYPE, AppleLibraryDescription.TYPE)
                    .contains(input.getType());
        }
    }).transform(new Function<TargetNode<?>, TargetNode<AppleNativeTargetDescriptionArg>>() {
        @Override
        @SuppressWarnings("unchecked")
        public TargetNode<AppleNativeTargetDescriptionArg> apply(TargetNode<?> input) {
            return (TargetNode<AppleNativeTargetDescriptionArg>) input;
        }
    });
}

From source file:com.facebook.buck.model.BuildTargets.java

/**
 * Propagate a build target's flavors in a certain domain to a list of other build targets.
 *
 * @param domain the flavor domain to be propagated.
 * @param buildTarget the build target containing the flavors to be propagated
 * @param deps list of BuildTargets to propagate the flavors to.  If a target already contains
 *             one or more flavors in domain, it is left unchanged.
 * @return the list of BuildTargets with any flavors propagated.
 *//*  w  ww. ja v  a2s. co m*/
public static FluentIterable<BuildTarget> propagateFlavorsInDomainIfNotPresent(FlavorDomain<?> domain,
        BuildTarget buildTarget, FluentIterable<BuildTarget> deps) {
    if (domain.containsAnyOf(buildTarget.getFlavors())) {
        FluentIterable<BuildTarget> targetsWithFlavorsAlready = deps
                .filter(BuildTargets.containsFlavors(domain));

        FluentIterable<BuildTarget> targetsWithoutFlavors = deps
                .filter(Predicates.not(BuildTargets.containsFlavors(domain)));

        deps = targetsWithFlavorsAlready.append(BuildTargets.propagateFlavorDomains(buildTarget,
                ImmutableSet.of(domain), targetsWithoutFlavors));
    }

    return deps;
}

From source file:see.exceptions.SeeRuntimeException.java

/**
 * Extract see stacktrace from a throwable
 * @param throwable target throwable/*from ww  w  .  j av a2  s.co  m*/
 * @return extracted trace
 */
private static List<TraceElement> getTrace(Throwable throwable) {
    List<Throwable> causalChain = getCausalChain(throwable);
    FluentIterable<PropagatedException> stack = from(causalChain).filter(PropagatedException.class);
    FluentIterable<Node<?>> nodes = stack.transform(new Function<PropagatedException, Node<?>>() {
        @Override
        public Node<?> apply(PropagatedException input) {
            return input.getFailedNode();
        }
    });
    FluentIterable<TraceElement> trace = nodes.filter(Tracing.class)
            .transform(new Function<Tracing, TraceElement>() {
                @Nullable
                @Override
                public TraceElement apply(Tracing input) {
                    Option<TraceElement> position = input.position();
                    if (position.isDefined())
                        return position.get();
                    else
                        return null;
                }
            }).filter(notNull());
    return trace.toList().reverse();
}

From source file:net.sourceforge.fenixedu.domain.accessControl.StudentGroup.java

private static FluentIterable<Registration> filterCycle(FluentIterable<Registration> registrations,
        final CycleType cycleType, final ExecutionYear executionYear) {
    if (cycleType == null) {
        return registrations;
    }// ww  w.  j ava2 s . c o  m
    return registrations.filter(new Predicate<Registration>() {
        @Override
        public boolean apply(Registration registration) {
            return Objects.equal(registration.getCycleType(executionYear), cycleType);
        }
    });
}

From source file:net.sourceforge.fenixedu.domain.accessControl.StudentGroup.java

private static FluentIterable<Registration> filterCurricularYear(FluentIterable<Registration> registrations,
        final CurricularYear curricularYear, final ExecutionYear executionYear) {
    if (curricularYear == null) {
        return registrations;
    }/*from   w  w w  .ja  v  a2 s. c o m*/
    return registrations.filter(new Predicate<Registration>() {
        @Override
        public boolean apply(Registration registration) {
            return registration.getCurricularYear(executionYear) == curricularYear.getYear();
        }
    });
}

From source file:org.fenixedu.academic.domain.accessControl.StudentGroup.java

private static FluentIterable<Registration> filterCycle(FluentIterable<Registration> registrations,
        final CycleType cycleType, final ExecutionYear executionYear) {
    if (cycleType == null) {
        return registrations;
    }//from w ww. j a v  a2  s  . c  om
    return registrations
            .filter(getPredicateForActiveRegistrationsThatHaveAtLeastOneEnrolment(cycleType, executionYear));
}

From source file:ezbakehelpers.hdfs.HDFSHelper.java

/**
 * @param properties - EzProperties to get the HDFS Configuration from
 * @return {@link org.apache.hadoop.conf.Configuration} object with HDFS configuration stored in it
 *//* w  w w  .ja  v a 2s  .c  o  m*/
private static Configuration convertToHDFSConfiguration(Properties properties) {
    final Configuration hadoopConf = new Configuration();
    @SuppressWarnings("unchecked")
    FluentIterable<String> PROP_KEYS = FluentIterable.from((Set) properties.keySet());
    for (final String prop : ALL_PROPS) {
        final Set<String> properties_to_load = Sets.newHashSet();
        // if ends with a '.' we want to add all properties from EzProperties that starts with this property name
        if (prop.endsWith(".")) {
            Iterables.addAll(properties_to_load, PROP_KEYS.filter(new Predicate<String>() {
                @Override
                public boolean apply(String s) {
                    return s.startsWith(prop);
                }
            }));
        } else {
            properties_to_load.add(prop);
        }
        // for each property found, if it exist in the ezProperty load it
        for (String propToLoad : properties_to_load) {
            String value = properties.getProperty(propToLoad);
            if (!Strings.isNullOrEmpty(value))
                hadoopConf.set(propToLoad, value);
        }
    }
    //Maven including different jars causes this to get overwritten.
    //see http://stackoverflow.com/a/21118824
    hadoopConf.set(EzBakePropertyConstants.HADOOP_FILESYSTEM_IMPL,
            properties.getProperty(EzBakePropertyConstants.HADOOP_FILESYSTEM_IMPL,
                    org.apache.hadoop.hdfs.DistributedFileSystem.class.getName()));
    return hadoopConf;
}