public override IEnumerator <PropertyContainer> Iterator()
        {
            // TODO Don't loop through them all up front
            LinkedList <PropertyContainer> entities = new LinkedList <PropertyContainer>();
            TraversalBranch branch = _start;

            while (branch.Length() > 0)
            {
                entities.AddFirst(branch.EndNode());
                entities.AddFirst(branch.LastRelationship());
                branch = branch.Parent();
            }
            entities.AddFirst(branch.EndNode());
            if (_cachedStartNode == null)
            {
                _cachedStartNode = branch.EndNode();
            }
            if (_end.length() > 0)
            {
                entities.AddLast(_end.lastRelationship());
                branch = _end.parent();
                while (branch.Length() > 0)
                {
                    entities.AddLast(branch.EndNode());
                    entities.AddLast(branch.LastRelationship());
                    branch = branch.Parent();
                }
                entities.AddLast(branch.EndNode());
            }
            return(entities.GetEnumerator());
        }
        private LinkedList <Relationship> GatherRelationships(TraversalBranch first, TraversalBranch then)
        {
            // TODO Don't loop through them all up front
            LinkedList <Relationship> relationships = new LinkedList <Relationship>();
            TraversalBranch           branch        = first;

            while (branch.Length() > 0)
            {
                relationships.AddFirst(branch.LastRelationship());
                branch = branch.Parent();
            }
            // We can might as well cache start node since we're right now there anyway
            if (_cachedStartNode == null && first == _start && branch.Length() >= 0)
            {
                _cachedStartNode = branch.EndNode();
            }
            branch = then;
            while (branch.Length() > 0)
            {
                relationships.AddLast(branch.LastRelationship());
                branch = branch.Parent();
            }
            if (_cachedStartNode == null && then == _start && branch.Length() >= 0)
            {
                _cachedStartNode = branch.EndNode();
            }
            return(relationships);
        }
示例#3
0
        public override bool Equals(object obj)
        {
            if (obj == this)
            {
                return(true);
            }
            if (!(obj is TraversalBranch))
            {
                return(false);
            }

            TraversalBranch branch = this;
            TraversalBranch other  = ( TraversalBranch )obj;

            if (branch.Length() != other.Length())
            {
                return(false);
            }

            while (branch.Length() > 0)
            {
                if (!branch.LastRelationship().Equals(other.LastRelationship()))
                {
                    return(false);
                }
                branch = branch.Parent();
                other  = other.Parent();
            }
            return(true);
        }
        private IEnumerable <Node> GatherNodes(TraversalBranch first, TraversalBranch then)
        {
            // TODO Don't loop through them all up front
            LinkedList <Node> nodes  = new LinkedList <Node>();
            TraversalBranch   branch = first;

            while (branch.Length() > 0)
            {
                nodes.AddFirst(branch.EndNode());
                branch = branch.Parent();
            }
            if (_cachedStartNode == null && first == _start && branch.Length() >= 0)
            {
                _cachedStartNode = branch.EndNode();
            }
            nodes.AddFirst(branch.EndNode());
            branch = then.Parent();
            if (branch != null)
            {
                while (branch.Length() > 0)
                {
                    nodes.AddLast(branch.EndNode());
                    branch = branch.Parent();
                }
                if (branch.Length() >= 0)
                {
                    nodes.AddLast(branch.EndNode());
                }
            }
            if (_cachedStartNode == null && then == _start && branch != null && branch.Length() >= 0)
            {
                _cachedStartNode = branch.EndNode();
            }
            return(nodes);
        }
示例#5
0
        public override TraversalBranch Next(TraversalContext metadata)
        {
            TraversalBranch branch        = NextBranchFromCurrentSelector(metadata, false);
            Entry           state         = StateForCurrentSelector;
            AtomicInteger   previousDepth = state.Depth;

            if (branch != null && branch.Length() == previousDepth.get())
            {               // Same depth as previous branch returned from this side.
                return(branch);
            }

            if (branch != null)
            {
                _totalDepth.set(CurrentSide(), branch.Length());
            }
            if ((_stopDescentOnResult && (metadata.NumberOfPathsReturned > 0)) || (_totalDepth.get() > (_maxDepth + 1)))
            {
                NextSelector();
                return(null);
            }

            if (branch != null)
            {
                previousDepth.set(branch.Length());
                state.Branch = branch;
            }
            BranchSelector  otherSelector = NextSelector();
            Entry           otherState    = StateForCurrentSelector;
            TraversalBranch otherBranch   = otherState.Branch;

            if (otherBranch != null)
            {
                otherState.Branch = null;
                return(otherBranch);
            }

            otherBranch = otherSelector.Next(metadata);
            if (otherBranch != null)
            {
                return(otherBranch);
            }
            else
            {
                return(branch);
            }
        }
示例#6
0
        public override TraversalBranch Next(TraversalContext metadata)
        {
            TraversalBranch branch        = NextBranchFromNextSelector(metadata, true);
            int?            previousDepth = StateForCurrentSelector;

            if (branch != null && branch.Length() == previousDepth.Value)
            {
                return(branch);
            }
            else
            {
                if (branch != null)
                {
                    StateForCurrentSelector = branch.Length();
                }
            }
            return(branch);
        }
示例#7
0
        private TraversalBranch FindStartBranch()
        {
            TraversalBranch branch = this;

            while (branch.Length() > 0)
            {
                branch = branch.Parent();
            }
            return(branch);
        }
示例#8
0
        public override bool Check(TraversalBranch branch)
        {
            int            level    = branch.Length();
            MutableLongSet levelIds = _idsPerLevel.get(level);

            if (levelIds == null)
            {
                levelIds = new LongHashSet();
                _idsPerLevel.put(level, levelIds);
            }
            return(levelIds.add(Type.getId(branch)));
        }
示例#9
0
        public override IEnumerable <Relationship> Relationships()
        {
            LinkedList <Relationship> relationships = new LinkedList <Relationship>();
            TraversalBranch           branch        = this;

            while (branch.Length() > 0)
            {
                relationships.AddFirst(branch.LastRelationship());
                branch = branch.Parent();
            }
            return(relationships);
        }
示例#10
0
        public override IEnumerable <Node> Nodes()
        {
            LinkedList <Node> nodes  = new LinkedList <Node>();
            TraversalBranch   branch = this;

            while (branch.Length() > 0)
            {
                nodes.AddFirst(branch.EndNode());
                branch = branch.Parent();
            }
            nodes.AddFirst(branch.EndNode());
            return(nodes);
        }
示例#11
0
        public override bool Check(TraversalBranch source)
        {
            long idToCompare = Type.getId(source);

            while (source.Length() > 0)
            {
                source = source.Parent();
                if (Type.idEquals(source, idToCompare))
                {
                    return(false);
                }
            }
            return(true);
        }
示例#12
0
        public override IEnumerator <PropertyContainer> Iterator()
        {
            LinkedList <PropertyContainer> entities = new LinkedList <PropertyContainer>();
            TraversalBranch branch = this;

            while (branch.Length() > 0)
            {
                entities.AddFirst(branch.EndNode());
                entities.AddFirst(branch.LastRelationship());
                branch = branch.Parent();
            }
            entities.AddFirst(branch.EndNode());
            return(entities.GetEnumerator());
        }
示例#13
0
        public override int GetHashCode()
        {
            TraversalBranch branch   = this;
            int             hashCode = 1;

            while (branch.Length() > 0)
            {
                Relationship relationship = branch.LastRelationship();
                hashCode = 31 * hashCode + relationship.GetHashCode();
                branch   = branch.Parent();
            }
            if (hashCode == 1)
            {
                hashCode = EndNode().GetHashCode();
            }
            return(hashCode);
        }
示例#14
0
 protected internal override double?CalculateValue(TraversalBranch next)
 {
     return(next.Length() == 0 ? 0d : outerInstance.costEvaluator.GetCost(next.LastRelationship(), Direction.OUTGOING));
 }
示例#15
0
 protected internal override int?calculateValue(TraversalBranch next)
 {
     return(next.Length() == 0 ? 0 : evaluator.getCost(next.LastRelationship(), Direction.BOTH));
 }