[YANGTOOLS-222] Builder should not use singleton map Created: 23/Jul/14  Updated: 10/Apr/22  Due: 01/Aug/14  Resolved: 25/Jul/14

Status: Resolved
Project: yangtools
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug
Reporter: Alexander Fan Assignee: Martin Vitez
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating System: Mac OS
Platform: PC


External issue ID: 1407

 Description   

When creating a builder for a given object, i.e. "NodeConnectorBuilder ncBuilder = new NodeConnectorBuilder(nc)"
The ncBuilder will initialize its "augmentation" HashMap variable to be a SingletonMap when nc only has 1 augmentation.
However, I want to add augmentations onto ncBuilder using the "addAugmentation" method. Using the "addAugmentation" method will throw an UnsupportedOperationException because SingletonMap does not override AbstractMap's "put" method.

Here is an example of the NodeConnectorBuilder
if (base instanceof NodeConnectorImpl) {
NodeConnectorImpl _impl = (NodeConnectorImpl) base;
switch (_impl.augmentation.size())

{ case 0: this.augmentation = Collections.emptyMap(); break; case 1: final Map.Entry<java.lang.Class<? extends Augmentation<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector>>, Augmentation<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector>> e = _impl.augmentation.entrySet().iterator().next(); this.augmentation = Collections.<java.lang.Class<? extends Augmentation<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector>>, Augmentation<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector>>singletonMap(e.getKey(), e.getValue()); //this is where the problem lies break; default : this.augmentation = new HashMap<>(_impl.augmentation); }

}

The relevant file is BuilderTemplate.xtend



 Comments   
Comment by Martin Vitez [ 24/Jul/14 ]

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

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