Results 1 to 10 of 16

Thread: set contains(obj) returns true but remove(obj) fails.

Threaded View

  1. #1
    Join Date
    Jan 2009
    Location
    Huntington Beach, CA
    Posts
    718

    Default set contains(obj) returns true but remove(obj) fails.

    OK, this is related to my vertex question. But this looks like the brunt of my problem.

    In my User object I have a method to remove the ItemUserSignedUpToBringToEvent from its Set collection. I have implemented ItemUserSignedUpToBringToEvent's equals method to compare nodeIds.

    Code:
    public boolean removeItemSignedUpFor(ItemUserSignedUpToBringToEvent itemSignedUp) {
            return (itemsSignedUpFor.contains(itemSignedUp) &&
                    itemsSignedUpFor.remove(itemSignedUp));
        }
    contains call returns true, but the call to remove fails. Why???

    Here is my equals and hashcode for the ItemUserSignedUpToBringToEvent

    Code:
        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
    
            ItemUserSignedUpToBringToEvent signedUpItem = (ItemUserSignedUpToBringToEvent) o;
            if (nodeId == null) return super.equals(o);
            return nodeId.equals(signedUpItem.nodeId);
    
        }
    
        @Override
        public int hashCode() {
            return nodeId != null ? nodeId.hashCode() : super.hashCode();
        }
    In stepping through code, the Spring Data Neo4J class ManagedFieldAccessorSet remove method is returning false.

    Code:
    @Override
        public boolean remove(Object o) {
            if (delegate.remove(o)) {
                update();
                return true;
            }
            return false;
        }
    Thanks

    Mark
    Last edited by bytor99999; May 26th, 2012 at 05:40 PM. Reason: added more

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •