Bug 4295: Fixed incorrectly introduced nodes when MERGE was followed by DELETE
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / ChildTrackingPolicy.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
9
10 import java.util.Collections;
11 import java.util.HashMap;
12 import java.util.LinkedHashMap;
13 import java.util.Map;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
15
16 /**
17  * Child ordering policy. It defines how a {@link ModifiedNode} tracks its children.
18  */
19 abstract class ChildTrackingPolicy {
20     private static final int DEFAULT_CHILD_COUNT = 8;
21
22     /**
23      * No child nodes are possible, ever.
24      */
25     static final ChildTrackingPolicy NONE = new ChildTrackingPolicy() {
26         @Override
27         Map<PathArgument, ModifiedNode> createMap() {
28             return Collections.emptyMap();
29         }
30     };
31     /**
32      * Child nodes are possible and we need to make sure that their iteration order
33      * matches the order in which they are introduced.
34      */
35     static final ChildTrackingPolicy ORDERED = new ChildTrackingPolicy() {
36         @Override
37         Map<PathArgument, ModifiedNode> createMap() {
38             return new LinkedHashMap<>(DEFAULT_CHILD_COUNT);
39         }
40     };
41     /**
42      * Child nodes are possible, but their iteration order can be undefined.
43      */
44     static final ChildTrackingPolicy UNORDERED = new ChildTrackingPolicy() {
45         @Override
46         Map<PathArgument, ModifiedNode> createMap() {
47             return new HashMap<>();
48         }
49     };
50
51     /**
52      * Instantiate a new map for all possible children.
53      *
54      * @return An empty map instance
55      */
56     abstract Map<PathArgument, ModifiedNode> createMap();
57 }