-3

I want to implement a linkedList with Grails domain classes. The base class is the following:

class Node {

    String text

    Node predecessor
    Node successor



public static remove(Node n) {

   def node = Node.get(n)
   node.delete()

}





}

A node can have 0 or 1 predecessor Node and 0 or 1 successor Nodes.

How do I implement the following operations such that they work with GORM?

  • Node get(int index)
  • void add(Node n)
  • void add(Node n, int index)
  • remove(int index)
  • remove Node n)
Michael
  • 32,527
  • 49
  • 210
  • 370
  • 2
    Have you tried implementing anything in the relevant methods? Meaning have you tried actually writing the code that is going to be needed to manage the relationships via GORM? Without seeing what you have tried it's hard to make suggestions other than to write the implementation for you. – Joshua Moore Jun 26 '14 at 16:20
  • @JoshuaMoore I added the code I have. – Michael Jun 26 '14 at 16:56

1 Answers1

2

I'm not sure this answer can fit your problem, but do you think you can use two domains instead of one ?

For example:

class Node {
    String text
}

and (for example):

class NodesLst {
    List nodes
    static hasMany = [nodes:Nodes]
}

If you know List in Java / Groovy, all your functions will be easy to write.

Hope this helps

Abincepto
  • 1,016
  • 8
  • 13
  • Yes this would be an option. How do I have to write the required functions? – Michael Jun 26 '14 at 16:49
  • I agree with the first comment of JoshuaMoore. You should try to write the functions, and if needed, you will find assistance here to correct errors. – Abincepto Jun 27 '14 at 08:37