Do not pretty-print body class
[yangtools.git] / data / 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             // We cannot use ImmutableMap, as we need a functioning Map.clear()
29             return Collections.emptyMap();
30         }
31     };
32     /**
33      * Child nodes are possible and we need to make sure that their iteration order
34      * matches the order in which they are introduced.
35      */
36     static final ChildTrackingPolicy ORDERED = new ChildTrackingPolicy() {
37         @Override
38         Map<PathArgument, ModifiedNode> createMap() {
39             return new LinkedHashMap<>(DEFAULT_CHILD_COUNT);
40         }
41     };
42     /**
43      * Child nodes are possible, but their iteration order can be undefined.
44      */
45     static final ChildTrackingPolicy UNORDERED = new ChildTrackingPolicy() {
46         @Override
47         Map<PathArgument, ModifiedNode> createMap() {
48             return new HashMap<>();
49         }
50     };
51
52     /**
53      * Instantiate a new map for all possible children.
54      *
55      * @return An empty map instance
56      */
57     abstract Map<PathArgument, ModifiedNode> createMap();
58 }