2 * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.data.spi.node.impl;
10 import static java.util.Objects.requireNonNull;
12 import java.util.Collection;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.opendaylight.yangtools.util.ImmutableOffsetMap;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.schema.AbstractChoiceNode;
18 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
19 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
20 import org.opendaylight.yangtools.yang.data.spi.node.LazyLeafOperations;
21 import org.opendaylight.yangtools.yang.data.spi.node.LazyValues;
23 final class ImmutableChoiceNode extends AbstractChoiceNode {
24 private final @NonNull NodeIdentifier name;
25 final @NonNull Map<NodeIdentifier, Object> children;
27 ImmutableChoiceNode(final NodeIdentifier name, final Map<NodeIdentifier, Object> children) {
28 this.name = requireNonNull(name);
29 // FIXME: move this to caller
30 this.children = ImmutableOffsetMap.unorderedCopyOf(children);
34 public NodeIdentifier name() {
39 public DataContainerChild childByArg(final NodeIdentifier child) {
40 return LazyLeafOperations.getChild(children, child);
44 public Collection<DataContainerChild> body() {
45 return new LazyValues(children);
50 return children.size();
54 protected int valueHashCode() {
55 return children.hashCode();
59 protected boolean valueEquals(final ChoiceNode other) {
60 return other instanceof ImmutableChoiceNode immutable ? children.equals(immutable.children)
61 : ImmutableNormalizedNodeMethods.bodyEquals(this, other);