Because mutable objects are evil. It would for example make it impossible to
write classes like this:

class Person {
    private final Expansion<Node> friends;
    Person(Node node) {
        this.friends = node.expand( FRIEND ).nodes();
    }
    Iterable<Person> getFriends() {
        return persons( friends );
    }
    Iterable<Person> getFriends( final int minimumAge ) {
        return persons( friends.filterNodes( new Predicate<Node>() {
            public boolean accept(Node friend) {
                return minimumAge >= (Integer)friend.getProperty("age");
            }
        }) );
    }
    static Iterable<Person> persons( Iterable<Node> persons ) {
        return IterableWrapper<Person, Node>( persons ) {
            protected Person underlyingObjectToObject( Node person ) {
                return new Person( person );
            }
        }
    }
}

This might be an acceptable loss though. This could be a case where it is ok
to reuse the same object and mutate the internal state. It's something to
think about...

-tobias

On Wed, Jun 23, 2010 at 7:10 PM, Craig Taverner <cr...@amanzi.com> wrote:

> Why not have includes() return the same instance with internal state
> changed, then the various call options are equivalent.
>
> On Jun 23, 2010 6:41 PM, "Tobias Ivarsson" <
> tobias.ivars...@neotechnology.com> wrote:
>
> On Wed, Jun 23, 2010 at 6:10 PM, Craig Taverner <cr...@amanzi.com> wrote:
> >
> > (I also noticed that r...
> I get that feeling as well. Another feeling I get with includes() is that
> it
> might be possible to do the following:
>
>
> Expansion<Relationship> expansion = startNode.expand( KNOWS );
> expansion.includes( LIKES );
> expansion.includes( LOVES );
> for (Node node : expansion.nodes()) {
>   ...
> }
>
> With includes() one gets the feeling that the above would expand LOVES,
> LIKES and KNOWS relationships, but it will in fact only expand KNOWS
> relationships. With and() I don't think that mistake would be as common.
>
> Cheers,
> --
>
> Tobias Ivarsson <tobias.ivars...@neotechnology.com>
> Hacker, Neo Technology
> www.neotechnology.com
> Cel...
> _______________________________________________
> Neo4j mailing list
> User@lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user
>



-- 
Tobias Ivarsson <tobias.ivars...@neotechnology.com>
Hacker, Neo Technology
www.neotechnology.com
Cellphone: +46 706 534857
_______________________________________________
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to