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 TestShortestPath method withFilters.
@Test
public void withFilters() throws Exception {
// Layout:
//
// (a)-->(b)-->(c)-->(d)
// \ ^
// -->(g)-->(h)--/
//
graph.makeEdgeChain("a,b,c,d");
graph.makeEdgeChain("a,g,h,d");
final Node a = graph.getNode("a");
final Node d = graph.getNode("d");
final Node b = graph.getNode("b");
b.setProperty("skip", true);
final Predicate<Node> filter = item -> {
final boolean skip = (Boolean) item.getProperty("skip", false);
return !skip;
};
testShortestPathFinder(finder -> assertPaths(finder.findAllPaths(a, d), "a,g,h,d"), ((StandardExpander) PathExpanders.allTypesAndDirections()).addNodeFilter(filter), 10);
}
use of java.util.function.Predicate in project neo4j by neo4j.
the class StoreMigrator method moveMigratedFiles.
@Override
public void moveMigratedFiles(File migrationDir, File storeDir, String versionToUpgradeFrom, String versionToUpgradeTo) throws IOException {
// Move the migrated ones into the store directory
StoreFile.fileOperation(MOVE, fileSystem, migrationDir, storeDir, StoreFile.currentStoreFiles(), // allow to skip non existent source files
true, // allow to overwrite target files
ExistingTargetStrategy.OVERWRITE, StoreFileType.values());
// move the files with the page cache.
try {
Iterable<FileHandle> fileHandles = pageCache.streamFilesRecursive(migrationDir)::iterator;
for (FileHandle fh : fileHandles) {
Predicate<StoreFile> predicate = storeFile -> storeFile.fileName(StoreFileType.STORE).equals(fh.getFile().getName());
if (StreamSupport.stream(StoreFile.currentStoreFiles().spliterator(), false).anyMatch(predicate)) {
final Optional<PagedFile> optionalPagedFile = pageCache.getExistingMapping(fh.getFile());
if (optionalPagedFile.isPresent()) {
optionalPagedFile.get().close();
}
fh.rename(new File(storeDir, fh.getFile().getName()), StandardCopyOption.REPLACE_EXISTING);
}
}
} catch (NoSuchFileException e) {
//This means that we had no files only present in the page cache, this is fine.
}
RecordFormats oldFormat = selectForVersion(versionToUpgradeFrom);
RecordFormats newFormat = selectForVersion(versionToUpgradeTo);
boolean movingAwayFromVersionTrailers = oldFormat.hasCapability(VERSION_TRAILERS) && !newFormat.hasCapability(VERSION_TRAILERS);
if (movingAwayFromVersionTrailers) {
StoreFile.removeTrailers(versionToUpgradeFrom, fileSystem, storeDir, pageCache.pageSize());
}
File neoStore = new File(storeDir, MetaDataStore.DEFAULT_NAME);
long logVersion = MetaDataStore.getRecord(pageCache, neoStore, Position.LOG_VERSION);
long lastCommittedTx = MetaDataStore.getRecord(pageCache, neoStore, Position.LAST_TRANSACTION_ID);
// update or add upgrade id and time and other necessary neostore records
updateOrAddNeoStoreFieldsAsPartOfMigration(migrationDir, storeDir, versionToUpgradeTo);
// delete old logs
legacyLogs.deleteUnusedLogFiles(storeDir);
if (movingAwayFromVersionTrailers) {
// write a check point in the log in order to make recovery work in the newer version
new StoreMigratorCheckPointer(storeDir, fileSystem).checkPoint(logVersion, lastCommittedTx);
}
}
use of java.util.function.Predicate in project jersey by jersey.
the class ProviderBinder method bindProviders.
/**
* Bind all providers contained in {@code p roviderBag} (classes and instances) using injection manager. Configuration is
* also committed.
*
* @param componentBag bag of provider classes and instances.
* @param constrainedTo current runtime (client or server).
* @param registeredClasses classes which are manually registered by the user (not found by the classpath scanning).
* @param injectionManager injection manager the binder will use to bind the providers into.
*/
public static void bindProviders(ComponentBag componentBag, RuntimeType constrainedTo, Set<Class<?>> registeredClasses, InjectionManager injectionManager) {
Predicate<ContractProvider> filter = ComponentBag.EXCLUDE_EMPTY.and(ComponentBag.excludeMetaProviders(injectionManager));
/*
* Check the {@code component} whether it is correctly configured for client or server {@link RuntimeType runtime}.
*/
Predicate<Class<?>> correctlyConfigured = componentClass -> Providers.checkProviderRuntime(componentClass, componentBag.getModel(componentClass), constrainedTo, registeredClasses == null || !registeredClasses.contains(componentClass), false);
/*
* These binder will be register to Bean Manager at the and of method because of a bulk registration to avoid register
* each binder alone.
*/
Collection<Binder> binderToRegister = new ArrayList<>();
// Bind provider classes except for pure meta-providers and providers with empty contract models (e.g. resources)
Set<Class<?>> classes = new LinkedHashSet<>(componentBag.getClasses(filter));
if (constrainedTo != null) {
classes = classes.stream().filter(correctlyConfigured).collect(Collectors.toSet());
}
for (final Class<?> providerClass : classes) {
final ContractProvider model = componentBag.getModel(providerClass);
binderToRegister.addAll(createProviderBinders(providerClass, model));
}
// Bind pure provider instances except for pure meta-providers and providers with empty contract models (e.g. resources)
Set<Object> instances = componentBag.getInstances(filter);
if (constrainedTo != null) {
instances = instances.stream().filter(component -> correctlyConfigured.test(component.getClass())).collect(Collectors.toSet());
}
for (final Object provider : instances) {
final ContractProvider model = componentBag.getModel(provider.getClass());
binderToRegister.addAll(createProviderBinders(provider, model));
}
injectionManager.register(CompositeBinder.wrap(binderToRegister));
}
use of java.util.function.Predicate in project Railcraft by Railcraft.
the class GeneratorMine method getGen.
@Nullable
private static WorldGenerator getGen(@Nullable IBlockState ore, int density) {
Predicate<IBlockState> genCheck = state -> RailcraftConfig.isWorldGenEnabled("sky") ? GenTools.AIR_STONE.test(state) : GenTools.STONE.test(state);
WorldGenerator gen;
if (ore == null)
gen = null;
else if (density >= 4)
gen = new WorldGenMinable(ore, density, genCheck::test);
else
gen = new WorldGenSmallDeposits(ore, density, genCheck);
return gen;
}
Aggregations