import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Splitter;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSet.Builder;
import java.util.Collection;
-import java.util.LinkedHashSet;
-import java.util.Set;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
final StmtContext<Collection<SchemaNodeIdentifier>, KeyStatement, ?> keyStmtCtx,
final QNameModule newQNameModule) {
- Set<SchemaNodeIdentifier> newKeys = new LinkedHashSet<>();
- for (String keyToken : LIST_KEY_SPLITTER.split(keyStmtCtx.rawStatementArgument())) {
- final QName keyQName = QName.create(newQNameModule, keyToken);
- newKeys.add(SchemaNodeIdentifier.create(false, keyQName));
+ final Builder<SchemaNodeIdentifier> builder = ImmutableSet.builder();
+ boolean replaced = false;
+ for (SchemaNodeIdentifier arg : keyStmtCtx.getStatementArgument()) {
+ final QName qname = arg.getLastComponent();
+ if (!newQNameModule.equals(qname)) {
+ final QName newQname = QName.create(newQNameModule, qname.getLocalName());
+ builder.add(SchemaNodeIdentifier.create(false, newQname));
+ replaced = true;
+ } else {
+ builder.add(arg);
+ }
}
- return newKeys;
+ // This makes sure we reuse the collection when a grouping is instantiated in the same module
+ return replaced ? builder.build() : keyStmtCtx.getStatementArgument();
}
}
@Override
public Collection<SchemaNodeIdentifier> parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
- final Builder<SchemaNodeIdentifier> builder = ImmutableSet.<SchemaNodeIdentifier>builder();
+ final Builder<SchemaNodeIdentifier> builder = ImmutableSet.builder();
int tokens = 0;
for (String keyToken : StmtContextUtils.LIST_KEY_SPLITTER.split(value)) {
builder.add(SchemaNodeIdentifier.create(false, Utils.qNameFromArgument(ctx, keyToken)));