public override IEnumerator <RECORD> Iterator() { CloseIterator(); ResourceIterable <RECORD> iterable = scan(_store, _forward); return(cloned(_iterator = iterable.GetEnumerator())); }
public virtual Path PathToReference(Node me) { PathFinder <Path> finder = GraphAlgoFactory.shortestPath(PathExpanders.allTypesAndDirections(), 6); using (Transaction tx = me.GraphDatabase.beginTx()) { Node other; if (me.hasRelationship(RelationshipType.withName("friend"))) { ResourceIterable <Relationship> relationships = (ResourceIterable <Relationship>)me.getRelationships(RelationshipType.withName("friend")); using (ResourceIterator <Relationship> resourceIterator = relationships.GetEnumerator()) { //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: other = resourceIterator.next().getOtherNode(me); } } else { other = me.GraphDatabase.createNode(); } Path path = finder.FindSinglePath(other, me); tx.Success(); return(path); } }
private void DeleteFirst(ResourceIterable <Relationship> iterable) { using (ResourceIterator <Relationship> iterator = iterable.GetEnumerator()) { //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: iterator.next().delete(); } }
private void AssertHasNext(ResourceIterable <Relationship> relationships) { using (ResourceIterator <Relationship> iterator = relationships.GetEnumerator()) { //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertTrue(iterator.hasNext()); } }
private Relationship GetFistRelationship(Node node) { ResourceIterable <Relationship> relationships = (ResourceIterable <Relationship>)node.GetRelationships(Direction.OUTGOING); using (ResourceIterator <Relationship> iterator = relationships.GetEnumerator()) { //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: return(iterator.next()); } }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected: //ORIGINAL LINE: public <R extends org.neo4j.kernel.impl.store.record.AbstractBaseRecord> void applyFilteredParallel(final org.neo4j.kernel.impl.store.RecordStore<R> store, final org.neo4j.helpers.progress.ProgressListener progressListener, int numberOfThreads, long recordsPerCpu, final org.neo4j.consistency.checking.full.QueueDistribution_QueueDistributor<R> distributor) public virtual void ApplyFilteredParallel <R>(RecordStore <R> store, ProgressListener progressListener, int numberOfThreads, long recordsPerCpu, QueueDistribution_QueueDistributor <R> distributor) where R : Org.Neo4j.Kernel.impl.store.record.AbstractBaseRecord { CacheAccess.prepareForProcessingOfSingleStore(recordsPerCpu); RecordProcessor <R> processor = new RecordProcessor_AdapterAnonymousInnerClass(this, store); ResourceIterable <R> scan = scan(store, _stage.Forward); using (ResourceIterator <R> records = scan.GetEnumerator()) { distributeRecords(numberOfThreads, this.GetType().Name, _qSize, cloned(records), progressListener, processor, distributor); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void iterablesStreamClosesResourceIterator() internal virtual void IterablesStreamClosesResourceIterator() { IList <object> list = new IList <object> { "a", "b", "c", "def" }; Resource resource = mock(typeof(Resource)); ResourceIterable <object> iterable = () => Iterators.ResourceIterator(list.GetEnumerator(), resource); using (Stream <object> stream = Iterables.Stream(iterable)) { assertEquals(list, stream.collect(toList())); } verify(resource).close(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void streamShouldCloseSingleOnCompleted() internal virtual void StreamShouldCloseSingleOnCompleted() { // Given AtomicBoolean closed = new AtomicBoolean(false); ResourceIterator <int> resourceIterator = newResourceIterator(iterator(new int?[] { 1, 2, 3 }), () => closed.set(true)); ResourceIterable <int> iterable = () => resourceIterator; // When IList <int> result = iterable.ToList(); // Then assertEquals(asList(1, 2, 3), result); assertTrue(closed.get()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void streamShouldCloseMultipleOnCompleted() internal virtual void StreamShouldCloseMultipleOnCompleted() { // Given AtomicInteger closed = new AtomicInteger(); Resource resource = closed.incrementAndGet; ResourceIterator <int> resourceIterator = newResourceIterator(iterator(new int?[] { 1, 2, 3 }), resource, resource); ResourceIterable <int> iterable = () => resourceIterator; // When IList <int> result = iterable.ToList(); // Then assertEquals(asList(1, 2, 3), result); assertEquals(2, closed.get(), "two calls to close"); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldRunBuilderOnExistingStoreDir() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldRunBuilderOnExistingStoreDir() { // When // create graph db with one node upfront File existingStoreDir = TestDir.directory("existingStore"); File storeDir = Config.defaults(GraphDatabaseSettings.data_directory, existingStoreDir.toPath().ToString()).get(GraphDatabaseSettings.database_path); GraphDatabaseService db = (new TestGraphDatabaseFactory()).newEmbeddedDatabase(storeDir); try { Db.execute("create ()"); } finally { Db.shutdown(); } using (ServerControls server = GetTestServerBuilder(TestDir.databaseDir()).copyFrom(existingStoreDir).newServer()) { // Then using (Transaction tx = server.Graph().beginTx()) { ResourceIterable <Node> allNodes = Iterables.asResourceIterable(server.Graph().AllNodes); assertTrue(Iterables.count(allNodes) > 0); // When: create another node server.Graph().createNode(); tx.Success(); } } // Then: we still only have one node since the server is supposed to work on a copy db = (new TestGraphDatabaseFactory()).newEmbeddedDatabase(storeDir); try { using (Transaction tx = Db.beginTx()) { assertEquals(1, Iterables.count(Db.AllNodes)); tx.Success(); } } finally { Db.shutdown(); } }
private bool ObjectExistsInIterable(Relationship rel, ResourceIterable <Relationship> allRels) { using (ResourceIterator <Relationship> resourceIterator = allRels.GetEnumerator()) { while (resourceIterator.MoveNext()) { Relationship iteratedRel = resourceIterator.Current; { if (rel.Equals(iteratedRel)) { return(true); } } } return(false); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void allPathsToSelfReturnsZero() public virtual void AllPathsToSelfReturnsZero() { // GIVEN Node start = Graph.makeNode("start", "x", 0d, "y", 0d); // WHEN ResourceIterable <WeightedPath> paths = Iterables.asResourceIterable(_finder.findAllPaths(start, start)); // THEN foreach (WeightedPath path in paths) { assertNotNull(path); assertEquals(start, path.StartNode()); assertEquals(start, path.EndNode()); assertEquals(0, path.Length()); } }
private void SetWeight(string start, string end, double weight) { Node startNode = Graph.getNode(start); Node endNode = Graph.getNode(end); ResourceIterable <Relationship> relationships = Iterables.asResourceIterable(startNode.Relationships); using (ResourceIterator <Relationship> resourceIterator = relationships.GetEnumerator()) { while (resourceIterator.MoveNext()) { Relationship rel = resourceIterator.Current; if (rel.GetOtherNode(startNode).Equals(endNode)) { rel.SetProperty("weight", weight); return; } } } throw new Exception("No relationship between nodes " + start + " and " + end); }
//JAVA TO C# CONVERTER TODO TASK: There is no .NET equivalent to the Java 'super' constraint: //ORIGINAL LINE: <R extends org.neo4j.kernel.impl.store.record.AbstractBaseRecord> void apply(RecordStore<R> store, org.neo4j.helpers.progress.ProgressListener progressListener, System.Predicate<? super R>... filters) throws FAILURE //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: internal virtual void Apply <R>(RecordStore <R> store, ProgressListener progressListener, params System.Predicate <object>[] filters) where R : Org.Neo4j.Kernel.impl.store.record.AbstractBaseRecord { ResourceIterable <R> iterable = Scanner.Scan(store, true, filters); using (ResourceIterator <R> scan = iterable.GetEnumerator()) { while (scan.MoveNext()) { R record = scan.Current; if (ShouldStop) { break; } store.Accept(this, record); progressListener.Set(record.Id); } progressListener.Done(); } }
protected internal virtual Node GetNodeWithName(string name) { ResourceIterable <Node> allNodes = GraphDb.AllNodes; using (ResourceIterator <Node> nodeIterator = allNodes.GetEnumerator()) { while (nodeIterator.MoveNext()) { Node node = nodeIterator.Current; { string nodeName = ( string )node.GetProperty("name", null); if (!string.ReferenceEquals(nodeName, null) && nodeName.Equals(name)) { return(node); } } } } return(null); }
/// <param name="node1Id"> </param> /// <param name="node2Id"> </param> /// <returns> One relationship between two given nodes, if there exists one, /// otherwise null. </returns> public virtual Relationship GetRelationship(string node1Id, string node2Id) { Node node1 = GetNode(node1Id); Node node2 = GetNode(node2Id); if (node1 == null || node2 == null) { return(null); } ResourceIterable <Relationship> relationships = Iterables.asResourceIterable(node1.Relationships); using (ResourceIterator <Relationship> resourceIterator = relationships.GetEnumerator()) { while (resourceIterator.MoveNext()) { Relationship relationship = resourceIterator.Current; if (relationship.GetOtherNode(node1).Equals(node2)) { return(relationship); } } } return(null); }
public override Node Next() { if (!HasNext()) { throw new NoSuchElementException(); } Node currentNode = Queue.extractMin(); CostType currentCost = MySeen[currentNode]; // Already done with this node? if (MyDistances.ContainsKey(currentNode)) { return(null); } if (outerInstance.LimitReached()) { return(null); } ++outerInstance.NumberOfNodesTraversed; MyDistances[currentNode] = currentCost; // TODO: remove from seen or not? probably not... because of path // detection // Check if we have found a better path CheckForPath(currentNode, currentCost, OtherSeen); // Found a path? (abort traversing from this node) if (OtherDistances.ContainsKey(currentNode)) { OneShortestPathHasBeenFound = true; } else { // Otherwise, follow all edges from this node foreach (RelationshipType costRelationType in outerInstance.CostRelationTypes) { ResourceIterable <Relationship> relationships = Iterables.asResourceIterable(currentNode.GetRelationships(costRelationType, Direction)); using (ResourceIterator <Relationship> iterator = relationships.GetEnumerator()) { while (iterator.MoveNext()) { Relationship relationship = iterator.Current; if (outerInstance.LimitReached()) { break; } ++outerInstance.NumberOfTraversedRelationShips; // Target node Node target = relationship.GetOtherNode(currentNode); if (OtherDistances.ContainsKey(target)) { continue; } // Find out if an eventual path would go in the opposite // direction of the edge bool backwardsEdge = relationship.EndNode.Equals(currentNode) ^ Backwards; CostType newCost = outerInstance.CostAccumulator.addCosts(currentCost, outerInstance.CostEvaluator.getCost(relationship, backwardsEdge ? Direction.INCOMING : Direction.OUTGOING)); // Already done with target node? if (MyDistances.ContainsKey(target)) { // Have we found a better cost for a node which is // already // calculated? if (outerInstance.CostComparator.Compare(MyDistances[target], newCost) > 0) { throw new Exception("Cycle with negative costs found."); } // Equally good path found? else if (outerInstance.CalculateAllShortestPaths && outerInstance.CostComparator.Compare(MyDistances[target], newCost) == 0) { // Put it in predecessors IList <Relationship> myPredecessors = Predecessors[currentNode]; // Dont do it if this relation is already in // predecessors (other direction) if (myPredecessors == null || !myPredecessors.Contains(relationship)) { IList <Relationship> predList = Predecessors[target]; if (predList == null) { // This only happens if we get back to // the // start node, which is just bogus } else { predList.Add(relationship); } } } continue; } // Have we found a better cost for this node? if (!MySeen.ContainsKey(target) || outerInstance.CostComparator.Compare(MySeen[target], newCost) > 0) { // Put it in the queue if (!MySeen.ContainsKey(target)) { Queue.insertValue(target, newCost); } // or update the entry. (It is important to keep // these // cases apart to limit the size of the queue) else { Queue.decreaseValue(target, newCost); } // Update it MySeen[target] = newCost; // Put it in predecessors IList <Relationship> predList = new LinkedList <Relationship>(); predList.Add(relationship); Predecessors[target] = predList; } // Have we found an equal cost for (additional path to) // this // node? else if (outerInstance.CalculateAllShortestPaths && outerInstance.CostComparator.Compare(MySeen[target], newCost) == 0) { // Put it in predecessors IList <Relationship> predList = Predecessors[target]; predList.Add(relationship); } } } } } // Check how far we need to continue when searching for all shortest // paths if (outerInstance.CalculateAllShortestPaths && OneShortestPathHasBeenFound) { // If we cannot continue or continuation would only find more // expensive paths: conclude that all shortest paths have been // found. AllShortestPathsHasBeenFound = Queue.Empty || outerInstance.CostComparator.Compare(MySeen[Queue.peek()], currentCost) > 0; } return(currentNode); }
protected internal ResourcePathIterableWrapper(ResourceIterable <Path> iterableToWrap) { this.IterableToWrap = iterableToWrap; }
public CacheNextRel(Stage stage, CacheAccess cacheAccess, ResourceIterable <NodeRecord> nodes) : base(stage, cacheAccess) { this.Nodes = nodes; }
public ResourceIterableWrapper(ResourceIterable <U> source) { this._source = source; }
/// <summary> /// Instantiates a new limiting <seealso cref="System.Collections.IEnumerable"/> which can limit the number /// of items returned from iterators it spawns. /// </summary> /// <param name="source"> the source of items. </param> /// <param name="limit"> the limit, i.e. the max number of items to return. </param> public LimitingResourceIterable(ResourceIterable <T> source, int limit) { this._source = source; this._limit = limit; }