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:vazkii.botania.common.block.subtile.functional.SubTileHeiseiDream.java

@Override
public void onUpdate() {
    super.onUpdate();

    if (supertile.getWorld().isRemote)
        return;//ww w.  ja  v a 2 s .com

    final int cost = 100;

    @SuppressWarnings("unchecked")
    List<IMob> mobs = (List) supertile.getWorld().getEntitiesWithinAABB(Entity.class,
            new AxisAlignedBB(supertile.getPos().add(-RANGE, -RANGE, -RANGE),
                    supertile.getPos().add(RANGE + 1, RANGE + 1, RANGE + 1)),
            Predicates.instanceOf(IMob.class));

    if (mobs.size() > 1 && mana >= cost)
        for (IMob mob : mobs) {
            if (mob instanceof EntityLiving) {
                EntityLiving entity = (EntityLiving) mob;
                if (brainwashEntity(entity, mobs)) {
                    mana -= cost;
                    sync();
                    break;
                }
            }
        }
}

From source file:org.jpmml.rattle.visitors.ScoreDistributionCleaner.java

private TreeModel getTreeModel() {
    Deque<PMMLObject> parents = getParents();

    return (TreeModel) Iterables.find(parents, Predicates.instanceOf(TreeModel.class));
}

From source file:org.eclipse.sirius.diagram.ui.tools.internal.figure.locator.FeedbackDBorderItemLocator.java

@Override
protected List<IFigure> getBrotherFigures(IFigure targetBorderItem) {
    IFigure parentFigure = getParentFigure();
    if (parentFigure instanceof BorderedNodeFigure) {
        parentFigure = ((BorderedNodeFigure) parentFigure).getBorderItemContainer();
    }/*from   w  w  w .jav a  2s .com*/
    @SuppressWarnings("unchecked")
    Iterable<IFigure> brotherFigures = Iterables.filter(parentFigure.getChildren(), Predicates
            .and(Predicates.instanceOf(IFigure.class), Predicates.not(Predicates.equalTo(targetBorderItem))));
    return Lists.newArrayList(brotherFigures);
}

From source file:vazkii.botania.common.item.equipment.bauble.ItemUnholyCloak.java

@Override
public boolean effectOnDamage(LivingHurtEvent event, EntityPlayer player, ItemStack stack) {
    if (!event.getSource().isUnblockable()) {
        int range = 6;
        List mobs = player.worldObj.getEntitiesWithinAABB(Entity.class,
                new AxisAlignedBB(player.posX - range, player.posY - range, player.posZ - range,
                        player.posX + range, player.posY + range, player.posZ + range),
                Predicates.instanceOf(IMob.class));
        for (IMob mob : (List<IMob>) mobs)
            if (mob instanceof EntityLivingBase) {
                EntityLivingBase entity = (EntityLivingBase) mob;
                entity.attackEntityFrom(DamageSource.causePlayerDamage(player), event.getAmount());
            }/*from w  ww.j av  a  2 s  . c o  m*/

        player.worldObj.playSound(null, player.posX, player.posY, player.posZ, BotaniaSoundEvents.unholyCloak,
                SoundCategory.PLAYERS, 1F, 1F);
        for (int i = 0; i < 90; i++) {
            float rad = i * 4F * (float) Math.PI / 180F;
            float xMotion = (float) Math.cos(rad) * 0.2F;
            float zMotion = (float) Math.sin(rad) * 0.2F;
            Botania.proxy.wispFX(player.posX, player.posY + 0.5, player.posZ,
                    0.4F + (float) Math.random() + 0.25F, 0F, 0F, 0.6F + (float) Math.random() * 0.2F, xMotion,
                    0F, zMotion);
        }

        return true;
    }

    return false;
}

From source file:brooklyn.entity.container.docker.application.VanillaDockerApplicationImpl.java

@Override
public DockerContainer getDockerContainer() {
    DockerContainerLocation location = (DockerContainerLocation) Iterables.find(getLocations(),
            Predicates.instanceOf(DockerContainerLocation.class));
    return location.getOwner();
}

From source file:brooklyn.entity.messaging.rabbit.RabbitDestination.java

@Override
public void onManagementStarting() {
    super.onManagementStarting();

    exchange = (getConfig(EXCHANGE_NAME) != null) ? getConfig(EXCHANGE_NAME) : getDefaultExchangeName();
    virtualHost = getConfig(RabbitBroker.VIRTUAL_HOST_NAME);
    setAttribute(RabbitBroker.VIRTUAL_HOST_NAME, virtualHost);

    machine = (SshMachineLocation) Iterables.find(getParent().getLocations(),
            Predicates.instanceOf(SshMachineLocation.class));
    shellEnvironment = getParent().getShellEnvironment();
}

From source file:org.apache.brooklyn.entity.messaging.kafka.KafkaSupport.java

/**
 * Send a message to the {@link KafkaCluster} on the given topic.
 *///w  w  w .j  a  va 2s  .c  om
public void sendMessage(String topic, String message) {
    Optional<Entity> anyBrokerNodeInCluster = Iterables.tryFind(cluster.getCluster().getChildren(),
            Predicates.and(Predicates.instanceOf(KafkaBroker.class),
                    EntityPredicates.attributeEqualTo(KafkaBroker.SERVICE_UP, true)));
    if (anyBrokerNodeInCluster.isPresent()) {
        KafkaBroker broker = (KafkaBroker) anyBrokerNodeInCluster.get();

        Properties props = new Properties();

        props.put("metadata.broker.list",
                format("%s:%d", broker.getAttribute(KafkaBroker.HOSTNAME), broker.getKafkaPort()));
        props.put("bootstrap.servers",
                format("%s:%d", broker.getAttribute(KafkaBroker.HOSTNAME), broker.getKafkaPort()));
        props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");

        Producer<String, String> producer = new KafkaProducer<>(props);
        ((KafkaZooKeeper) cluster.getZooKeeper()).createTopic(topic);

        ProducerRecord<String, String> data = new ProducerRecord<>(topic, message);
        producer.send(data);
        producer.close();
    } else {
        throw new InvalidParameterException("No kafka broker node found");
    }
}

From source file:org.apache.brooklyn.entity.messaging.rabbit.RabbitDestination.java

@Override
public void onManagementStarting() {
    super.onManagementStarting();

    exchange = (getConfig(EXCHANGE_NAME) != null) ? getConfig(EXCHANGE_NAME) : getDefaultExchangeName();
    virtualHost = getConfig(RabbitBroker.VIRTUAL_HOST_NAME);
    sensors().set(RabbitBroker.VIRTUAL_HOST_NAME, virtualHost);

    machine = (SshMachineLocation) Iterables.find(getParent().getLocations(),
            Predicates.instanceOf(SshMachineLocation.class));
    shellEnvironment = getParent().getShellEnvironment();
}

From source file:org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement.java

protected final <S extends DeclaredStatement<?>> S firstDeclared(final Class<S> type) {
    return type.cast(Iterables.find(substatements, Predicates.instanceOf(type)));
}

From source file:brooklyn.entity.trait.StartableMethods.java

private static <T extends Entity> Iterable<T> filterStartableManagedEntities(Iterable<T> contenders) {
    return Iterables.filter(contenders,
            Predicates.and(Predicates.instanceOf(Startable.class), EntityPredicates.isManaged()));
}