// FIXME: do we want an Optional or a throws instead of @Nullable here?
public static @Nullable TypeDefinitionAwareCodec<?, ?> fromType(final TypeDefinition<?> typeDefinition) {
- if (typeDefinition instanceof BinaryTypeDefinition) {
- return BinaryStringCodec.from((BinaryTypeDefinition)typeDefinition);
- } else if (typeDefinition instanceof BitsTypeDefinition) {
- return BitsStringCodec.from((BitsTypeDefinition)typeDefinition);
- } else if (typeDefinition instanceof BooleanTypeDefinition) {
- return BooleanStringCodec.from((BooleanTypeDefinition)typeDefinition);
- } else if (typeDefinition instanceof DecimalTypeDefinition) {
- return DecimalStringCodec.from((DecimalTypeDefinition)typeDefinition);
+ if (typeDefinition instanceof BinaryTypeDefinition binaryType) {
+ return BinaryStringCodec.from(binaryType);
+ } else if (typeDefinition instanceof BitsTypeDefinition bitsType) {
+ return BitsStringCodec.from(bitsType);
+ } else if (typeDefinition instanceof BooleanTypeDefinition booleanType) {
+ return BooleanStringCodec.from(booleanType);
+ } else if (typeDefinition instanceof DecimalTypeDefinition decimalType) {
+ return DecimalStringCodec.from(decimalType);
} else if (typeDefinition instanceof EmptyTypeDefinition) {
return EmptyStringCodec.INSTANCE;
- } else if (typeDefinition instanceof EnumTypeDefinition) {
- return EnumStringCodec.from((EnumTypeDefinition)typeDefinition);
- } else if (typeDefinition instanceof Int8TypeDefinition) {
- return AbstractIntegerStringCodec.from((Int8TypeDefinition) typeDefinition);
- } else if (typeDefinition instanceof Int16TypeDefinition) {
- return AbstractIntegerStringCodec.from((Int16TypeDefinition) typeDefinition);
- } else if (typeDefinition instanceof Int32TypeDefinition) {
- return AbstractIntegerStringCodec.from((Int32TypeDefinition) typeDefinition);
- } else if (typeDefinition instanceof Int64TypeDefinition) {
- return AbstractIntegerStringCodec.from((Int64TypeDefinition) typeDefinition);
- } else if (typeDefinition instanceof StringTypeDefinition) {
- return StringStringCodec.from((StringTypeDefinition)typeDefinition);
- } else if (typeDefinition instanceof Uint8TypeDefinition) {
- return AbstractIntegerStringCodec.from((Uint8TypeDefinition) typeDefinition);
- } else if (typeDefinition instanceof Uint16TypeDefinition) {
- return AbstractIntegerStringCodec.from((Uint16TypeDefinition) typeDefinition);
- } else if (typeDefinition instanceof Uint32TypeDefinition) {
- return AbstractIntegerStringCodec.from((Uint32TypeDefinition) typeDefinition);
- } else if (typeDefinition instanceof Uint64TypeDefinition) {
- return AbstractIntegerStringCodec.from((Uint64TypeDefinition) typeDefinition);
- } else if (ENABLE_UNION_CODEC && typeDefinition instanceof UnionTypeDefinition) {
- return UnionStringCodec.from((UnionTypeDefinition)typeDefinition);
+ } else if (typeDefinition instanceof EnumTypeDefinition enumType) {
+ return EnumStringCodec.from(enumType);
+ } else if (typeDefinition instanceof Int8TypeDefinition int8Type) {
+ return AbstractIntegerStringCodec.from(int8Type);
+ } else if (typeDefinition instanceof Int16TypeDefinition int16Type) {
+ return AbstractIntegerStringCodec.from(int16Type);
+ } else if (typeDefinition instanceof Int32TypeDefinition int32Type) {
+ return AbstractIntegerStringCodec.from(int32Type);
+ } else if (typeDefinition instanceof Int64TypeDefinition int64Type) {
+ return AbstractIntegerStringCodec.from(int64Type);
+ } else if (typeDefinition instanceof StringTypeDefinition stringType) {
+ return StringStringCodec.from(stringType);
+ } else if (typeDefinition instanceof Uint8TypeDefinition uint8Type) {
+ return AbstractIntegerStringCodec.from(uint8Type);
+ } else if (typeDefinition instanceof Uint16TypeDefinition uint16Type) {
+ return AbstractIntegerStringCodec.from(uint16Type);
+ } else if (typeDefinition instanceof Uint32TypeDefinition uint32Type) {
+ return AbstractIntegerStringCodec.from(uint32Type);
+ } else if (typeDefinition instanceof Uint64TypeDefinition uint64Type) {
+ return AbstractIntegerStringCodec.from(uint64Type);
+ } else if (ENABLE_UNION_CODEC && typeDefinition instanceof UnionTypeDefinition unionType) {
+ return UnionStringCodec.from(unionType);
} else {
return null;
}
@Override
protected String serializeImpl(final Object data) {
- return data instanceof byte[] ? Base64.getEncoder().encodeToString((byte[]) data) : data.toString();
+ return data instanceof byte[] bytes ? Base64.getEncoder().encodeToString(bytes) : data.toString();
}
}
import org.opendaylight.yangtools.rfc8528.data.api.StreamWriterMountPointExtension;
import org.opendaylight.yangtools.rfc8528.data.util.ImmutableMountPointNode;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.stream.ForwardingNormalizedNodeStreamWriter;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriterExtension;
public void close() throws IOException {
super.close();
- final NormalizedNode data = mountResult.getResult();
- if (!(data instanceof ContainerNode)) {
+ final var data = mountResult.getResult();
+ if (!(data instanceof ContainerNode container)) {
throw new IOException("Unhandled mount data " + data);
}
- writeChild(ImmutableMountPointNode.of(mountId, mountCtx, (ContainerNode) data));
+ writeChild(ImmutableMountPointNode.of(mountId, mountCtx, container));
}
};
}
// leaf-list entry nodes are special: they require a value and we can derive it from our instance
// identitifier
final var lastArg = id.getLastPathArgument();
- if (lastArg instanceof NodeWithValue) {
- writer.scalarValue(((NodeWithValue<?>) lastArg).getValue());
+ if (lastArg instanceof NodeWithValue<?> withValue) {
+ writer.scalarValue(withValue.getValue());
}
}
} catch (IOException e) {
* @return {@link NormalizedNodeStreamWriter} which will write item to supplied result holder.
*/
public static @NonNull NormalizedNodeStreamWriter from(final NormalizedNodeResult result) {
- return result instanceof NormalizedNodeMetadataResult ? from((NormalizedNodeMetadataResult) result)
+ return result instanceof NormalizedNodeMetadataResult metadataResult ? from(metadataResult)
: new ImmutableNormalizedNodeStreamWriter(result);
}
}
static <T> @Nullable InterningLeafNodeBuilder<T> forSchema(final @Nullable DataSchemaNode schema) {
- if (schema instanceof LeafSchemaNode) {
- final Optional<Interner<LeafNode<T>>> interner = LeafInterner.forSchema((LeafSchemaNode)schema);
+ if (schema instanceof LeafSchemaNode leafSchema) {
+ final Optional<Interner<LeafNode<T>>> interner = LeafInterner.forSchema(leafSchema);
if (interner.isPresent()) {
- return new InterningLeafNodeBuilder<>(interner.get());
+ return new InterningLeafNodeBuilder<>(interner.orElseThrow());
}
}
return null;
}
private static @Nullable LeafsetEntryInterner getInterner(final @Nullable DataSchemaNode schema) {
- return schema instanceof LeafListSchemaNode ? LeafsetEntryInterner.forSchema((LeafListSchemaNode) schema)
+ return schema instanceof LeafListSchemaNode leafListSchema ? LeafsetEntryInterner.forSchema(leafListSchema)
: null;
}
private boolean writeChildren(final Iterable<? extends NormalizedNode> children, final SchemaNode parentSchemaNode,
final boolean endParent) throws IOException {
// Augmentations cannot be gotten with node.getChild so create our own structure with augmentations resolved
- final Multimap<QName, NormalizedNode> qnameToNodes = ArrayListMultimap.create();
+ final var qnameToNodes = ArrayListMultimap.<QName, NormalizedNode>create();
for (final NormalizedNode child : children) {
putChild(qnameToNodes, child);
}
- if (parentSchemaNode instanceof DataNodeContainer) {
- if (parentSchemaNode instanceof ListSchemaNode && qnameToNodes.containsKey(parentSchemaNode.getQName())) {
+ if (parentSchemaNode instanceof DataNodeContainer parentContainer) {
+ if (parentContainer instanceof ListSchemaNode && qnameToNodes.containsKey(parentSchemaNode.getQName())) {
write(qnameToNodes.get(parentSchemaNode.getQName()), parentSchemaNode);
} else {
- for (final DataSchemaNode schemaNode : ((DataNodeContainer) parentSchemaNode).getChildNodes()) {
+ for (final DataSchemaNode schemaNode : parentContainer.getChildNodes()) {
write(qnameToNodes.get(schemaNode.getQName()), schemaNode);
}
}
- } else if (parentSchemaNode instanceof ChoiceSchemaNode) {
- for (final CaseSchemaNode ccNode : ((ChoiceSchemaNode) parentSchemaNode).getCases()) {
+ } else if (parentSchemaNode instanceof ChoiceSchemaNode parentChoice) {
+ for (final CaseSchemaNode ccNode : parentChoice.getCases()) {
for (final DataSchemaNode dsn : ccNode.getChildNodes()) {
if (qnameToNodes.containsKey(dsn.getQName())) {
write(qnameToNodes.get(dsn.getQName()), dsn);
}
private static void putChild(final Multimap<QName, NormalizedNode> qnameToNodes, final NormalizedNode child) {
- if (child instanceof AugmentationNode) {
- for (DataContainerChild grandChild : ((AugmentationNode) child).body()) {
+ if (child instanceof AugmentationNode augmentChild) {
+ for (DataContainerChild grandChild : augmentChild.body()) {
putChild(qnameToNodes, grandChild);
}
} else {
public static @NonNull DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> create(
final AugmentationNode node) {
- if (!(node instanceof ImmutableAugmentationNode)) {
- throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
+ if (!(node instanceof ImmutableAugmentationNode immutableNode)) {
+ throw new UnsupportedOperationException("Cannot initialize from class " + node.getClass());
}
-
- return new ImmutableAugmentationNodeBuilder((ImmutableAugmentationNode)node);
+ return new ImmutableAugmentationNodeBuilder(immutableNode);
}
@Override
public DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> withChild(
final DataContainerChild child) {
// Check nested augments
- if (child instanceof AugmentationNode) {
- final AugmentationIdentifier myId = getNodeIdentifier();
+ if (child instanceof AugmentationNode aug) {
+ final var myId = getNodeIdentifier();
throw new DataValidationException(String.format(
- "Unable to add: %s, as a child for: %s, Nested augmentations are not permitted", child.getIdentifier(),
+ "Unable to add: %s, as a child for: %s, Nested augmentations are not permitted", aug.getIdentifier(),
myId == null ? this : myId));
}
}
public static @NonNull DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> create(final ChoiceNode node) {
- if (!(node instanceof ImmutableChoiceNode)) {
- throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
+ if (!(node instanceof ImmutableChoiceNode immutableNode)) {
+ throw new UnsupportedOperationException("Cannot initialize from class " + node.getClass());
}
-
- return new ImmutableChoiceNodeBuilder((ImmutableChoiceNode)node);
+ return new ImmutableChoiceNodeBuilder(immutableNode);
}
@Override
}
public static @NonNull DataContainerNodeBuilder<NodeIdentifier, ContainerNode> create(final ContainerNode node) {
- if (!(node instanceof ImmutableContainerNode)) {
- throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
+ if (!(node instanceof ImmutableContainerNode immutableNode)) {
+ throw new UnsupportedOperationException("Cannot initialize from class " + node.getClass());
}
- return new ImmutableContainerNodeBuilder((ImmutableContainerNode) node);
+ return new ImmutableContainerNodeBuilder(immutableNode);
}
@Override
@Override
protected boolean valueEquals(final SystemLeafSetNode<?> other) {
- if (other instanceof ImmutableLeafSetNode) {
- return children.equals(((ImmutableLeafSetNode<?>) other).children);
+ if (other instanceof ImmutableLeafSetNode<?> otherImmutable) {
+ return children.equals(otherImmutable.children);
}
if (size() != other.size()) {
return false;
public static @NonNull DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> create(
final MapEntryNode node) {
- if (!(node instanceof ImmutableMapEntryNode)) {
+ if (!(node instanceof ImmutableMapEntryNode immutableNode)) {
throw new UnsupportedOperationException("Cannot initialize from class " + node.getClass());
}
-
- return new ImmutableMapEntryNodeBuilder((ImmutableMapEntryNode)node);
+ return new ImmutableMapEntryNodeBuilder(immutableNode);
}
private static void fillQNames(final Iterable<DataContainerChild> iterable, final Map<QName, PathArgument> out) {
private @Nullable NodeIdentifier nodeIdentifier = null;
protected ImmutableMapNodeBuilder() {
- this.value = new HashMap<>(DEFAULT_CAPACITY);
+ value = new HashMap<>(DEFAULT_CAPACITY);
}
protected ImmutableMapNodeBuilder(final int sizeHint) {
if (sizeHint >= 0) {
- this.value = Maps.newHashMapWithExpectedSize(sizeHint);
+ value = Maps.newHashMapWithExpectedSize(sizeHint);
} else {
- this.value = new HashMap<>(DEFAULT_CAPACITY);
+ value = new HashMap<>(DEFAULT_CAPACITY);
}
}
protected ImmutableMapNodeBuilder(final SystemMapNode node) {
- this.nodeIdentifier = node.getIdentifier();
- this.value = MapAdaptor.getDefaultInstance().takeSnapshot(
- node instanceof ImmutableMapNode ? ((ImmutableMapNode) node).children : node.asMap());
+ nodeIdentifier = node.getIdentifier();
+ value = MapAdaptor.getDefaultInstance().takeSnapshot(accessChildren(node));
}
public static @NonNull CollectionNodeBuilder<MapEntryNode, SystemMapNode> create() {
@Override
public ImmutableMapNodeBuilder withChild(final MapEntryNode child) {
- this.value.put(child.getIdentifier(), child);
+ value.put(child.getIdentifier(), child);
return this;
}
@Override
public ImmutableMapNodeBuilder withoutChild(final PathArgument key) {
- this.value.remove(key);
+ value.remove(key);
return this;
}
@Override
public ImmutableMapNodeBuilder withNodeIdentifier(final NodeIdentifier withNodeIdentifier) {
- this.nodeIdentifier = withNodeIdentifier;
+ nodeIdentifier = withNodeIdentifier;
return this;
}
@Override
protected boolean valueEquals(final SystemMapNode other) {
- final Map<NodeIdentifierWithPredicates, MapEntryNode> otherChildren =
- other instanceof ImmutableMapNode ? ((ImmutableMapNode) other).children : other.asMap();
- return children.equals(otherChildren);
+ return children.equals(accessChildren(other));
}
}
+
+ private static @NonNull Map<NodeIdentifierWithPredicates, MapEntryNode> accessChildren(final SystemMapNode node) {
+ return node instanceof ImmutableMapNode immutableNode ? immutableNode.children : node.asMap();
+ }
}
public static @NonNull DataContainerNodeBuilder<NodeIdentifier, UnkeyedListEntryNode> create(
final UnkeyedListEntryNode node) {
- if (!(node instanceof ImmutableUnkeyedListEntryNode)) {
- throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
+ if (!(node instanceof ImmutableUnkeyedListEntryNode immutableNode)) {
+ throw new UnsupportedOperationException("Cannot initialize from class " + node.getClass());
}
- return new ImmutableUnkeyedListEntryNodeBuilder((ImmutableUnkeyedListEntryNode) node);
+ return new ImmutableUnkeyedListEntryNodeBuilder(immutableNode);
}
@Override
private boolean dirty;
protected ImmutableUnkeyedListNodeBuilder() {
- this.value = new LinkedList<>();
- this.dirty = false;
+ value = new LinkedList<>();
+ dirty = false;
}
protected ImmutableUnkeyedListNodeBuilder(final ImmutableUnkeyedListNode node) {
- this.nodeIdentifier = node.getIdentifier();
+ nodeIdentifier = node.getIdentifier();
// FIXME: clean this up, notably reuse unmodified lists
- this.value = new LinkedList<>();
+ value = new LinkedList<>();
Iterables.addAll(value, node.body());
- this.dirty = true;
+ dirty = true;
}
public static CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> create() {
public static CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> create(
final UnkeyedListNode node) {
- if (!(node instanceof ImmutableUnkeyedListNode)) {
- throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
+ if (!(node instanceof ImmutableUnkeyedListNode immutableNode)) {
+ throw new UnsupportedOperationException("Cannot initialize from class " + node.getClass());
}
-
- return new ImmutableUnkeyedListNodeBuilder((ImmutableUnkeyedListNode) node);
+ return new ImmutableUnkeyedListNodeBuilder(immutableNode);
}
private void checkDirty() {
@Override
public CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> withChild(final UnkeyedListEntryNode child) {
checkDirty();
- this.value.add(child);
+ value.add(child);
return this;
}
@Override
public CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> withNodeIdentifier(
final NodeIdentifier withNodeIdentifier) {
- this.nodeIdentifier = withNodeIdentifier;
+ nodeIdentifier = withNodeIdentifier;
return this;
}
@Override
protected boolean valueEquals(final UnkeyedListNode other) {
final Collection<UnkeyedListEntryNode> otherChildren;
- if (other instanceof ImmutableUnkeyedListNode) {
- otherChildren = ((ImmutableUnkeyedListNode) other).children;
+ if (other instanceof ImmutableUnkeyedListNode immutableOther) {
+ otherChildren = immutableOther.children;
} else {
otherChildren = other.body();
}
public static <T> @NonNull ListNodeBuilder<T, UserLeafSetNode<T>> create(
final UserLeafSetNode<T> node) {
if (!(node instanceof ImmutableUserLeafSetNode<?>)) {
- throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
+ throw new UnsupportedOperationException("Cannot initialize from class " + node.getClass());
}
return new ImmutableUserLeafSetNodeBuilder<>((ImmutableUserLeafSetNode<T>) node);
@Override
protected boolean valueEquals(final UserLeafSetNode<?> other) {
- if (other instanceof ImmutableUserLeafSetNode) {
- return children.equals(((ImmutableUserLeafSetNode<?>) other).children);
+ if (other instanceof ImmutableUserLeafSetNode<?> immutableOther) {
+ return children.equals(immutableOther.children);
}
// Note: performs a size() check first
return Iterables.elementsEqual(children.values(), other.body());
}
public static @NonNull CollectionNodeBuilder<MapEntryNode, UserMapNode> create(final UserMapNode node) {
- if (!(node instanceof ImmutableUserMapNode)) {
- throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
+ if (!(node instanceof ImmutableUserMapNode immutableNode)) {
+ throw new UnsupportedOperationException("Cannot initialize from class " + node.getClass());
}
-
- return new ImmutableUserMapNodeBuilder((ImmutableUserMapNode) node);
+ return new ImmutableUserMapNodeBuilder(immutableNode);
}
private void checkDirty() {
@Override
protected boolean valueEquals(final UserMapNode other) {
- final Map<NodeIdentifierWithPredicates, MapEntryNode> otherChildren;
- if (other instanceof ImmutableUserMapNode) {
- otherChildren = ((ImmutableUserMapNode) other).children;
- } else {
- otherChildren = other.asMap();
- }
+ final var otherChildren = other instanceof ImmutableUserMapNode immutableOther ? immutableOther.children
+ : other.asMap();
return Iterables.elementsEqual(children.values(), otherChildren.values());
}
}
import org.opendaylight.yangtools.yang.model.api.AugmentationTarget;
import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
/**
* General validator for container like statements, e.g. container, list-entry, choice, augment
public DataNodeContainerValidator(final DataNodeContainer schema) {
this.schema = requireNonNull(schema, "Schema was null");
- this.childNodes = getChildNodes(schema);
+ childNodes = getChildNodes(schema);
- if (schema instanceof AugmentationTarget) {
- for (AugmentationSchemaNode augmentation : ((AugmentationTarget) schema).getAvailableAugmentations()) {
+ if (schema instanceof AugmentationTarget target) {
+ for (var augmentation : target.getAvailableAugmentations()) {
augments.add(DataSchemaContextNode.augmentationIdentifierFrom(augmentation));
}
}
private static Set<QName> getChildNodes(final DataNodeContainer nodeContainer) {
Set<QName> allChildNodes = new HashSet<>();
- for (DataSchemaNode childSchema : nodeContainer.getChildNodes()) {
- if (childSchema instanceof CaseSchemaNode) {
- allChildNodes.addAll(getChildNodes((DataNodeContainer) childSchema));
+ for (var childSchema : nodeContainer.getChildNodes()) {
+ if (childSchema instanceof CaseSchemaNode caseChildSchema) {
+ allChildNodes.addAll(getChildNodes(caseChildSchema));
} else if (!(childSchema instanceof AugmentationSchemaNode)) {
allChildNodes.add(childSchema.getQName());
}
@Override
protected boolean valueEquals(final N other) {
- if (other instanceof AbstractImmutableDataContainerNode) {
- return children.equals(((AbstractImmutableDataContainerNode<?, ?>) other).children);
+ if (other instanceof AbstractImmutableDataContainerNode<?, ?> immutableContainer) {
+ return children.equals(immutableContainer.children);
}
if (size() != other.size()) {
return false;
private static @NonNull DataContainerChild decodeExpendableChild(final PathArgument key,
final @NonNull Object value) {
- return value instanceof DataContainerChild ? (DataContainerChild) value : coerceLeaf(key, value);
+ return value instanceof DataContainerChild child ? child : coerceLeaf(key, value);
}
private static @NonNull Object encodeExpendableChild(final @NonNull DataContainerChild node) {
- return node instanceof LeafNode ? verifyEncode(((LeafNode<?>) node).body()) : node;
+ return node instanceof LeafNode<?> leafNode ? verifyEncode(leafNode.body()) : node;
}
private static @NonNull Object verifyEncode(final @NonNull Object value) {
@Override
public boolean equals(final Object obj) {
- return this == obj || obj instanceof LazyValues && map.equals(((LazyValues)obj).map);
+ return this == obj || obj instanceof LazyValues other && map.equals(other.map);
}
private static final class Iter implements Iterator<DataContainerChild> {
@Override
public DataContainerChild next() {
- final Entry<PathArgument, Object> entry = iterator.next();
- final Object value = entry.getValue();
- return value instanceof DataContainerChild ? (DataContainerChild) value
- : LazyLeafOperations.coerceLeaf(entry.getKey(), value);
+ final var entry = iterator.next();
+ final var value = entry.getValue();
+ return value instanceof DataContainerChild child ? child
+ : LazyLeafOperations.coerceLeaf(entry.getKey(), value);
}
}
}
* @return Unmodifiable view
*/
static Map<PathArgument, DataContainerChild> create(final Map<PathArgument, DataContainerChild> map) {
- if (map instanceof UnmodifiableChildrenMap) {
- return map;
- }
- if (map instanceof ImmutableMap) {
+ if (map instanceof UnmodifiableChildrenMap || map instanceof ImmutableMap) {
return map;
}
if (map.isEmpty()) {
if (map.size() < WRAP_THRESHOLD) {
return ImmutableMap.copyOf(map);
}
-
return new UnmodifiableChildrenMap(map);
}
@Override
@SuppressWarnings("unchecked")
public Map<PathArgument, DataContainerChild> createMutableClone() {
- if (delegate instanceof HashMap) {
- return (Map<PathArgument, DataContainerChild>) ((HashMap<?, ?>) delegate).clone();
+ if (delegate instanceof HashMap<?, ?> hashMap) {
+ return (Map<PathArgument, DataContainerChild>) hashMap.clone();
}
return new HashMap<>(delegate);
}