For neo4j.graph-collections.list.List I suggest the following.
The graph collections List class is an implementation of the java.util.List 
class, parameterized with Node, supporting all methods, except subList(int 
start, int end). 
Whenever nodes need to be stored as a list, the List class can be used, 
guaranteeing the List contract is maintained.
package org.neo4j.collections.list;

import org.neo4j.collections.list.List;
import org.neo4j.graphdb.Node;
import org.neo4j.kernel.EmbeddedGraphDatabase;
import java.util.ArrayList;
import org.neo4j.graphdb.Transaction;

public class Demo {

        public static void main(String[] args){

                
                
                //create/load database
                EmbeddedGraphDatabase graphDb = new EmbeddedGraphDatabase( 
"var/db" );
                
                Transaction tx = graphDb.beginTx();

                //create node representing the list
                Node indexNode = graphDb.createNode();

                //create list
                List list = new List( indexNode, graphDb );

                //create nodes to be added to the list
                Node node1 = graphDb.createNode();
                Node node2 = graphDb.createNode();
                Node node3 = graphDb.createNode();
                Node node4 = graphDb.createNode();

                //add nodes to the list one by one
                list.add(node1);
                list.add(node2);
                list.add(node3);
                list.add(node4);

                //remove entries by index
                list.remove(3);
                list.remove(2);

                //remove entries by node
                list.remove(node2);
                list.remove(node1);

                //add a collection of nodes to the list
                ArrayList<Node> al1 = new ArrayList<Node>();
                al1.add(node1);
                al1.add(node2);
                al1.add(node3);
                al1.add(node4);

                list.addAll(al1);

                //use the list in a for loop
                for(Node n: list){
                  System.out.println(n);
                }

                //find first entry in the list containing a specific node
                list.indexOf(node2);

                //find last entry in the list containing a specific node
                list.lastIndexOf(node2);

                //retain a collection of nodes from the list
                ArrayList<Node> al2 = new ArrayList<Node>();
                al2.add(node1);
                al2.add(node3);
                al2.add(node4);

                list.retainAll(al2);

                //remove a collection of nodes from the list
                ArrayList<Node> al3 = new ArrayList<Node>();
                al2.add(node3);
                al2.add(node4);

                list.removeAll(al3);
                
                //delete the list
                list.delete();

                tx.success();
                tx.finish();
        }
}


> From: peter.neuba...@neotechnology.com
> Date: Thu, 30 Jun 2011 17:49:46 +0200
> To: user@lists.neo4j.org
> Subject: Re: [Neo4j] graph-collections List class
> 
> Guys,
> if you can write some illustrative test code for the different
> collections, I could undertake to put some documentation skeleton into
> place that can be merged into the main manual and look like
> http://docs.neo4j.org/chunked/snapshot/. To start with, we could have
> it separately though.
> 
> WDYT?
> 
> Cheers,
> 
> /peter neubauer
> 
> GTalk:      neubauer.peter
> Skype       peter.neubauer
> Phone       +46 704 106975
> LinkedIn   http://www.linkedin.com/in/neubauer
> Twitter      http://twitter.com/peterneubauer
> 
> http://www.neo4j.org               - Your high performance graph database.
> http://startupbootcamp.org/    - Ă–resund - Innovation happens HERE.
> http://www.thoughtmade.com - Scandinavia's coolest Bring-a-Thing party.
> 
> 
> 
> On Thu, Jun 30, 2011 at 5:28 PM, Niels Hoogeveen
> <pd_aficion...@hotmail.com> wrote:
> >
> > Today I added a List class to the graph-collections repo:
> > https://github.com/peterneubauer/graph-collections/tree/master/src/main/java/org/neo4j/collections/list
> > The List class implements the java.util.List<Node> interface.
> > Niels
> > _______________________________________________
> > Neo4j mailing list
> > User@lists.neo4j.org
> > https://lists.neo4j.org/mailman/listinfo/user
> >
> _______________________________________________
> Neo4j mailing list
> User@lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user
                                          
_______________________________________________
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to