Example usage for com.google.common.base Predicates instanceOf

List of usage examples for com.google.common.base Predicates instanceOf

Introduction

In this page you can find the example usage for com.google.common.base Predicates instanceOf.

Prototype

@GwtIncompatible("Class.isInstance")
public static Predicate<Object> instanceOf(Class<?> clazz) 

Source Link

Document

Returns a predicate that evaluates to true if the object being tested is an instance of the given class.

Usage

From source file:org.eclipselabs.agrum.services.model.plugin.parser.ModelParser.java

/**
 * To get an iterator on each outgoing transition of a state, which possessed a tick event as trigger
 * @param s - the state/*from   w ww. ja v  a 2  s . co m*/
 * @return the iterator
 */
private static Iterator<Transition> tickTransitionIterator(State s) {
    Predicate<Object> allTransitions = Predicates.instanceOf(Transition.class);
    Iterator<Transition> transitions = Iterators.filter(s.getOutgoings().listIterator(), allTransitions);

    transitions = Iterators.filter(transitions, new com.google.common.base.Predicate<Transition>() {

        @Override
        public boolean apply(Transition arg0) {
            for (Trigger trg : arg0.getTriggers()) {
                if (trg.getEvent().getName().equals(clockTriggerName))
                    return true;
            }
            return false;
        }
    });
    return transitions;
}

From source file:org.jetbrains.jet.lang.resolve.DelegationResolver.java

@SuppressWarnings("unchecked")
private static Collection<CallableMemberDescriptor> extractCallableMembers(JetType type) {
    return (Collection) Collections2.filter(type.getMemberScope().getAllDescriptors(),
            Predicates.instanceOf(CallableMemberDescriptor.class));
}

From source file:org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveStatementBase.java

@SuppressWarnings("unchecked")
protected final <T> Collection<T> allSubstatementsOfType(final Class<T> type) {
    return Collection.class.cast(Collections2.filter(substatements, Predicates.instanceOf(type)));
}

From source file:org.eclipse.sirius.sample.interactions.services.InteractionOrderingServices.java

public boolean eolPrecondition(Participant p) {
    Interaction i = (Interaction) new EObjectQuery(p)
            .getFirstAncestorOfType(InteractionsPackage.Literals.INTERACTION).get();
    for (Message msg : Iterables.filter(i.getMessages(),
            Predicates.instanceOf(DestroyParticipantMessage.class))) {
        if (msg.getReceivingEnd() != null && msg.getReceivingEnd().getContext() == p) {
            return true;
        }//from  w ww. ja  v a  2  s.co  m
    }
    return false;
}

From source file:com.eucalyptus.ws.util.ErrorHandlerSupport.java

protected static Optional<Integer> getHttpResponseStatus(final Throwable t) {
    final QueryBindingInfo info = Ats.inClassHierarchy(t.getClass()).get(QueryBindingInfo.class);
    final Optional<Integer> status = info == null ? Optional.<Integer>absent() : Optional.of(info.statusCode());
    return Iterables.tryFind(Exceptions.causes(t), Predicates.instanceOf(HasHttpStatusCode.class))
            .transform(Functions.compose(HasHttpStatusCode.Utils.httpStatusCode(),
                    CollectionUtils.cast(HasHttpStatusCode.class)))
            .or(status);//  ww w.j a  va2 s  . c  o m
}

From source file:org.dasein.cloud.jclouds.vcloud.director.network.VCloudDirectorNetworkSupport.java

@Override
public Iterable<NetworkInterface> listNetworkInterfaces(String forVmId)
        throws CloudException, InternalException {
    RestContext<VCloudDirectorAdminClient, VCloudDirectorAdminAsyncClient> ctx = provider.getCloudClient();

    try {//from w w  w. j a  va 2 s  .co m
        try {
            Set<Reference> refs = provider.getOrg().getNetworks();
            List<NetworkInterface> list = Lists.newArrayList();
            List<Network> networks = Lists.newArrayList();
            Vm vm = ctx.getApi().getVmClient().getVm(provider.toHref(ctx, forVmId));
            NetworkConnection def = null;

            if (refs != null) {
                for (Reference t : refs) {
                    if (t.getType().equals(VCloudDirectorMediaType.NETWORK)) {
                        Network network = ctx.getApi().getNetworkClient().getNetwork(t.getHref());

                        if (network != null) {
                            networks.add(network);
                        }
                    }
                }
            }
            NetworkConnectionSection section = (NetworkConnectionSection) Iterables.find(vm.getSections(),
                    Predicates.instanceOf(NetworkConnectionSection.class));
            for (NetworkConnection c : section.getNetworkConnections()) {
                NetworkInterface nic = new NetworkInterface();

                nic.setProviderNetworkInterfaceId(c.getMACAddress());
                nic.setIpAddress(c.getIpAddress());
                nic.setProviderVirtualMachineId(forVmId);
                for (Network network : networks) {
                    if (network.getName().equals(c.getNetwork())) {
                        IpScope scope = network.getConfiguration().getIpScope();

                        if (def == null || def.getNetworkConnectionIndex() > c.getNetworkConnectionIndex()) {
                            def = c;
                        }
                        nic.setGatewayAddress(scope.getGateway());
                        nic.setNetmask(scope.getNetmask());
                        nic.setProviderVlanId(provider.toId(ctx, network.getHref()));
                    }
                }
            }
            if (def != null) {
                for (NetworkInterface nic : list) {
                    if (def.getMACAddress().equals(nic.getProviderNetworkInterfaceId())) {
                        nic.setDefaultRoute(true);
                    }
                }
            }
            return list;
        } catch (RuntimeException e) {
            logger.error("Error listing network interfaces for " + forVmId + ": " + e.getMessage());
            if (logger.isDebugEnabled()) {
                e.printStackTrace();
            }
            throw new CloudException(e);
        }
    } finally {
        ctx.close();
    }
}

From source file:org.eclipse.sirius.ui.tools.internal.views.common.modelingproject.OpenRepresentationsFileJob.java

/**
 * Constructor to open several representations files.
 *
 * @param elements/*  w  w w  . j  av  a 2 s  . co m*/
 *            A list of URIs of the representations files to open or a list
 *            of the modeling projects to initialize and open.
 */
public OpenRepresentationsFileJob(List<? extends Object> elements) {
    super(OpenRepresentationsFileJob.JOB_LABEL);
    if (!(Iterators.all(elements.iterator(), Predicates.instanceOf(URI.class))
            || Iterators.all(elements.iterator(), Predicates.instanceOf(ModelingProject.class)))) {
        throw new IllegalArgumentException(Messages.OpenRepresentationsFileJob_errorInvalidInputList);
    }
    Iterators.addAll(this.representationsFilesURIs, Iterators.filter(elements.iterator(), URI.class));
    Iterators.addAll(this.modelingProjects, Iterators.filter(elements.iterator(), ModelingProject.class));
}

From source file:eu.stratosphere.sopremo.expressions.EvaluationExpression.java

@SuppressWarnings("unchecked")
public <T extends EvaluationExpression> T findFirst(final Class<T> evaluableClass) {
    return (T) this.findFirst(Predicates.instanceOf(evaluableClass));
}

From source file:org.eclipse.sirius.diagram.ui.tools.internal.commands.ToggleFoldingStateCommand.java

private void addFilterType(DDiagramElement element, GraphicalFilter filter) {
    if (!Iterables.any(element.getGraphicalFilters(), Predicates.instanceOf(filter.getClass()))) {
        element.getGraphicalFilters().add(filter);
    }// w  w w.  j a va 2  s  .c om
}

From source file:com.xebialabs.deployit.ci.JenkinsPackageOptions.java

private List<DeployableView> sortDeployables(List<DeployableView> deployables) {
    List<DeployableView> result = Lists.newArrayList(
            Iterables.filter(deployables, Predicates.not(Predicates.instanceOf(EmbeddedView.class))));
    List<EmbeddedView> embeddeds = /* double cast: dirty but quick */
            (List<EmbeddedView>) (Object) Lists
                    .newArrayList(Iterables.filter(deployables, Predicates.instanceOf(EmbeddedView.class)));
    // sort the embeddeds on the number of /'s in the parent name
    Collections.sort(embeddeds, new Comparator<EmbeddedView>() {
        @Override// w ww. ja  va 2  s .  c o m
        public int compare(EmbeddedView o1, EmbeddedView o2) {
            return o1.getParentName().split("/").length - o2.getParentName().split("/").length;
        }
    });
    result.addAll(embeddeds);
    return result;
}