[MDSAL-151] Add "add"/"del" utility methods to builders. Created: 05/Apr/16  Updated: 13/Sep/18  Resolved: 13/Sep/18

Status: Resolved
Project: mdsal
Component/s: Binding V2 codegen
Affects Version/s: None
Fix Version/s: None

Type: Improvement
Reporter: Sharon Aicler Assignee: Jie Han
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating System: All
Platform: All



 Description   

It will make it much easier to work with List properties if in addition to setter & getter we can add "adder" & "remover" of elements, e.g. if the property type is List<Node> and today we have "void setNode(List<Node> node)" & "List<Node> getNodes()", we should add also "void addNode(Node node)" and "delNode(Node node)" to make it easy to use.



 Comments   
Comment by Dhevendran Kulandaivel [ 17/May/16 ]

(In reply to Sharon Aicler from comment #0)
> It will make it much easier to work with List properties if in addition to
> setter & getter we can add "adder" & "remover" of elements, e.g. if the
> property type is List<Node> and today we have "void setNode(List<Node>
> node)" & "List<Node> getNodes()", we should add also "void addNode(Node
> node)" and "delNode(Node node)" to make it easy to use.

Hi Sharon Aicler

I can take up this . Can you provide us more details on this requirement

Thanks & Regards,
Dhevendran K

Comment by Sharon Aicler [ 18/May/16 ]

Hi Dhevendran,
This is pretty simple.... say today you have a yang def as follows:
container my-container{
list my-list {
}
}

Today the generated method inside MyContainer builder will be:
public void setMyList(List<MyList> lst)

{ impl.myList = lst; }
public List<MyList> getMyKList(){ return impl.myList; }

I am suggesting add helper methods of "add" and "del"
public void setMyList(List<MyList> lst){ impl.myList = lst; }

public List<MyList> getMyKList()

{ return impl.myList; }

public void addMyList(MyList element){
if(this.impl.myList==null)

{ this.impl.myList = new ArrayList(); }

this.impl.myList.add(element);
}
public void delMyList(MyList element)

{ this.impl.myList.remove(element); }

So bottom line a developer should not instantiate a list every time and allow the builder to do it.

Comment by Dhevendran Kulandaivel [ 25/May/16 ]

H Sharon Aicler

Thanks for your input. I will get back to you on this

Thanks & Regards,
Dhevendran K

Comment by Alaykumar B Patel [ 28/Dec/16 ]

Hey Sharon,

I think one can add the method signatures to ChildOf node in listToGenType method, and then in the BaseTemplate.xtend define methods to generate adder and remover methods by getting the method signatures through type.getMethodSignatures() in BaseTemplate.

Is this a natural way of achieving it?

Thank you

Regards,
Alay

Comment by Jie Han [ 07/Feb/18 ]

https://git.opendaylight.org/gerrit/#/c/67999/

Generated at Wed Feb 07 20:08:46 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.