Sha256: e25d2f67220802aaf3f2453fe3511c7ee53d2f378060ed1f0e365e5382c6b938

Contents?: true

Size: 1.7 KB

Versions: 7

Compression:

Stored size: 1.7 KB

Contents

module Neo4j
  # == Represents a set of relationships.
  # See Neo4j::EventHandler
  class RelationshipSet
    def initialize(size=0)
      @relationship_type_set = java.util.HashSet.new(size)
      @relationship_set = java.util.HashSet.new(size)
      @relationship_map = java.util.HashMap.new(size)
    end

    # Adds a relationship to the set
    def add(rel)
      @relationship_type_set.add(RelationshipSetEntry.new(rel.getEndNode().getId(),rel.rel_type))
      relationships(rel.getEndNode().getId()) << rel
      @relationship_set.add(rel.getId)
    end

    # Returns a collection of relationships where the node with the specified end node id is the end node.
    def relationships(end_node_id)
      @relationship_map.get(end_node_id) || add_list(end_node_id)
    end

    # Returns true if the specified relationship is in the set
    def contains_rel?(rel)
      @relationship_set.contains(rel.getId)
    end

    # Returns true if a relationship with the specified end_node_id and relationship_type is present in the set.
    def contains?(end_node_id,relationship_type)
      @relationship_type_set.contains(RelationshipSetEntry.new(end_node_id,relationship_type))
    end

    protected
    def add_list(node_id)
      @relationship_map.put(node_id,[])
      @relationship_map.get(node_id)
    end
  end

  class RelationshipSetEntry
    attr_accessor :nodeid, :relationship_type
    def initialize(nodeid,relationship_type)
      @nodeid,@relationship_type = nodeid.to_s, relationship_type.to_s
    end

    def ==(o)
      eql?(o)
    end

    def eql?(other)
      @nodeid == other.nodeid && @relationship_type == other.relationship_type
    end

    def hash
      3 * @nodeid.hash + @relationship_type.hash
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
neo4j-2.0.0.alpha.5-java lib/neo4j/relationship_set.rb
neo4j-2.0.0.alpha.4-java lib/neo4j/relationship_set.rb
neo4j-2.0.0.alpha.3-java lib/neo4j/relationship_set.rb
neo4j-1.3.1-java lib/neo4j/relationship_set.rb
neo4j-1.3.0-java lib/neo4j/relationship_set.rb
neo4j-1.2.6-java lib/neo4j/relationship_set.rb
neo4j-1.2.5-java lib/neo4j/relationship_set.rb