Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright (c) 2013 GraphAware
  *
  * This file is part of GraphAware.
  *
  * GraphAware is free software: you can redistribute it and/or modify it under the terms of
  * the GNU General Public License as published by the Free Software Foundation, either
  * version 3 of the License, or (at your option) any later version.
  *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 *  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details. You should have received a copy of
 * the GNU General Public License along with this program.  If not, see
 * <http://www.gnu.org/licenses/>.
 */
package com.graphaware.tx.event.batch.propertycontainer.inserter;
org.neo4j.graphdb.Relationship java.util.Iterator for all kinds of relationship filtering by type and direction.
    private final long nodeId;
    private final BatchInserter batchInserter;
    private final Direction direction;
    private final RelationshipType[] relationshipTypes;
    public BatchInserterRelationshipIterator(long nodeIdBatchInserter batchInserterDirection directionRelationshipType... relationshipTypes) {
        this. = nodeId;
        this. = batchInserter;
        this. = batchInserter.getRelationships(nodeId).iterator();
        this. = direction;
        this. = relationshipTypes//empty or null = any
    }
    @Override
    protected Relationship fetchNextOrNull() {
        while (.hasNext()) {
            BatchRelationship next = .next();
            if (!typeMatches(next)) {
                continue;
            }
            if (!directionMatches(next)) {
                continue;
            }
            return new BatchInserterRelationship(next);
        }
        return null;
    }
    private boolean typeMatches(BatchRelationship batchRelationship) {
        if ( == null || . == 0) {
            return true;
        }
        for (RelationshipType relationshipType : ) {
            if (relationshipType.name().equals(batchRelationship.getType().name())) {
                return true;
            }
        }
        return false;
    }
    private boolean directionMatches(BatchRelationship batchRelationship) {
        if (..equals()) {
            return true;
        }
        if (..equals() &&  == batchRelationship.getEndNode()) {
            return true;
        }
        if (..equals() &&  == batchRelationship.getStartNode()) {
            return true;
        }
        return false;
    }
    @Override
    public Iterator<Relationshipiterator() {
        return this;
    }
New to GrepCode? Check out our FAQ X