NormalizedMetadata is not Identifiable
[yangtools.git] / data / yang-data-api / src / main / java / org / opendaylight / yangtools / yang / data / api / schema / DuplicateEntry.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.api.schema;
9
10 import java.util.ArrayList;
11 import java.util.List;
12 import org.opendaylight.yangtools.concepts.Identifiable;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
14
15 /**
16  * Entry describing a duplicate found in a {@link NormalizedNode} tree. Note this
17  * class leaks mutable collections, so users are advised either not to share it.
18  */
19 public final class DuplicateEntry implements Identifiable<YangInstanceIdentifier> {
20     private final List<YangInstanceIdentifier> hardLinks = new ArrayList<>(1);
21     private List<YangInstanceIdentifier> duplicates = List.of();
22
23     DuplicateEntry(final YangInstanceIdentifier path) {
24         hardLinks.add(path);
25     }
26
27     void addDuplicate(final YangInstanceIdentifier path) {
28         if (duplicates.isEmpty()) {
29             duplicates = new ArrayList<>();
30         }
31         duplicates.add(path);
32     }
33
34     void addHardLink(final YangInstanceIdentifier path) {
35         hardLinks.add(path);
36     }
37
38     @Override
39     public YangInstanceIdentifier getIdentifier() {
40         return hardLinks.get(0);
41     }
42
43     public List<YangInstanceIdentifier> getHardLinks() {
44         return hardLinks;
45     }
46
47     public List<YangInstanceIdentifier> getDuplicates() {
48         return duplicates;
49     }
50 }