本文整理了Java中com.google.common.base.Predicate
类的一些代码示例,展示了Predicate
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Predicate
类的具体详情如下:
包路径:com.google.common.base.Predicate
类名称:Predicate
[英]Legacy version of java.util.function.Predicate. Determines a true or false value for a given input.
As this interface extends java.util.function.Predicate, an instance of this type may be used as a Predicate directly. To use a java.util.function.Predicate where a com.google.common.base.Predicate is expected, use the method reference predicate::test.
This interface is now a legacy type. Use java.util.function.Predicate (or the appropriate primitive specialization such as IntPredicate) instead whenever possible. Otherwise, at least reduce explicit dependencies on this type by using lambda expressions or method references instead of classes, leaving your code easier to migrate in the future.
The Predicates class provides common predicates and related utilities.
See the Guava User Guide article on the use of Predicate.
[中]java的遗留版本。util。作用谓语确定给定输入的真值或假值。
因为这个接口扩展了java。util。作用谓词,这种类型的实例可以直接用作谓词。使用java。util。作用断言com的位置。谷歌。常见的基础如果需要谓词,请使用reference Predicate::test方法。
该接口现在是一种遗留类型。使用java。util。作用尽可能使用谓词(或适当的原语专门化,如IntPredicate)。否则,至少可以通过使用lambda表达式或方法引用而不是类来减少对这种类型的显式依赖,从而使代码在将来更容易迁移。
谓词类提供公共谓词和相关实用程序。
请参阅关于the use of Predicate的Guava用户指南文章。
代码示例来源:origin: thinkaurelius/titan
@Override
public boolean apply(@Nullable InternalRelation internalRelation) {
return !SCHEMA_FILTER.apply(internalRelation);
}
};
代码示例来源:origin: google/guava
@Override
public boolean equals(@Nullable Object obj) {
if (obj instanceof NotPredicate) {
NotPredicate<?> that = (NotPredicate<?>) obj;
return predicate.equals(that.predicate);
}
return false;
}
代码示例来源:origin: google/guava
@Override
public void forEach(Consumer<? super E> action) {
checkNotNull(action);
unfiltered.forEach(
(E e) -> {
if (predicate.test(e)) {
action.accept(e);
}
});
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test(dependsOnMethods = { "testApplyTag", "testApplyTagWithValue" })
protected void testList() {
assertTrue(retry(new Predicate<Iterable<Tag>>() {
public boolean apply(Iterable<Tag> input) {
return api().list().filter(new Predicate<Tag>() {
@Override
public boolean apply(Tag in) {
return in.getResourceId().equals(resource.id);
}
}).toSet().equals(input);
}
}, 600, 200, 200, MILLISECONDS).apply(ImmutableSet.of(tag, tag2)));
}
代码示例来源:origin: com.diffplug.guava/guava-core
@Override
public boolean equals(@Nullable Object obj) {
if (obj instanceof PredicateFunction) {
PredicateFunction<?> that = (PredicateFunction<?>) obj;
return predicate.equals(that.predicate);
}
return false;
}
代码示例来源:origin: apache/jclouds
@Test(dependsOnMethods = "testCreateVolumeInAvailabilityZone")
void testCreateSnapshotInRegion() {
Snapshot snapshot = client.createSnapshotInRegion(defaultRegion, volumeId);
Predicate<Snapshot> snapshotted = retry(new SnapshotCompleted(client), 600, 10, SECONDS);
assert snapshotted.apply(snapshot);
Snapshot result = Iterables.getOnlyElement(client.describeSnapshotsInRegion(defaultRegion,
snapshotIds(snapshot.getId())));
assertEquals(result.getProgress(), 100);
this.snapshot = result;
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test
public void testStopAndStartServer() throws Exception {
assertTrue(serverStatusChecker.apply(Server.State.RUNNING));
serverApi.stop(serverId);
assertTrue(serverStatusChecker.apply(Server.State.STOPPED));
serverApi.start(serverId);
assertTrue(serverStatusChecker.apply(Server.State.RUNNING));
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test
public void testTemplateIsReady() {
assertTrue(isReady().apply(
Template.builder().id("a").ready(true).build()
));
assertFalse(isReady().apply(
Template.builder().id("b").ready(false).build()
));
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test
public void testListImages() {
Iterable<org.jclouds.cloudstack.domain.Template> templates = adapter.listImages();
assertFalse(Iterables.isEmpty(templates));
for (org.jclouds.cloudstack.domain.Template template : templates) {
assert TemplatePredicates.isReady().apply(template) : template;
}
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test
void testAlwaysTrue() {
// will call once immediately
Predicate<String> predicate = retry(Predicates.<String> alwaysTrue(), 3, 1, SECONDS);
stopwatch.start();
predicate.apply("");
long duration = stopwatch.elapsed(MILLISECONDS);
assertOrdered(duration, SLOW_BUILD_SERVER_GRACE);
}
代码示例来源:origin: apache/jclouds
@Test
void testRetryAlwaysFalseMillis() {
// maxWait=3; period=1; maxPeriod defaults to 1*10
// will call at 0, 1, 1+(1*1.5), 3
RepeatedAttemptsPredicate rawPredicate = new RepeatedAttemptsPredicate(Integer.MAX_VALUE);
Predicate<String> predicate = retry(rawPredicate, 3, 1, SECONDS);
stopwatch.start();
assertFalse(predicate.apply(""));
long duration = stopwatch.elapsed(MILLISECONDS);
assertOrdered(3000 - EARLY_RETURN_GRACE, duration, 3000 + SLOW_BUILD_SERVER_GRACE);
assertCallTimes(rawPredicate.callTimes, 0, 1000, 1000 + 1500, 3000);
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test
public void testTypeEqualsWhenNotEqual() {
assertFalse(typeEqualTo(Type.SECONDARY).apply(zone));
}
}
代码示例来源:origin: google/guava
@Override
public E last() {
SortedSet<E> sortedUnfiltered = (SortedSet<E>) unfiltered;
while (true) {
E element = sortedUnfiltered.last();
if (predicate.apply(element)) {
return element;
}
sortedUnfiltered = sortedUnfiltered.headSet(element);
}
}
}
代码示例来源:origin: jclouds/legacy-jclouds
protected void assertEventuallyImageStateEquals(ServerImage image, final ServerImageState state) {
assertTrue(retry(new Predicate<ServerImage>() {
public boolean apply(ServerImage input) {
return Iterables.getOnlyElement(api.getImageServices().getImagesById(input.getId()))
.getState() == state;
}
}, 600, 1, SECONDS).apply(image));
}
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test
public void testFilterWhenNotFound() {
assertTrue(retry(new Predicate<Iterable<Subnet>>() {
public boolean apply(Iterable<Subnet> input) {
return api().filter(new SubnetFilterBuilder().subnetId("subnet-pants").build())
.toSet().equals(input);
}
}, 600, 200, 200, MILLISECONDS).apply(ImmutableSet.<Subnet> of()));
}
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby
@Override public boolean equals(@Nullable Object obj) {
if (obj instanceof PredicateFunction) {
PredicateFunction<?> that = (PredicateFunction<?>) obj;
return predicate.equals(that.predicate);
}
return false;
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test(dependsOnMethods = "testCreateVolumeInAvailabilityZone")
void testCreateSnapshotInRegion() {
Snapshot snapshot = client.createSnapshotInRegion(defaultRegion, volumeId);
Predicate<Snapshot> snapshotted = retry(new SnapshotCompleted(client), 600, 10, SECONDS);
assert snapshotted.apply(snapshot);
Snapshot result = Iterables.getOnlyElement(client.describeSnapshotsInRegion(snapshot.getRegion(),
snapshotIds(snapshot.getId())));
assertEquals(result.getProgress(), 100);
this.snapshot = result;
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test
public void testCreateArchive() throws Exception {
try {
archiveApi.delete(archiveUser);
} catch(Exception ex) {
}
int before = archiveApi.list().size();
archiveApi.createWithCredentialsAndSize(archiveUser, "password", 10);
assertTrue(archiveCounter.apply(before + 1));
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test
public void testMatchApiKey() {
assertTrue(apiKeyEquals("random-text").apply(
User.builder().id("random-id").apiKey("random-text").build()
));
assertFalse(apiKeyEquals("something-different").apply(
User.builder().id("random-id").apiKey("random-text").build()
));
}
代码示例来源:origin: apache/jclouds
@Test
public void testListImages() {
Iterable<org.jclouds.cloudstack.domain.Template> templates = adapter.listImages();
assertFalse(Iterables.isEmpty(templates));
for (org.jclouds.cloudstack.domain.Template template : templates) {
assert TemplatePredicates.isReady().apply(template) : template;
}
}
内容来源于网络,如有侵权,请联系作者删除!