use of java.util.function.Predicate in project neo4j by neo4j.
the class TestBidirectionalTraversal method mirroredTraversalReversesInitialState.
@Test
public void mirroredTraversalReversesInitialState() throws Exception {
/*
* (a)-->(b)-->(c)-->(d)
*/
createGraph("a TO b", "b TO c", "c TO d");
BranchCollisionPolicy collisionPolicy = new BranchCollisionPolicy() {
@Override
public BranchCollisionDetector create(Evaluator evaluator, Predicate<Path> pathPredicate) {
return new StandardBranchCollisionDetector(null, null) {
@Override
protected boolean includePath(Path path, TraversalBranch startPath, TraversalBranch endPath) {
assertEquals(0, startPath.state());
assertEquals(10, endPath.state());
return true;
}
};
}
};
Iterables.count(getGraphDb().bidirectionalTraversalDescription().mirroredSides(getGraphDb().traversalDescription().uniqueness(NODE_PATH).expand(PathExpanders.<Integer>forType(to), new InitialBranchState.State<>(0, 10))).collisionPolicy(collisionPolicy).traverse(getNodeWithName("a"), getNodeWithName("d")));
}
use of java.util.function.Predicate in project neo4j by neo4j.
the class ClusterManager method allSeesAllAsJoined.
public static Predicate<ManagedCluster> allSeesAllAsJoined() {
return new Predicate<ManagedCluster>() {
@Override
public boolean test(ManagedCluster cluster) {
int clusterSize = cluster.size();
int clusterMembersChecked = 0;
for (HighlyAvailableGraphDatabase database : cluster.getAllMembers()) {
clusterMembersChecked++;
ClusterMembers members = database.getDependencyResolver().resolveDependency(ClusterMembers.class);
if (count(members.getMembers()) < clusterSize) {
return false;
}
}
for (ObservedClusterMembers arbiter : cluster.getArbiters()) {
clusterMembersChecked++;
if (count(arbiter.getMembers()) < clusterSize) {
return false;
}
}
// Everyone sees everyone else as joined!
return clusterMembersChecked > 0;
}
@Override
public String toString() {
return "All instances should see all others as joined";
}
};
}
use of java.util.function.Predicate in project helios by spotify.
the class HostsResource method list.
/**
* Returns the list of hostnames of known hosts/agents.
* @return The list of hostnames.
*/
@GET
@Produces(APPLICATION_JSON)
@Timed
@ExceptionMetered
public List<String> list(@QueryParam("namePattern") final String namePattern, @QueryParam("selector") final List<String> hostSelectors) {
List<String> hosts = model.listHosts();
if (namePattern != null) {
final Predicate<String> matchesPattern = Pattern.compile(namePattern).asPredicate();
hosts = hosts.stream().filter(matchesPattern).collect(Collectors.toList());
}
if (!hostSelectors.isEmpty()) {
// check that all supplied selectors are parseable/valid
final List<HostSelector> selectors = hostSelectors.stream().map(selectorStr -> {
final HostSelector parsed = HostSelector.parse(selectorStr);
if (parsed == null) {
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity("Invalid host selector: " + selectorStr).build());
}
return parsed;
}).collect(Collectors.toList());
final Map<String, Map<String, String>> hostsAndLabels = getLabels(hosts);
final HostMatcher matcher = new HostMatcher(hostsAndLabels);
hosts = matcher.getMatchingHosts(selectors);
}
return hosts;
}
use of java.util.function.Predicate in project platform_frameworks_base by android.
the class RecentsProvider method call.
@Override
public Bundle call(String method, String arg, Bundle extras) {
if (METHOD_PURGE.equals(method)) {
// Purge references to unknown authorities
final Intent intent = new Intent(DocumentsContract.PROVIDER_INTERFACE);
final Set<String> knownAuth = Sets.newHashSet();
for (ResolveInfo info : getContext().getPackageManager().queryIntentContentProviders(intent, 0)) {
knownAuth.add(info.providerInfo.authority);
}
purgeByAuthority(new Predicate<String>() {
@Override
public boolean test(String authority) {
// Purge unknown authorities
return !knownAuth.contains(authority);
}
});
return null;
} else if (METHOD_PURGE_PACKAGE.equals(method)) {
// Purge references to authorities in given package
final Intent intent = new Intent(DocumentsContract.PROVIDER_INTERFACE);
intent.setPackage(arg);
final Set<String> packageAuth = Sets.newHashSet();
for (ResolveInfo info : getContext().getPackageManager().queryIntentContentProviders(intent, 0)) {
packageAuth.add(info.providerInfo.authority);
}
if (!packageAuth.isEmpty()) {
purgeByAuthority(new Predicate<String>() {
@Override
public boolean test(String authority) {
// Purge authority matches
return packageAuth.contains(authority);
}
});
}
return null;
} else {
return super.call(method, arg, extras);
}
}
use of java.util.function.Predicate in project cassandra by apache.
the class CompactionController method getPurgeEvaluator.
/**
* @param key
* @return a predicate for whether tombstones marked for deletion at the given time for the given partition are
* purgeable; we calculate this by checking whether the deletion time is less than the min timestamp of all SSTables
* containing his partition and not participating in the compaction. This means there isn't any data in those
* sstables that might still need to be suppressed by a tombstone at this timestamp.
*/
public Predicate<Long> getPurgeEvaluator(DecoratedKey key) {
if (NEVER_PURGE_TOMBSTONES || !compactingRepaired())
return time -> false;
overlapIterator.update(key);
Set<SSTableReader> filteredSSTables = overlapIterator.overlaps();
Iterable<Memtable> memtables = cfs.getTracker().getView().getAllMemtables();
long minTimestampSeen = Long.MAX_VALUE;
boolean hasTimestamp = false;
for (SSTableReader sstable : filteredSSTables) {
// we check index file instead.
if (sstable.getBloomFilter() instanceof AlwaysPresentFilter && sstable.getPosition(key, SSTableReader.Operator.EQ, false) != null || sstable.getBloomFilter().isPresent(key)) {
minTimestampSeen = Math.min(minTimestampSeen, sstable.getMinTimestamp());
hasTimestamp = true;
}
}
for (Memtable memtable : memtables) {
Partition partition = memtable.getPartition(key);
if (partition != null) {
minTimestampSeen = Math.min(minTimestampSeen, partition.stats().minTimestamp);
hasTimestamp = true;
}
}
if (!hasTimestamp)
return time -> true;
else {
final long finalTimestamp = minTimestampSeen;
return time -> time < finalTimestamp;
}
}
Aggregations