當前位置: 首頁>>代碼示例>>Java>>正文


Java Predicates類代碼示例

本文整理匯總了Java中com.google.common.base.Predicates的典型用法代碼示例。如果您正苦於以下問題:Java Predicates類的具體用法?Java Predicates怎麽用?Java Predicates使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Predicates類屬於com.google.common.base包,在下文中一共展示了Predicates類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: enclosedBy

import com.google.common.base.Predicates; //導入依賴的package包/類
@Override
public Ordering<Element> enclosedBy(Element element) {
  if (element instanceof ElementImpl &&
      Iterables.all(element.getEnclosedElements(), Predicates.instanceOf(ElementImpl.class))) {

    ElementImpl implementation = (ElementImpl) element;
    if (implementation._binding instanceof SourceTypeBinding) {
      SourceTypeBinding sourceBinding = (SourceTypeBinding) implementation._binding;

      return Ordering.natural().onResultOf(
          Functions.compose(bindingsToSourceOrder(sourceBinding), this));
    }
  }

  return DEFAULT_PROVIDER.enclosedBy(element);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:SourceOrdering.java

示例2: collideWithNearbyEntities

import com.google.common.base.Predicates; //導入依賴的package包/類
protected void collideWithNearbyEntities()
{
    List<Entity> list = this.worldObj.getEntitiesInAABBexcluding(this, this.getEntityBoundingBox().expand(0.20000000298023224D, 0.0D, 0.20000000298023224D), Predicates.<Entity> and (EntitySelectors.NOT_SPECTATING, new Predicate<Entity>()
    {
        public boolean apply(Entity p_apply_1_)
        {
            return p_apply_1_.canBePushed();
        }
    }));

    if (!list.isEmpty())
    {
        for (int i = 0; i < list.size(); ++i)
        {
            Entity entity = (Entity)list.get(i);
            this.collideWithEntity(entity);
        }
    }
}
 
開發者ID:SkidJava,項目名稱:BaseClient,代碼行數:20,代碼來源:EntityLivingBase.java

示例3: testConcatIntersectionType

import com.google.common.base.Predicates; //導入依賴的package包/類
/**
 * This test passes if the {@code concat(…).filter(…).filter(…)} statement at the end compiles.
 * That statement compiles only if {@link FluentIterable#concat concat(aIterable, bIterable)}
 * returns a {@link FluentIterable} of elements of an anonymous type whose supertypes are the
 * <a href="https://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.9">intersection</a>
 * of the supertypes of {@code A} and the supertypes of {@code B}.
 */
public void testConcatIntersectionType() {
  Iterable<A> aIterable = ImmutableList.of();
  Iterable<B> bIterable = ImmutableList.of();

  Predicate<X> xPredicate = Predicates.alwaysTrue();
  Predicate<Y> yPredicate = Predicates.alwaysTrue();

  FluentIterable<?> unused =
      FluentIterable.concat(aIterable, bIterable).filter(xPredicate).filter(yPredicate);

  /* The following fails to compile:
   *
   * The method append(Iterable<? extends FluentIterableTest.A>) in the type
   * FluentIterable<FluentIterableTest.A> is not applicable for the arguments
   * (Iterable<FluentIterableTest.B>)
   */
  // FluentIterable.from(aIterable).append(bIterable);

  /* The following fails to compile:
   *
   * The method filter(Predicate<? super Object>) in the type FluentIterable<Object> is not
   * applicable for the arguments (Predicate<FluentIterableTest.X>)
   */
  // FluentIterable.of().append(aIterable).append(bIterable).filter(xPredicate);
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:33,代碼來源:FluentIterableTest.java

示例4: findResourceFile

import com.google.common.base.Predicates; //導入依賴的package包/類
private ResourceLocation findResourceFile(SourceGroup[] resSG, final String value, final String folderName) {
    FileObject resFile = Iterables.find(
            Iterables.transform(
                    Arrays.asList(resSG),
                    new Function<SourceGroup, FileObject>() {
                @Override
                public FileObject apply(SourceGroup sg) {
                    return sg.getRootFolder().getFileObject(folderName + "/" + value + ".xml");
                }
            }),
            Predicates.notNull(),
            null);
    if (resFile == null) {
        LOG.log(Level.FINE, "Resource file {0} not found for {0}.", value);
        return null;
    }
    return new ResourceLocation(resFile, -1);
}
 
開發者ID:NBANDROIDTEAM,項目名稱:NBANDROID-V2,代碼行數:19,代碼來源:ProjectResourceLocator.java

示例5: shouldExecute

import com.google.common.base.Predicates; //導入依賴的package包/類
/**
 * Returns whether the EntityAIBase should begin execution.
 */
public boolean shouldExecute()
{
    if (this.targetChance > 0 && this.taskOwner.getRNG().nextInt(this.targetChance) != 0)
    {
        return false;
    }
    else
    {
        double d0 = this.getTargetDistance();
        List<T> list = this.taskOwner.worldObj.<T>getEntitiesWithinAABB(this.targetClass, this.taskOwner.getEntityBoundingBox().expand(d0, 4.0D, d0), Predicates.<T> and (this.targetEntitySelector, EntitySelectors.NOT_SPECTATING));
        Collections.sort(list, this.theNearestAttackableTargetSorter);

        if (list.isEmpty())
        {
            return false;
        }
        else
        {
            this.targetEntity = (EntityLivingBase)list.get(0);
            return true;
        }
    }
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:27,代碼來源:EntityAINearestAttackableTarget.java

示例6: iterator

import com.google.common.base.Predicates; //導入依賴的package包/類
@Override
public Iterator<FragmentExecutor> iterator() {
  return Iterators.unmodifiableIterator(
    FluentIterable
      .from(handlers.asMap().values())
      .transform(new Function<FragmentHandler, FragmentExecutor>() {
        @Nullable
        @Override
        public FragmentExecutor apply(FragmentHandler input) {
          return input.getExecutor();
        }
      })
      .filter(Predicates.<FragmentExecutor>notNull())
      .iterator()
  );
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:17,代碼來源:FragmentExecutors.java

示例7: scan

import com.google.common.base.Predicates; //導入依賴的package包/類
public PostProcessor[] scan(final Object instance) {
    return FluentIterable
            .from(ReflectionUtils.getDeclaredFields(instance.getClass(), true))
            .filter(new Predicate<Field>() {
                @Override
                public boolean apply(Field input) {
                    return input.isAnnotationPresent(Random.PostProcessor.class)
                            && PostProcessor.class.isAssignableFrom(input.getType());
                }
            })
            .transform(new Function<Field, PostProcessor>() {
                @Override
                public PostProcessor apply(Field field) {
                    try {
                        if (!ReflectionUtils.makeFieldAccessible(field)) {
                            return null;
                        }
                        return (PostProcessor) field.get(instance);
                    } catch (IllegalAccessException e) {
                        throw new RandomitoException(e);
                    }
                }
            })
            .filter(Predicates.<PostProcessor>notNull())
            .toArray(PostProcessor.class);
}
 
開發者ID:randomito,項目名稱:randomito-all,代碼行數:27,代碼來源:AnnotationPostProcessorScanner.java

示例8: SimpleHelpMap

import com.google.common.base.Predicates; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public SimpleHelpMap(CraftServer server) {
    this.helpTopics = new TreeMap<String, HelpTopic>(HelpTopicComparator.topicNameComparatorInstance()); // Using a TreeMap for its explicit sorting on key
    this.topicFactoryMap = new HashMap<Class, HelpTopicFactory<Command>>();
    this.server = server;
    this.yaml = new HelpYamlReader(server);

    Predicate indexFilter = Predicates.not(Predicates.instanceOf(CommandAliasHelpTopic.class));
    if (!yaml.commandTopicsInMasterIndex()) {
        indexFilter = Predicates.and(indexFilter, Predicates.not(new IsCommandTopicPredicate()));
    }

    this.defaultTopic = new IndexHelpTopic("Index", null, null, Collections2.filter(helpTopics.values(), indexFilter), "Use /help [n] to get page n of help.");

    registerHelpTopicFactory(MultipleCommandAlias.class, new MultipleCommandAliasHelpTopicFactory());
}
 
開發者ID:UraniumMC,項目名稱:Uranium,代碼行數:17,代碼來源:SimpleHelpMap.java

示例9: warnOnMissingOffsets

import com.google.common.base.Predicates; //導入依賴的package包/類
/**
 * Warns about CAS offsets for Responses being inconsistent with actual document text for non-TIME
 * roles
 */
private void warnOnMissingOffsets(final File systemOutputStoreFile, final Symbol docID,
    final ImmutableSet<Response> responses,
    final Map<Symbol, File> docIDMap) throws IOException {
  final String text = Files.asCharSource(docIDMap.get(docID), Charsets.UTF_8).read();
  for (final Response r : FluentIterable.from(responses)
      .filter(Predicates.compose(not(equalTo(TIME)), ResponseFunctions.role()))) {
    final KBPString cas = r.canonicalArgument();
    final String casTextInRaw =
        resolveCharOffsets(cas.charOffsetSpan(), docID, text).replaceAll("\\s+", " ");
    // allow whitespace
    if (!casTextInRaw.contains(cas.string())) {
      log.warn("Warning for {} - response {} CAS does not match text span of {} ",
          systemOutputStoreFile.getAbsolutePath(), renderResponse(r, text), casTextInRaw);
    }
  }
}
 
開發者ID:isi-nlp,項目名稱:tac-kbp-eal,代碼行數:21,代碼來源:ValidateSystemOutput.java

示例10: getDeclaredSources

import com.google.common.base.Predicates; //導入依賴的package包/類
public Iterable<Class<? extends RuleSource>> getDeclaredSources(Class<?> container) {
    try {
        return FluentIterable.from(cache.get(container))
                .transform(new Function<Reference<Class<? extends RuleSource>>, Class<? extends RuleSource>>() {
                    @Override
                    public Class<? extends RuleSource> apply(Reference<Class<? extends RuleSource>> input) {
                        return input.get();
                    }
                })
                .filter(Predicates.notNull());
    } catch (ExecutionException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:15,代碼來源:ModelRuleSourceDetector.java

示例11: getManifestThemeNames

import com.google.common.base.Predicates; //導入依賴的package包/類
public Iterable<String> getManifestThemeNames(InputStream is) {
    return Iterables.filter(
            Iterables.transform(
                    getAttrNames(is, manifestXpathExp),
                    new Function<String, String>() {
                @Override
                public String apply(String name) {
                    return name.startsWith("@style/") ? name.substring("@style/".length()) : null;
                }
            }),
            Predicates.notNull());
}
 
開發者ID:NBANDROIDTEAM,項目名稱:NBANDROID-V2,代碼行數:13,代碼來源:ManifestParser.java

示例12: filterFiltered

import com.google.common.base.Predicates; //導入依賴的package包/類
/**
 * Support {@code clear()}, {@code removeAll()}, and {@code retainAll()} when
 * filtering a filtered navigable map.
 */
@GwtIncompatible // NavigableMap
private static <K, V> NavigableMap<K, V> filterFiltered(
    FilteredEntryNavigableMap<K, V> map, Predicate<? super Entry<K, V>> entryPredicate) {
  Predicate<Entry<K, V>> predicate =
      Predicates.<Entry<K, V>>and(map.entryPredicate, entryPredicate);
  return new FilteredEntryNavigableMap<K, V>(map.unfiltered, predicate);
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:12,代碼來源:Maps.java

示例13: resolveFileResourceNames

import com.google.common.base.Predicates; //導入依賴的package包/類
private List<String> resolveFileResourceNames(ObjectListing objectListing) {
    List<S3ObjectSummary> objectSummaries = objectListing.getObjectSummaries();
    if (null != objectSummaries) {
        return ImmutableList.copyOf(Iterables.filter(
            Iterables.transform(objectSummaries, EXTRACT_FILE_NAME),
            Predicates.notNull()
        ));
    }
    return Collections.emptyList();

}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:12,代碼來源:S3ResourceResolver.java

示例14: testFirstMatch

import com.google.common.base.Predicates; //導入依賴的package包/類
public void testFirstMatch() {
  FluentIterable<String> iterable = FluentIterable.from(Lists.newArrayList("cool", "pants"));
  assertThat(iterable.firstMatch(Predicates.equalTo("cool"))).hasValue("cool");
  assertThat(iterable.firstMatch(Predicates.equalTo("pants"))).hasValue("pants");
  assertThat(iterable.firstMatch(Predicates.alwaysFalse())).isAbsent();
  assertThat(iterable.firstMatch(Predicates.alwaysTrue())).hasValue("cool");
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:8,代碼來源:FluentIterableTest.java

示例15: testSimpleFragment

import com.google.common.base.Predicates; //導入依賴的package包/類
@Test
public void testSimpleFragment() {
  for (String inputUrl
       : new String[] { "#foo", "/bar#foo", "mailto:[email protected]#foo" }) {
    assertFragmentClassification(
        Classification.NOT_A_MATCH,
        inputUrl,
        FragmentClassifiers.builder().build());
    assertFragmentClassification(
        Classification.NOT_A_MATCH,
        inputUrl,
        FragmentClassifiers.builder()
            .match(Predicates.equalTo(Optional.<String>absent()))
            .build());
    assertFragmentClassification(
        Classification.MATCH,
        inputUrl,
        FragmentClassifiers.builder()
            .match(Predicates.equalTo(Optional.of("#foo")))
            .build());
    assertFragmentClassification(
        Classification.MATCH,
        inputUrl,
        FragmentClassifiers.builder()
            .matchAsUrl(
                new UrlClassifier() {

                  @Override
                  public Classification apply(
                      UrlValue x, Diagnostic.Receiver<? super UrlValue> r) {
                    assertEquals(
                        "http://example.org./foo", x.urlText);
                    assertTrue(x.inheritsPlaceholderAuthority);
                    return Classification.MATCH;
                  }

                })
            .build());
  }
}
 
開發者ID:OWASP,項目名稱:url-classifier,代碼行數:41,代碼來源:FragmentClassifierBuilderTest.java


注:本文中的com.google.common.base.Predicates類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。