当前位置: 首页>>代码示例>>Java>>正文


Java Predicates.and方法代码示例

本文整理汇总了Java中com.google.common.base.Predicates.and方法的典型用法代码示例。如果您正苦于以下问题:Java Predicates.and方法的具体用法?Java Predicates.and怎么用?Java Predicates.and使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.base.Predicates的用法示例。


在下文中一共展示了Predicates.and方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generateUriPredicate

import com.google.common.base.Predicates; //导入方法依赖的package包/类
private Predicate<URI> generateUriPredicate(FileInput fileInput, @Nullable Predicate<URI> globPredicate) {
    Predicate<URI> moduloPredicate;
    boolean sharedStorage = MoreObjects.firstNonNull(shared, fileInput.sharedStorageDefault());
    if (sharedStorage) {
        moduloPredicate = new Predicate<URI>() {
            @Override
            public boolean apply(URI input) {
                int hash = input.hashCode();
                if (hash == Integer.MIN_VALUE) {
                    hash = 0; // Math.abs(Integer.MIN_VALUE) == Integer.MIN_VALUE
                }
                return Math.abs(hash) % numReaders == readerNumber;
            }
        };
    } else {
        moduloPredicate = MATCH_ALL_PREDICATE;
    }

    if (globPredicate != null) {
        return Predicates.and(moduloPredicate, globPredicate);
    }
    return moduloPredicate;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:24,代码来源:FileReadingCollector.java

示例2: shouldExecute

import com.google.common.base.Predicates; //导入方法依赖的package包/类
/**
 * Returns whether the EntityAIBase should begin execution.
 */
public boolean shouldExecute()
{
    if (this.theWatcher.getRNG().nextFloat() >= this.chance)
    {
        return false;
    }
    else
    {
        if (this.theWatcher.getAttackTarget() != null)
        {
            this.closestEntity = this.theWatcher.getAttackTarget();
        }

        if (this.watchedClass == EntityPlayer.class)
        {
            Predicate<Entity> predicate = Predicates.<Entity> and (EntitySelectors.NOT_SPECTATING, EntitySelectors.func_191324_b(this.theWatcher));
            this.closestEntity = this.theWatcher.world.func_190525_a(this.theWatcher.posX, this.theWatcher.posY, this.theWatcher.posZ, (double)this.maxDistanceForPlayer, predicate);
        }
        else
        {
            this.closestEntity = this.theWatcher.world.findNearestEntityWithinAABB(this.watchedClass, this.theWatcher.getEntityBoundingBox().expand((double)this.maxDistanceForPlayer, 3.0D, (double)this.maxDistanceForPlayer), this.theWatcher);
        }

        return this.closestEntity != null;
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:30,代码来源:EntityAIWatchClosest.java

示例3: getTeamCollisionPredicate

import com.google.common.base.Predicates; //导入方法依赖的package包/类
public static <T extends Entity> Predicate<T> getTeamCollisionPredicate(final Entity entityIn)
{
    final Team team = entityIn.getTeam();
    final Team.CollisionRule team$collisionrule = team == null ? Team.CollisionRule.ALWAYS : team.getCollisionRule();
    Predicate<?> ret = team$collisionrule == Team.CollisionRule.NEVER ? Predicates.alwaysFalse() : Predicates.and(NOT_SPECTATING, new Predicate<Entity>()
    {
        public boolean apply(@Nullable Entity p_apply_1_)
        {
            if (!p_apply_1_.canBePushed())
            {
                return false;
            }
            else if (!entityIn.worldObj.isRemote || p_apply_1_ instanceof EntityPlayer && ((EntityPlayer)p_apply_1_).isUser())
            {
                Team team1 = p_apply_1_.getTeam();
                Team.CollisionRule team$collisionrule1 = team1 == null ? Team.CollisionRule.ALWAYS : team1.getCollisionRule();

                if (team$collisionrule1 == Team.CollisionRule.NEVER)
                {
                    return false;
                }
                else
                {
                    boolean flag = team != null && team.isSameTeam(team1);
                    return (team$collisionrule == Team.CollisionRule.HIDE_FOR_OWN_TEAM || team$collisionrule1 == Team.CollisionRule.HIDE_FOR_OWN_TEAM) && flag ? false : team$collisionrule != Team.CollisionRule.HIDE_FOR_OTHER_TEAMS && team$collisionrule1 != Team.CollisionRule.HIDE_FOR_OTHER_TEAMS || flag;
                }
            }
            else
            {
                return false;
            }
        }
    });
    return (Predicate<T>)ret;
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:36,代码来源:EntitySelectors.java

示例4: filterFiltered

import com.google.common.base.Predicates; //导入方法依赖的package包/类
/**
 * Support removal operations when filtering a filtered multimap. Since a filtered multimap has
 * iterators that don't support remove, passing one to the FilteredEntryMultimap constructor would
 * lead to a multimap whose removal operations would fail. This method combines the predicates to
 * avoid that problem.
 */
private static <K, V> SetMultimap<K, V> filterFiltered(
    FilteredSetMultimap<K, V> multimap, Predicate<? super Entry<K, V>> entryPredicate) {
  Predicate<Entry<K, V>> predicate =
      Predicates.<Entry<K, V>>and(multimap.entryPredicate(), entryPredicate);
  return new FilteredEntrySetMultimap<K, V>(multimap.unfiltered(), predicate);
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:13,代码来源:Multimaps.java

示例5: getPredicate

import com.google.common.base.Predicates; //导入方法依赖的package包/类
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);
        }
    }));
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:12,代码来源:ConditionAnd.java

示例6: createCombined

import com.google.common.base.Predicates; //导入方法依赖的package包/类
FilteredCollection<E> createCombined(Predicate<? super E> newPredicate) {
  return new FilteredCollection<E>(unfiltered, Predicates.<E>and(predicate, newPredicate));
  // .<E> above needed to compile in JDK 5
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:5,代码来源:Collections2.java

示例7: filter

import com.google.common.base.Predicates; //导入方法依赖的package包/类
/**
 * Returns the elements of {@code unfiltered} that satisfy a predicate. The
 * returned set is a live view of {@code unfiltered}; changes to one affect
 * the other.
 *
 * <p>The resulting set's iterator does not support {@code remove()}, but all
 * other set methods are supported. When given an element that doesn't satisfy
 * the predicate, the set's {@code add()} and {@code addAll()} methods throw
 * an {@link IllegalArgumentException}. When methods such as {@code
 * removeAll()} and {@code clear()} are called on the filtered set, only
 * elements that satisfy the filter will be removed from the underlying set.
 *
 * <p>The returned set isn't threadsafe or serializable, even if
 * {@code unfiltered} is.
 *
 * <p>Many of the filtered set's methods, such as {@code size()}, iterate
 * across every element in the underlying set and determine which elements
 * satisfy the filter. When a live view is <i>not</i> needed, it may be faster
 * to copy {@code Iterables.filter(unfiltered, predicate)} and use the copy.
 *
 * <p><b>Warning:</b> {@code predicate} must be <i>consistent with equals</i>,
 * as documented at {@link Predicate#apply}. Do not provide a predicate such
 * as {@code Predicates.instanceOf(ArrayList.class)}, which is inconsistent
 * with equals. (See {@link Iterables#filter(Iterable, Class)} for related
 * functionality.)
 *
 * <p><b>Java 8 users:</b> many use cases for this method are better
 * addressed by {@link java.util.stream.Stream#filter}. This method is not
 * being deprecated, but we gently encourage you to migrate to streams.
 */
// TODO(kevinb): how to omit that last sentence when building GWT javadoc?
public static <E> Set<E> filter(Set<E> unfiltered, Predicate<? super E> predicate) {
  if (unfiltered instanceof SortedSet) {
    return filter((SortedSet<E>) unfiltered, predicate);
  }
  if (unfiltered instanceof FilteredSet) {
    // Support clear(), removeAll(), and retainAll() when filtering a filtered
    // collection.
    FilteredSet<E> filtered = (FilteredSet<E>) unfiltered;
    Predicate<E> combinedPredicate = Predicates.<E>and(filtered.predicate, predicate);
    return new FilteredSet<E>((Set<E>) filtered.unfiltered, combinedPredicate);
  }

  return new FilteredSet<E>(checkNotNull(unfiltered), checkNotNull(predicate));
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:46,代码来源:Sets.java

示例8: filterFiltered

import com.google.common.base.Predicates; //导入方法依赖的package包/类
/**
 * Support {@code clear()}, {@code removeAll()}, and {@code retainAll()} when
 * filtering a filtered sorted map.
 */
private static <K, V> SortedMap<K, V> filterFiltered(
    FilteredEntrySortedMap<K, V> map, Predicate<? super Entry<K, V>> entryPredicate) {
  Predicate<Entry<K, V>> predicate = Predicates.<Entry<K, V>>and(map.predicate, entryPredicate);
  return new FilteredEntrySortedMap<K, V>(map.sortedMap(), predicate);
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:10,代码来源:Maps.java

示例9: filterFiltered

import com.google.common.base.Predicates; //导入方法依赖的package包/类
/**
 * Support {@code clear()}, {@code removeAll()}, and {@code retainAll()} when
 * filtering a filtered map.
 */
private static <K, V> Map<K, V> filterFiltered(
    AbstractFilteredMap<K, V> map, Predicate<? super Entry<K, V>> entryPredicate) {
  return new FilteredEntryMap<K, V>(
      map.unfiltered, Predicates.<Entry<K, V>>and(map.predicate, entryPredicate));
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:10,代码来源:Maps.java

示例10: filterResults

import com.google.common.base.Predicates; //导入方法依赖的package包/类
private static <T extends Entity> List<T> filterResults(Map<String, String> params, Class <? extends T > entityClass, List<Predicate<Entity>> inputList, String type, World worldIn, BlockPos position)
{
    List<T> list = Lists.<T>newArrayList();
    String s = getArgument(params, "type");
    s = s != null && s.startsWith("!") ? s.substring(1) : s;
    boolean flag = !type.equals("e");
    boolean flag1 = type.equals("r") && s != null;
    int i = parseIntWithDefault(params, "dx", 0);
    int j = parseIntWithDefault(params, "dy", 0);
    int k = parseIntWithDefault(params, "dz", 0);
    int l = parseIntWithDefault(params, "r", -1);
    Predicate<Entity> predicate = Predicates.and(inputList);
    Predicate<Entity> predicate1 = Predicates.<Entity>and(EntitySelectors.IS_ALIVE, predicate);
    int i1 = worldIn.playerEntities.size();
    int j1 = worldIn.loadedEntityList.size();
    boolean flag2 = i1 < j1 / 16;

    if (!params.containsKey("dx") && !params.containsKey("dy") && !params.containsKey("dz"))
    {
        if (l >= 0)
        {
            AxisAlignedBB axisalignedbb1 = new AxisAlignedBB((double)(position.getX() - l), (double)(position.getY() - l), (double)(position.getZ() - l), (double)(position.getX() + l + 1), (double)(position.getY() + l + 1), (double)(position.getZ() + l + 1));

            if (flag && flag2 && !flag1)
            {
                list.addAll(worldIn.<T>getPlayers(entityClass, predicate1));
            }
            else
            {
                list.addAll(worldIn.<T>getEntitiesWithinAABB(entityClass, axisalignedbb1, predicate1));
            }
        }
        else if (type.equals("a"))
        {
            list.addAll(worldIn.<T>getPlayers(entityClass, predicate));
        }
        else if (!type.equals("p") && (!type.equals("r") || flag1))
        {
            list.addAll(worldIn.<T>getEntities(entityClass, predicate1));
        }
        else
        {
            list.addAll(worldIn.<T>getPlayers(entityClass, predicate1));
        }
    }
    else
    {
        final AxisAlignedBB axisalignedbb = getAABB(position, i, j, k);

        if (flag && flag2 && !flag1)
        {
            Predicate<Entity> predicate2 = new Predicate<Entity>()
            {
                public boolean apply(@Nullable Entity p_apply_1_)
                {
                    return p_apply_1_ != null && axisalignedbb.intersectsWith(p_apply_1_.getEntityBoundingBox());
                }
            };
            list.addAll(worldIn.<T>getPlayers(entityClass, Predicates.<T>and(predicate1, predicate2)));
        }
        else
        {
            list.addAll(worldIn.<T>getEntitiesWithinAABB(entityClass, axisalignedbb, predicate1));
        }
    }

    return list;
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:69,代码来源:EntitySelector.java

示例11: filterResults

import com.google.common.base.Predicates; //导入方法依赖的package包/类
private static <T extends Entity> List<T> filterResults(Map<String, String> params, Class <? extends T > entityClass, List<Predicate<Entity>> inputList, String type, World worldIn, BlockPos position)
{
    List<T> list = Lists.<T>newArrayList();
    String s = getArgument(params, field_190849_w);
    s = s != null && s.startsWith("!") ? s.substring(1) : s;
    boolean flag = !type.equals("e");
    boolean flag1 = type.equals("r") && s != null;
    int i = getInt(params, field_190838_l, 0);
    int j = getInt(params, field_190839_m, 0);
    int k = getInt(params, field_190840_n, 0);
    int l = getInt(params, field_190831_e, -1);
    Predicate<Entity> predicate = Predicates.and(inputList);
    Predicate<Entity> predicate1 = Predicates.<Entity> and (EntitySelectors.IS_ALIVE, predicate);

    if (!params.containsKey(field_190838_l) && !params.containsKey(field_190839_m) && !params.containsKey(field_190840_n))
    {
        if (l >= 0)
        {
            AxisAlignedBB axisalignedbb1 = new AxisAlignedBB((double)(position.getX() - l), (double)(position.getY() - l), (double)(position.getZ() - l), (double)(position.getX() + l + 1), (double)(position.getY() + l + 1), (double)(position.getZ() + l + 1));

            if (flag && !flag1)
            {
                list.addAll(worldIn.<T>getPlayers(entityClass, predicate1));
            }
            else
            {
                list.addAll(worldIn.<T>getEntitiesWithinAABB(entityClass, axisalignedbb1, predicate1));
            }
        }
        else if (type.equals("a"))
        {
            list.addAll(worldIn.<T>getPlayers(entityClass, predicate));
        }
        else if (!type.equals("p") && (!type.equals("r") || flag1))
        {
            list.addAll(worldIn.<T>getEntities(entityClass, predicate1));
        }
        else
        {
            list.addAll(worldIn.<T>getPlayers(entityClass, predicate1));
        }
    }
    else
    {
        final AxisAlignedBB axisalignedbb = getAABB(position, i, j, k);

        if (flag && !flag1)
        {
            Predicate<Entity> predicate2 = new Predicate<Entity>()
            {
                public boolean apply(@Nullable Entity p_apply_1_)
                {
                    return p_apply_1_ != null && axisalignedbb.intersectsWith(p_apply_1_.getEntityBoundingBox());
                }
            };
            list.addAll(worldIn.<T>getPlayers(entityClass, Predicates.<T> and (predicate1, predicate2)));
        }
        else
        {
            list.addAll(worldIn.<T>getEntitiesWithinAABB(entityClass, axisalignedbb, predicate1));
        }
    }

    return list;
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:66,代码来源:EntitySelector.java

示例12: filterFiltered

import com.google.common.base.Predicates; //导入方法依赖的package包/类
/**
 * Support removal operations when filtering a filtered multimap. Since a
 * filtered multimap has iterators that don't support remove, passing one to
 * the FilteredEntryMultimap constructor would lead to a multimap whose removal
 * operations would fail. This method combines the predicates to avoid that
 * problem.
 */
private static <K, V> Multimap<K, V> filterFiltered(
    FilteredMultimap<K, V> multimap, Predicate<? super Entry<K, V>> entryPredicate) {
  Predicate<Entry<K, V>> predicate =
      Predicates.<Entry<K, V>>and(multimap.entryPredicate(), entryPredicate);
  return new FilteredEntryMultimap<K, V>(multimap.unfiltered(), predicate);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:14,代码来源:Multimaps.java

示例13: filter

import com.google.common.base.Predicates; //导入方法依赖的package包/类
/**
 * Returns a view of the elements of {@code unfiltered} that satisfy a predicate. The returned
 * multiset is a live view of {@code unfiltered}; changes to one affect the other.
 *
 * <p>The resulting multiset's iterators, and those of its {@code entrySet()} and
 * {@code elementSet()}, do not support {@code remove()}.  However, all other multiset methods
 * supported by {@code unfiltered} are supported by the returned multiset. When given an element
 * that doesn't satisfy the predicate, the multiset's {@code add()} and {@code addAll()} methods
 * throw an {@link IllegalArgumentException}. When methods such as {@code removeAll()} and
 * {@code clear()} are called on the filtered multiset, only elements that satisfy the filter
 * will be removed from the underlying multiset.
 *
 * <p>The returned multiset isn't threadsafe or serializable, even if {@code unfiltered} is.
 *
 * <p>Many of the filtered multiset's methods, such as {@code size()}, iterate across every
 * element in the underlying multiset and determine which elements satisfy the filter. When a
 * live view is <i>not</i> needed, it may be faster to copy the returned multiset and use the
 * copy.
 *
 * <p><b>Warning:</b> {@code predicate} must be <i>consistent with equals</i>, as documented at
 * {@link Predicate#apply}. Do not provide a predicate such as
 * {@code Predicates.instanceOf(ArrayList.class)}, which is inconsistent with equals. (See
 * {@link Iterables#filter(Iterable, Class)} for related functionality.)
 *
 * @since 14.0
 */
@Beta
public static <E> Multiset<E> filter(Multiset<E> unfiltered, Predicate<? super E> predicate) {
  if (unfiltered instanceof FilteredMultiset) {
    // Support clear(), removeAll(), and retainAll() when filtering a filtered
    // collection.
    FilteredMultiset<E> filtered = (FilteredMultiset<E>) unfiltered;
    Predicate<E> combinedPredicate = Predicates.<E>and(filtered.predicate, predicate);
    return new FilteredMultiset<E>(filtered.unfiltered, combinedPredicate);
  }
  return new FilteredMultiset<E>(unfiltered, predicate);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:38,代码来源:Multisets.java

示例14: filterKeys

import com.google.common.base.Predicates; //导入方法依赖的package包/类
/**
 * Returns a multimap containing the mappings in {@code unfiltered} whose keys
 * satisfy a predicate. The returned multimap is a live view of
 * {@code unfiltered}; changes to one affect the other.
 *
 * <p>The resulting multimap's views have iterators that don't support
 * {@code remove()}, but all other methods are supported by the multimap and
 * its views. When adding a key that doesn't satisfy the predicate, the
 * multimap's {@code put()}, {@code putAll()}, and {@code replaceValues()}
 * methods throw an {@link IllegalArgumentException}.
 *
 * <p>When methods such as {@code removeAll()} and {@code clear()} are called on
 * the filtered multimap or its views, only mappings whose keys satisfy the
 * filter will be removed from the underlying multimap.
 *
 * <p>The returned multimap isn't threadsafe or serializable, even if
 * {@code unfiltered} is.
 *
 * <p>Many of the filtered multimap's methods, such as {@code size()}, iterate
 * across every key/value mapping in the underlying multimap and determine
 * which satisfy the filter. When a live view is <i>not</i> needed, it may be
 * faster to copy the filtered multimap and use the copy.
 *
 * <p><b>Warning:</b> {@code keyPredicate} must be <i>consistent with equals</i>,
 * as documented at {@link Predicate#apply}. Do not provide a predicate such
 * as {@code Predicates.instanceOf(ArrayList.class)}, which is inconsistent
 * with equals.
 *
 * @since 14.0
 */
public static <K, V> ListMultimap<K, V> filterKeys(
    ListMultimap<K, V> unfiltered, final Predicate<? super K> keyPredicate) {
  if (unfiltered instanceof FilteredKeyListMultimap) {
    FilteredKeyListMultimap<K, V> prev = (FilteredKeyListMultimap<K, V>) unfiltered;
    return new FilteredKeyListMultimap<K, V>(
        prev.unfiltered(), Predicates.<K>and(prev.keyPredicate, keyPredicate));
  } else {
    return new FilteredKeyListMultimap<K, V>(unfiltered, keyPredicate);
  }
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:41,代码来源:Multimaps.java


注:本文中的com.google.common.base.Predicates.and方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。