Java Code Examples for com.google.common.base.Predicate

The following are top voted examples for showing how to use com.google.common.base.Predicate. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: harshencastle   File: EntitySoulPart.java   View source code 7 votes vote down vote up
@Override
protected void initEntityAI() {
	this.tasks.addTask(8, new AIEntityFlyingTowardsPlayer(this));
       this.tasks.addTask(9, new EntityAIWatchClosest(this, EntityPlayer.class, 3.0F, 1.0F));
       this.tasks.addTask(10, new EntityAIWatchClosest(this, EntityLiving.class, 8.0F));
	this.tasks.addTask(11, new EntityAILookIdle(this));

	this.targetTasks.addTask(0, new EntityAINearestAttackableTarget<>(this, EntityPlayer.class, 10, false, false, new Predicate<EntityLivingBase>() {

		@Override
		public boolean apply(EntityLivingBase input) {
			return !input.isPotionActive(HarshenPotions.potionSoulless);
		}
	}));

}
 
Example 2
Project: Reer   File: ManagedProxyClassGenerator.java   View source code 6 votes vote down vote up
private void writeViewPropertyDslMethods(ClassVisitor visitor, Type generatedType, Collection<ModelProperty<?>> viewProperties, Class<?> viewClass) {
    boolean writable = Iterables.any(viewProperties, new Predicate<ModelProperty<?>>() {
        @Override
        public boolean apply(ModelProperty<?> viewProperty) {
            return viewProperty.isWritable();
        }
    });
    // TODO:LPTR Instead of the first view property, we should figure out these parameters from the actual property
    ModelProperty<?> firstProperty = viewProperties.iterator().next();

    writeConfigureMethod(visitor, generatedType, firstProperty, writable);
    writeSetMethod(visitor, generatedType, firstProperty);
    writeTypeConvertingSetter(visitor, generatedType, viewClass, firstProperty);

    // TODO - this should be applied to all methods, including delegating methods
    writeReadOnlySetter(visitor, viewClass, writable, firstProperty);
}
 
Example 3
Project: Backmemed   File: EntityOcelot.java   View source code 6 votes vote down vote up
protected void initEntityAI()
{
    this.aiSit = new EntityAISit(this);
    this.aiTempt = new EntityAITempt(this, 0.6D, Items.FISH, true);
    this.tasks.addTask(1, new EntityAISwimming(this));
    this.tasks.addTask(2, this.aiSit);
    this.tasks.addTask(3, this.aiTempt);
    this.tasks.addTask(5, new EntityAIFollowOwner(this, 1.0D, 10.0F, 5.0F));
    this.tasks.addTask(6, new EntityAIOcelotSit(this, 0.8D));
    this.tasks.addTask(7, new EntityAILeapAtTarget(this, 0.3F));
    this.tasks.addTask(8, new EntityAIOcelotAttack(this));
    this.tasks.addTask(9, new EntityAIMate(this, 0.8D));
    this.tasks.addTask(10, new EntityAIWanderAvoidWater(this, 0.8D, 1.0000001E-5F));
    this.tasks.addTask(11, new EntityAIWatchClosest(this, EntityPlayer.class, 10.0F));
    this.targetTasks.addTask(1, new EntityAITargetNonTamed(this, EntityChicken.class, false, (Predicate)null));
}
 
Example 4
Project: BaseClient   File: BlockPattern.java   View source code 6 votes vote down vote up
public BlockPattern(Predicate<BlockWorldState>[][][] predicatesIn)
{
    this.blockMatches = predicatesIn;
    this.fingerLength = predicatesIn.length;

    if (this.fingerLength > 0)
    {
        this.thumbLength = predicatesIn[0].length;

        if (this.thumbLength > 0)
        {
            this.palmLength = predicatesIn[0][0].length;
        }
        else
        {
            this.palmLength = 0;
        }
    }
    else
    {
        this.thumbLength = 0;
        this.palmLength = 0;
    }
}
 
Example 5
Project: reflect   File: Example.java   View source code 6 votes vote down vote up
private static void resources() {
  Resources rs1 = Scanner.paths("/io/ytcode/reflect/").scan();

  Resources rs2 = rs1.pattern(".*/resource/.*").suffix(".class");
  System.out.println(rs2.size());

  Resources rs3 =
      rs1.filter(
          new Predicate<Resource>() {
            @Override
            public boolean apply(Resource r) {
              return r.name().endsWith(".xml");
            }
          });
  System.out.println(rs3.size());
}
 
Example 6
Project: DecompiledMinecraft   File: EntityAIAvoidEntity.java   View source code 6 votes vote down vote up
public EntityAIAvoidEntity(EntityCreature p_i46405_1_, Class<T> p_i46405_2_, Predicate <? super T > p_i46405_3_, float p_i46405_4_, double p_i46405_5_, double p_i46405_7_)
{
    this.canBeSeenSelector = new Predicate<Entity>()
    {
        public boolean apply(Entity p_apply_1_)
        {
            return p_apply_1_.isEntityAlive() && EntityAIAvoidEntity.this.theEntity.getEntitySenses().canSee(p_apply_1_);
        }
    };
    this.theEntity = p_i46405_1_;
    this.field_181064_i = p_i46405_2_;
    this.avoidTargetSelector = p_i46405_3_;
    this.avoidDistance = p_i46405_4_;
    this.farSpeed = p_i46405_5_;
    this.nearSpeed = p_i46405_7_;
    this.entityPathNavigate = p_i46405_1_.getNavigator();
    this.setMutexBits(1);
}
 
Example 7
Project: vscrawler   File: EventLoop.java   View source code 6 votes vote down vote up
public void offerEvent(final Event event) {
    if (!isRunning.get()) {
        log.warn("程序已停止");
        return;
    }
    if (!allHandlers.containsKey(event.getTopic()) || allHandlers.get(event.getTopic()).size() < 0) {
        log.debug("cannot find handle for event:{}", event.getTopic());
        return;
    }
    if (event.isSync()) {
        disPatch(event);
        return;
    }
    if (event.isCleanExpire()) {
        eventQueue.removeAll(Collections2.filter(eventQueue, new Predicate<Event>() {
            @Override
            public boolean apply(Event input) {
                return StringUtils.equals(input.getTopic(), event.getTopic());
            }
        }));
    }
    eventQueue.put(event);


}
 
Example 8
Project: DecompiledMinecraft   File: FactoryBlockPattern.java   View source code 6 votes vote down vote up
private void checkMissingPredicates()
{
    List<Character> list = Lists.<Character>newArrayList();

    for (Entry<Character, Predicate<BlockWorldState>> entry : this.symbolMap.entrySet())
    {
        if (entry.getValue() == null)
        {
            list.add(entry.getKey());
        }
    }

    if (!list.isEmpty())
    {
        throw new IllegalStateException("Predicates for character(s) " + COMMA_JOIN.join(list) + " are missing");
    }
}
 
Example 9
Project: CountryCurrencyPicker   File: Country.java   View source code 6 votes vote down vote up
public static ArrayList<Country> listAll(Context context, final String filter) {
    ArrayList<Country> list = new ArrayList<>();

    for (String countryCode : Locale.getISOCountries()) {
        Country country = getCountry(countryCode, context);

        list.add(country);
    }

    sortList(list);

    if (filter != null && filter.length() > 0) {
        return new ArrayList<>(Collections2.filter(list, new Predicate<Country>() {
            @Override
            public boolean apply(Country input) {
                return input.getName().toLowerCase().contains(filter.toLowerCase());
            }
        }));
    } else {
        return list;
    }
}
 
Example 10
Project: tac-kbp-eal   File: ScoreKBPAgainstERE.java   View source code 6 votes vote down vote up
@Inject
ScoreKBPAgainstERE(
    final Parameters params,
    final Map<String, ScoringEventObserver<DocLevelEventArg, DocLevelEventArg>> scoringEventObservers,
    final ResponsesAndLinkingFromEREExtractor responsesAndLinkingFromEREExtractor,
    ResponsesAndLinkingFromKBPExtractorFactory responsesAndLinkingFromKBPExtractorFactory,
    @DocIDsToScoreP Set<Symbol> docIdsToScore,
    @KeyFileMapP Map<Symbol, File> keyFilesMap,
    Predicate<DocLevelEventArg> inScopePredicate,
    @PermitMissingSystemDocsP boolean permitMissingSystemDocuments) {
  this.params = checkNotNull(params);
  // we use a sorted map because the binding of plugins may be non-deterministic
  this.scoringEventObservers = ImmutableSortedMap.copyOf(scoringEventObservers);
  this.responsesAndLinkingFromEREExtractor = checkNotNull(responsesAndLinkingFromEREExtractor);
  this.responsesAndLinkingFromKBPExtractorFactory = responsesAndLinkingFromKBPExtractorFactory;
  this.docIDsToScore = ImmutableSet.copyOf(docIdsToScore);
  this.goldDocIDToFileMap = ImmutableMap.copyOf(keyFilesMap);
  this.inScopePredicate = inScopePredicate;
  this.permitMissingSystemDocuments = permitMissingSystemDocuments;
}
 
Example 11
Project: Backmemed   File: EntityAIFindEntityNearest.java   View source code 6 votes vote down vote up
public EntityAIFindEntityNearest(EntityLiving mobIn, Class <? extends EntityLivingBase > p_i45884_2_)
{
    this.mob = mobIn;
    this.classToCheck = p_i45884_2_;

    if (mobIn instanceof EntityCreature)
    {
        LOGGER.warn("Use NearestAttackableTargetGoal.class for PathfinerMob mobs!");
    }

    this.predicate = new Predicate<EntityLivingBase>()
    {
        public boolean apply(@Nullable EntityLivingBase p_apply_1_)
        {
            double d0 = EntityAIFindEntityNearest.this.getFollowRange();

            if (p_apply_1_.isSneaking())
            {
                d0 *= 0.800000011920929D;
            }

            return p_apply_1_.isInvisible() ? false : ((double)p_apply_1_.getDistanceToEntity(EntityAIFindEntityNearest.this.mob) > d0 ? false : EntityAITarget.isSuitableTarget(EntityAIFindEntityNearest.this.mob, p_apply_1_, false, true));
        }
    };
    this.sorter = new EntityAINearestAttackableTarget.Sorter(mobIn);
}
 
Example 12
Project: BaseClient   File: Chunk.java   View source code 6 votes vote down vote up
public <T extends Entity> void getEntitiesOfTypeWithinAAAB(Class <? extends T > entityClass, AxisAlignedBB aabb, List<T> listToFill, Predicate <? super T > p_177430_4_)
{
    int i = MathHelper.floor_double((aabb.minY - 2.0D) / 16.0D);
    int j = MathHelper.floor_double((aabb.maxY + 2.0D) / 16.0D);
    i = MathHelper.clamp_int(i, 0, this.entityLists.length - 1);
    j = MathHelper.clamp_int(j, 0, this.entityLists.length - 1);

    for (int k = i; k <= j; ++k)
    {
        for (T t : this.entityLists[k].getByClass(entityClass))
        {
            if (t.getEntityBoundingBox().intersectsWith(aabb) && (p_177430_4_ == null || p_177430_4_.apply(t)))
            {
                listToFill.add(t);
            }
        }
    }
}
 
Example 13
Project: Backmemed   File: Chunk.java   View source code 6 votes vote down vote up
public <T extends Entity> void getEntitiesOfTypeWithinAAAB(Class <? extends T > entityClass, AxisAlignedBB aabb, List<T> listToFill, Predicate <? super T > filter)
{
    int i = MathHelper.floor((aabb.minY - 2.0D) / 16.0D);
    int j = MathHelper.floor((aabb.maxY + 2.0D) / 16.0D);
    i = MathHelper.clamp(i, 0, this.entityLists.length - 1);
    j = MathHelper.clamp(j, 0, this.entityLists.length - 1);

    for (int k = i; k <= j; ++k)
    {
        for (T t : this.entityLists[k].getByClass(entityClass))
        {
            if (t.getEntityBoundingBox().intersectsWith(aabb) && (filter == null || filter.apply(t)))
            {
                listToFill.add(t);
            }
        }
    }
}
 
Example 14
Project: Backmemed   File: MultipartBakedModel.java   View source code 6 votes vote down vote up
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand)
{
    List<BakedQuad> list = Lists.<BakedQuad>newArrayList();

    if (state != null)
    {
        for (Entry<Predicate<IBlockState>, IBakedModel> entry : this.selectors.entrySet())
        {
            if (((Predicate)entry.getKey()).apply(state))
            {
                list.addAll(((IBakedModel)entry.getValue()).getQuads(state, side, rand++));
            }
        }
    }

    return list;
}
 
Example 15
Project: dremio-oss   File: ConvertFromJsonOperator.java   View source code 5 votes vote down vote up
/**
 * Update field schema
 * @param datasetConfig old dataset config
 * @param fieldName field's name
 * @param fieldSchema new field schema
 * @return updated dataset config
 */
private DatasetConfig updateDatasetField(DatasetConfig datasetConfig, final String fieldName, CompleteType fieldSchema) {
  // clone the dataset config
  Serializer<DatasetConfig> serializer = ProtostuffSerializer.of(DatasetConfig.getSchema());
  DatasetConfig newDatasetConfig = serializer.deserialize(serializer.serialize(datasetConfig));

  List<DatasetField> datasetFields = newDatasetConfig.getDatasetFieldsList();
  if (datasetFields == null) {
    datasetFields = Lists.newArrayList();
  }

  DatasetField datasetField = Iterables.find(datasetFields, new Predicate<DatasetField>() {
    @Override
    public boolean apply(@Nullable DatasetField input) {
      return fieldName.equals(input.getFieldName());
    }
  }, null);

  if (datasetField == null) {
    datasetField = new DatasetField().setFieldName(fieldName);
    datasetFields.add(datasetField);
  }

  datasetField.setFieldSchema(ByteString.copyFrom(fieldSchema.serialize()));
  newDatasetConfig.setDatasetFieldsList(datasetFields);

  return newDatasetConfig;
}
 
Example 16
Project: ArchUnit   File: Locations.java   View source code 5 votes vote down vote up
private static Set<Location> jarLocationsOf(URLClassLoader loader) {
    return FluentIterable.from(Locations.of(ImmutableSet.copyOf(loader.getURLs())))
            .filter(new Predicate<Location>() {
                @Override
                public boolean apply(Location input) {
                    return input.isJar();
                }
            }).toSet();
}
 
Example 17
Project: Mods   File: ItemFromData.java   View source code 5 votes vote down vote up
public static ItemStack getRandomWeapon(Random random, Predicate<WeaponData> predicate) {

		ArrayList<String> weapons = new ArrayList<>();
		for (Entry<String, WeaponData> entry : MapList.nameToData.entrySet())
			if (predicate.apply(entry.getValue())){
				weapons.add(entry.getKey());
			}
		if (weapons.isEmpty())
			return ItemStack.EMPTY;
		return getNewStack(weapons.get(random.nextInt(weapons.size())));
	}
 
Example 18
Project: Reer   File: LibraryResolutionResult.java   View source code 5 votes vote down vote up
public static LibraryResolutionResult of(Class<? extends Binary> binaryType, Collection<? extends VariantComponent> libraries, String libraryName, Predicate<? super VariantComponent> libraryFilter) {
    LibraryResolutionResult result = new LibraryResolutionResult(binaryType);
    for (VariantComponent librarySpec : libraries) {
        if (libraryFilter.apply(librarySpec)) {
            result.libsMatchingRequirements.put(librarySpec.getName(), librarySpec);
        } else {
            result.libsNotMatchingRequirements.put(librarySpec.getName(), librarySpec);
        }
    }
    result.resolve(libraryName);
    return result;
}
 
Example 19
Project: morf   File: TableOutputter.java   View source code 5 votes vote down vote up
/**
 * Indicates if the table has a column with a column type which we can't
 * output to a spreadsheet.
 *
 * @param table The table metadata.
 * @return
 */
boolean tableHasUnsupportedColumns(Table table) {
  return Iterables.any(table.columns(), new Predicate<Column>() {
    @Override
    public boolean apply(Column column) {
      return !supportedDataTypes.contains(column.getType());
    }
  });
}
 
Example 20
Project: dremio-oss   File: AccelerationStore.java   View source code 5 votes vote down vote up
public Optional<Layout> getLayoutById(final LayoutId id) {
  final Optional<Acceleration> acceleration = getByIndex(AccelerationIndexKeys.LAYOUT_ID, id.getId());
  if (!acceleration.isPresent()) {
    return Optional.absent();
  }

  return Iterables.tryFind(AccelerationUtils.getAllLayouts(acceleration.get()), new Predicate<Layout>() {
    @Override
    public boolean apply(@Nullable final Layout current) {
      return id.equals(current.getId());
    }
  });
}
 
Example 21
Project: Reer   File: DefaultModelSchemaExtractor.java   View source code 5 votes vote down vote up
private void pushUnsatisfiedDependencies(Iterable<? extends DefaultModelSchemaExtractionContext<?>> allDependencies, Queue<DefaultModelSchemaExtractionContext<?>> dependencyQueue, final ModelSchemaCache cache) {
    Iterables.addAll(dependencyQueue, Iterables.filter(allDependencies, new Predicate<ModelSchemaExtractionContext<?>>() {
        public boolean apply(ModelSchemaExtractionContext<?> dependency) {
            return cache.get(dependency.getType()) == null;
        }
    }));
}
 
Example 22
Project: Mods   File: EntityHHH.java   View source code 5 votes vote down vote up
protected void initEntityAI()
  {
this.tasks.addTask(1, new EntityAISwimming(this));
this.tasks.addTask(2, new EntityAIAttackMelee(this, 1.0D, false));
this.tasks.addTask(6, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
this.tasks.addTask(6, new EntityAILookIdle(this));
this.targetTasks.addTask(1, new EntityAINearestAttackableTarget<EntityLivingBase>(this, EntityLivingBase.class,2, false,false,new Predicate<EntityLivingBase>(){

	@Override
	public boolean apply(EntityLivingBase input) {
		// TODO Auto-generated method stub
		return input.getActivePotionEffect(TF2weapons.it)!=null;
	}
      	
      }));
/*this.targetTasks.addTask(2, new EntityAIHurtByTarget(this, false, new Class[0]));
      this.targetTasks.addTask(3, new EntityAINearestAttackableTarget<EntityLivingBase>(this, EntityLivingBase.class,2, false,false,new Predicate<EntityLivingBase>(){

	@Override
	public boolean apply(EntityLivingBase input) {
		// TODO Auto-generated method stub
		return (input instanceof EntityTF2Character || input instanceof EntityPlayer) && getDistanceSqToEntity(input)<600;
	}
      	
      }));*/
      
  }
 
Example 23
Project: empiria.player   File: HTML5MediaEventMapperJUnitTest.java   View source code 5 votes vote down vote up
public Object[] parametersForShouldNotCallListener_ifNorEndedNorPlay() {
    List<HTML5MediaEventsType> events = FluentIterable.from(Lists.newArrayList(HTML5MediaEventsType.values()))
            .filter(new Predicate<HTML5MediaEventsType>() {

                @Override
                public boolean apply(HTML5MediaEventsType type) {
                    return type != play && type != ended;
                }

            })
            .toList();

    return $(events.toArray());
}
 
Example 24
Project: guava-mock   File: Sets.java   View source code 5 votes vote down vote up
/**
 * Returns an unmodifiable <b>view</b> of the difference of two sets. The
 * returned set contains all elements that are contained by {@code set1} and
 * not contained by {@code set2}. {@code set2} may also contain elements not
 * present in {@code set1}; these are simply ignored. The iteration order of
 * the returned set matches that of {@code set1}.
 *
 * <p>Results are undefined if {@code set1} and {@code set2} are sets based
 * on different equivalence relations (as {@code HashSet}, {@code TreeSet},
 * and the keySet of an {@code IdentityHashMap} all are).
 */
public static <E> SetView<E> difference(final Set<E> set1, final Set<?> set2) {
  checkNotNull(set1, "set1");
  checkNotNull(set2, "set2");

  final Predicate<Object> notInSet2 = Predicates.not(Predicates.in(set2));
  return new SetView<E>() {
    @Override
    public UnmodifiableIterator<E> iterator() {
      return Iterators.filter(set1.iterator(), notInSet2);
    }

    @Override
    public Stream<E> stream() {
      return set1.stream().filter(notInSet2);
    }

    @Override
    public Stream<E> parallelStream() {
      return set1.parallelStream().filter(notInSet2);
    }

    @Override
    public int size() {
      return Iterators.size(iterator());
    }

    @Override
    public boolean isEmpty() {
      return set2.containsAll(set1);
    }

    @Override
    public boolean contains(Object element) {
      return set1.contains(element) && !set2.contains(element);
    }
  };
}
 
Example 25
Project: Backmemed   File: EntityEnderman.java   View source code 5 votes vote down vote up
public boolean shouldExecute()
{
    double d0 = this.getTargetDistance();
    this.player = this.enderman.world.getNearestAttackablePlayer(this.enderman.posX, this.enderman.posY, this.enderman.posZ, d0, d0, (Function<EntityPlayer, Double>)null, new Predicate<EntityPlayer>()
    {
        public boolean apply(@Nullable EntityPlayer p_apply_1_)
        {
            return p_apply_1_ != null && AIFindPlayer.this.enderman.shouldAttackPlayer(p_apply_1_);
        }
    });
    return this.player != null;
}
 
Example 26
Project: CustomWorldGen   File: ConditionAnd.java   View source code 5 votes vote down vote up
public Predicate<IBlockState> getPredicate(final BlockStateContainer blockState)
{
    return Predicates.and(Iterables.transform(this.conditions, new Function<ICondition, Predicate<IBlockState>>()
    {
        @Nullable
        public Predicate<IBlockState> apply(@Nullable ICondition p_apply_1_)
        {
            return p_apply_1_ == null ? null : p_apply_1_.getPredicate(blockState);
        }
    }));
}
 
Example 27
Project: DecompiledMinecraft   File: EntityGuardian.java   View source code 5 votes vote down vote up
protected void updateAITasks()
{
    super.updateAITasks();

    if (this.isElder())
    {
        int i = 1200;
        int j = 1200;
        int k = 6000;
        int l = 2;

        if ((this.ticksExisted + this.getEntityId()) % 1200 == 0)
        {
            Potion potion = Potion.digSlowdown;

            for (EntityPlayerMP entityplayermp : this.worldObj.getPlayers(EntityPlayerMP.class, new Predicate<EntityPlayerMP>()
        {
            public boolean apply(EntityPlayerMP p_apply_1_)
                {
                    return EntityGuardian.this.getDistanceSqToEntity(p_apply_1_) < 2500.0D && p_apply_1_.theItemInWorldManager.survivalOrAdventure();
                }
            }))
            {
                if (!entityplayermp.isPotionActive(potion) || entityplayermp.getActivePotionEffect(potion).getAmplifier() < 2 || entityplayermp.getActivePotionEffect(potion).getDuration() < 1200)
                {
                    entityplayermp.playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(10, 0.0F));
                    entityplayermp.addPotionEffect(new PotionEffect(potion.id, 6000, 2));
                }
            }
        }

        if (!this.hasHome())
        {
            this.setHomePosAndDistance(new BlockPos(this), 16);
        }
    }
}
 
Example 28
Project: CountryCurrencyPicker   File: Currency.java   View source code 5 votes vote down vote up
@Nullable
public static Currency getCurrencyWithCountries(java.util.Currency currency, Context context) {
    final Currency myCurrency = getCurrency(currency, context);

    if (tmpCountries == null) {
        tmpCountries = Country.listAllWithCurrencies(context, null);
    }

    ArrayList<Country> foundCountries = new ArrayList<>(Collections2.filter(tmpCountries, new Predicate<Country>() {
        @Override
        public boolean apply(Country input) {
            return input.getCurrency().getCode().equals(myCurrency.getCode());
        }
    }));

    if (foundCountries.size() > 0) {
        myCurrency.setCountries(foundCountries);

        ArrayList<String> names = new ArrayList<>();
        for (Country country : foundCountries) {
            names.add(country.getName());
        }
        myCurrency.setCountriesNames(names);

        return myCurrency;
    }
    return null;
}
 
Example 29
Project: empiria.player   File: FeedbackActionCollector.java   View source code 5 votes vote down vote up
private Collection<IModule> getSourcesToClear(final IModule currentModule) {
    Set<IModule> modulesCopy = Sets.newHashSet(source2actions.keySet());

    Predicate<IModule> isParentPredicate = new Predicate<IModule>() {
        @Override
        public boolean apply(IModule source) {
            List<HasChildren> parents = getParentHierarchy(source);
            return parents.contains(currentModule);
        }
    };
    return Collections2.filter(modulesCopy, isParentPredicate);
}
 
Example 30
Project: andbg   File: CollectionUtils.java   View source code 5 votes vote down vote up
public static <T> int lastIndexOf(@Nonnull Iterable<T> iterable, @Nonnull Predicate<? super T> predicate) {
    int index = 0;
    int lastMatchingIndex = -1;
    for (T item: iterable) {
        if (predicate.apply(item)) {
            lastMatchingIndex = index;
        }
        index++;
    }
    return lastMatchingIndex;
}
 
Example 31
Project: n4js   File: DefaultN4GlobalScopeProvider.java   View source code 5 votes vote down vote up
/**
 * If the type is a {@link Type} a new {@link BuiltInTypeScope} is created.
 */
@Override
protected IScope getScope(Resource context, boolean ignoreCase, EClass type, Predicate<IEObjectDescription> filter) {
	if (isSubtypeOfType(type)) {
		return getScope(getBuiltInTypeScope(context), context, ignoreCase, type, filter);
	}
	// do not call super but directly redirect with nullscope, using IScopeExt.NULLSCOPE instead of IScope.NULLSCOPE
	return getScope(IScope.NULLSCOPE, context, ignoreCase, type, filter);
}
 
Example 32
Project: Backmemed   File: EntityAIAvoidEntity.java   View source code 5 votes vote down vote up
/**
 * Returns whether the EntityAIBase should begin execution.
 */
public boolean shouldExecute()
{
    List<T> list = this.theEntity.world.<T>getEntitiesWithinAABB(this.classToAvoid, this.theEntity.getEntityBoundingBox().expand((double)this.avoidDistance, 3.0D, (double)this.avoidDistance), Predicates.and(new Predicate[] {EntitySelectors.CAN_AI_TARGET, this.canBeSeenSelector, this.avoidTargetSelector}));

    if (list.isEmpty())
    {
        return false;
    }
    else
    {
        this.closestLivingEntity = list.get(0);
        Vec3d vec3d = RandomPositionGenerator.findRandomTargetBlockAwayFrom(this.theEntity, 16, 7, new Vec3d(this.closestLivingEntity.posX, this.closestLivingEntity.posY, this.closestLivingEntity.posZ));

        if (vec3d == null)
        {
            return false;
        }
        else if (this.closestLivingEntity.getDistanceSq(vec3d.xCoord, vec3d.yCoord, vec3d.zCoord) < this.closestLivingEntity.getDistanceSqToEntity(this.theEntity))
        {
            return false;
        }
        else
        {
            this.entityPathEntity = this.entityPathNavigate.getPathToXYZ(vec3d.xCoord, vec3d.yCoord, vec3d.zCoord);
            return this.entityPathEntity != null;
        }
    }
}
 
Example 33
Project: googles-monorepo-demo   File: Maps.java   View source code 5 votes vote down vote up
private static <K, V> Predicate<Entry<V, K>> inversePredicate(
    final Predicate<? super Entry<K, V>> forwardPredicate) {
  return new Predicate<Entry<V, K>>() {
    @Override
    public boolean apply(Entry<V, K> input) {
      return forwardPredicate.apply(Maps.immutableEntry(input.getValue(), input.getKey()));
    }
  };
}
 
Example 34
Project: dremio-oss   File: PlanningStage.java   View source code 5 votes vote down vote up
public static List<ViewFieldType> removeUpdateColumn(final List<ViewFieldType> fields) {
  return FluentIterable.from(fields).filter(new Predicate<ViewFieldType>() {
    @Override
    public boolean apply(@Nullable ViewFieldType input) {
      return !IncrementalUpdateUtils.UPDATE_COLUMN.equals(input.getName());
    }
  }).toList();
}
 
Example 35
Project: BaseClient   File: BlockRailDetector.java   View source code 5 votes vote down vote up
private void updatePoweredState(World worldIn, BlockPos pos, IBlockState state)
{
    boolean flag = ((Boolean)state.getValue(POWERED)).booleanValue();
    boolean flag1 = false;
    List<EntityMinecart> list = this.<EntityMinecart>findMinecarts(worldIn, pos, EntityMinecart.class, new Predicate[0]);

    if (!list.isEmpty())
    {
        flag1 = true;
    }

    if (flag1 && !flag)
    {
        worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(true)), 3);
        worldIn.notifyNeighborsOfStateChange(pos, this);
        worldIn.notifyNeighborsOfStateChange(pos.down(), this);
        worldIn.markBlockRangeForRenderUpdate(pos, pos);
    }

    if (!flag1 && flag)
    {
        worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(false)), 3);
        worldIn.notifyNeighborsOfStateChange(pos, this);
        worldIn.notifyNeighborsOfStateChange(pos.down(), this);
        worldIn.markBlockRangeForRenderUpdate(pos, pos);
    }

    if (flag1)
    {
        worldIn.scheduleUpdate(pos, this, this.tickRate(worldIn));
    }

    worldIn.updateComparatorOutputLevel(pos, this);
}
 
Example 36
Project: Equella   File: SearchWhereModel.java   View source code 5 votes vote down vote up
private Iterable<BaseEntityLabel> filterByUuids(Iterable<BaseEntityLabel> entities, final Set<String> uuids)
{
	return filter(entities, new Predicate<BaseEntityLabel>()
	{
		@Override
		public boolean apply(@Nullable BaseEntityLabel label)
		{
			return uuids.contains(label.getUuid());
		}
	});
}
 
Example 37
Project: robird-reborn   File: BaseTimelineFragment.java   View source code 5 votes vote down vote up
protected int findPosition(final long tweetId) {
    return Iterables.indexOf(mTweets, new Predicate<Tweet>() {
        @Override
        public boolean apply(Tweet input) {
            return tweetId == input.tweetId();
        }
    });
}
 
Example 38
Project: tac-kbp-eal   File: EREAligner.java   View source code 5 votes vote down vote up
@MoveToBUECommon
static <T> Predicate<Collection<T>> containsElement(final T element) {
  return new Predicate<Collection<T>>() {
    @Override
    public boolean apply(@Nullable final Collection<T> input) {
      return checkNotNull(input).contains(element);
    }
  };
}
 
Example 39
Project: guava-mock   File: MoreFiles.java   View source code 5 votes vote down vote up
/**
 * Returns a predicate that returns the result of {@link Files#isDirectory(Path, LinkOption...)}
 * on input paths with the given link options.
 */
public static Predicate<Path> isDirectory(LinkOption... options) {
  final LinkOption[] optionsCopy = options.clone();
  return new Predicate<Path>() {
    @Override
    public boolean apply(Path input) {
      return Files.isDirectory(input, optionsCopy);
    }

    @Override
    public String toString() {
      return "MoreFiles.isDirectory(" + Arrays.toString(optionsCopy) + ")";
    }
  };
}
 
Example 40
Project: GitHub   File: Use.java   View source code 5 votes vote down vote up
public static void main(String... args) {
  Predicate<Val> empty = ValFunctions.isEmpty();
  Function<Val, String> name = ValFunctions.getName();
  Function<Val, Integer> age = ValFunctions.age();
  System.out.println(empty);
  System.out.println(name);
  System.out.println(age);
}