2 * Copyright (c) 2015 Cisco Systems, Inc. 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.impl.schema.tree;
10 import java.util.Collections;
11 import java.util.HashMap;
12 import java.util.LinkedHashMap;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
17 * Child ordering policy. It defines how a {@link ModifiedNode} tracks its children.
19 abstract class ChildTrackingPolicy {
20 private static final int DEFAULT_CHILD_COUNT = 8;
23 * No child nodes are possible, ever.
25 static final ChildTrackingPolicy NONE = new ChildTrackingPolicy() {
27 Map<PathArgument, ModifiedNode> createMap() {
28 // We cannot use ImmutableMap, as we need a functioning Map.clear()
29 return Collections.emptyMap();
33 * Child nodes are possible and we need to make sure that their iteration order
34 * matches the order in which they are introduced.
36 static final ChildTrackingPolicy ORDERED = new ChildTrackingPolicy() {
38 Map<PathArgument, ModifiedNode> createMap() {
39 return new LinkedHashMap<>(DEFAULT_CHILD_COUNT);
43 * Child nodes are possible, but their iteration order can be undefined.
45 static final ChildTrackingPolicy UNORDERED = new ChildTrackingPolicy() {
47 Map<PathArgument, ModifiedNode> createMap() {
48 return new HashMap<>();
53 * Instantiate a new map for all possible children.
55 * @return An empty map instance
57 abstract Map<PathArgument, ModifiedNode> createMap();