Disconnect SchemaContextFactoryConfiguration.Builder
[yangtools.git] / parser / yang-parser-api / src / main / java / org / opendaylight / yangtools / yang / parser / api / YangParserConfiguration.java
1 /*
2  * Copyright (c) 2021 PANTHEON.tech, s.r.o. 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.parser.api;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.annotations.Beta;
13 import com.google.common.base.MoreObjects;
14 import java.util.Objects;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.opendaylight.yangtools.concepts.Immutable;
18
19 /**
20  * A configuration of {@link YangParser} wiring for use with {@link YangParserFactory}.
21  */
22 @NonNullByDefault
23 public final class YangParserConfiguration implements Immutable {
24     /**
25      * System-wide default configuration.
26      */
27     public static final YangParserConfiguration DEFAULT = builder().build();
28
29     private final ImportResolutionMode importResolutionMode;
30     private final boolean retainDeclarationReferences;
31
32     private YangParserConfiguration(final ImportResolutionMode importResolutionMode,
33             final boolean retainDeclarationReferences) {
34         this.importResolutionMode = requireNonNull(importResolutionMode);
35         this.retainDeclarationReferences = retainDeclarationReferences;
36     }
37
38     @Beta
39     public ImportResolutionMode importResolutionMode() {
40         return importResolutionMode;
41     }
42
43     public boolean retainDeclarationReferences() {
44         return retainDeclarationReferences;
45     }
46
47     @Override
48     public int hashCode() {
49         return Objects.hash(importResolutionMode, retainDeclarationReferences);
50     }
51
52     @Override
53     public boolean equals(final @Nullable Object obj) {
54         if (this == obj) {
55             return true;
56         }
57         if (!(obj instanceof YangParserConfiguration)) {
58             return false;
59         }
60         final YangParserConfiguration other = (YangParserConfiguration) obj;
61         return importResolutionMode == other.importResolutionMode
62             && retainDeclarationReferences == other.retainDeclarationReferences;
63     }
64
65     @Override
66     public String toString() {
67         return MoreObjects.toStringHelper(this)
68             .add("importResolution", importResolutionMode)
69             .add("declarationReferences", retainDeclarationReferences)
70             .toString();
71     }
72
73     public static Builder builder() {
74         return new Builder();
75     }
76
77     public static final class Builder implements org.opendaylight.yangtools.concepts.Builder<YangParserConfiguration> {
78         private ImportResolutionMode importResolutionMode = ImportResolutionMode.DEFAULT;
79         private boolean retainDeclarationReferences = false;
80
81         private Builder() {
82             // Hidden on purpose
83         }
84
85         @Override
86         public YangParserConfiguration build() {
87             return new YangParserConfiguration(importResolutionMode, retainDeclarationReferences);
88         }
89
90         @Beta
91         public Builder importResolutionMode(final ImportResolutionMode newImportResolutionMode) {
92             this.importResolutionMode = requireNonNull(newImportResolutionMode);
93             return this;
94         }
95
96         public Builder retainDeclarationReferences(final boolean newRetainDeclarationReferences) {
97             this.retainDeclarationReferences = newRetainDeclarationReferences;
98             return this;
99         }
100     }
101 }