Filter non-Yang files when loading a directory
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / BitsType.java
1 /*
2  * Copyright (c) 2013 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.model.util;
9
10 import com.google.common.base.Preconditions;
11 import com.google.common.collect.ImmutableList;
12 import java.util.Collections;
13 import java.util.List;
14 import java.util.Objects;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
17 import org.opendaylight.yangtools.yang.model.api.Status;
18 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
20
21 /**
22  * The <code>default</code> implementation of Bits Type Definition interface.
23  *
24  * @see BitsTypeDefinition
25  */
26 public final class BitsType implements BitsTypeDefinition {
27     private static final QName NAME = BaseTypes.BITS_QNAME;
28     private static final String DESCRIPTION = "The bits built-in type represents a bit set. "
29             + "That is, a bits value is a set of flags identified by small integer position "
30             + "numbers starting at 0.  Each bit number has an assigned name.";
31
32     private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.7";
33     private static final String UNITS = "";
34     private final SchemaPath path;
35     private final List<Bit> bits;
36
37     /**
38      * Constructor with explicit definition of bits assigned to BitsType.
39      *
40      * @param path
41      * @param bits
42      */
43     private BitsType(final SchemaPath path, final List<Bit> bits) {
44         super();
45         this.bits = ImmutableList.copyOf(bits);
46         this.path = Preconditions.checkNotNull(path, "path must not be null");
47     }
48
49     public static BitsType create(final SchemaPath path, final List<Bit> bits) {
50         return new BitsType(path,bits);
51     }
52
53     /*
54      * (non-Javadoc)
55      *
56      * @see
57      * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
58      */
59     @Override
60     public BitsTypeDefinition getBaseType() {
61         return null;
62     }
63
64     /*
65      * (non-Javadoc)
66      *
67      * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
68      */
69     @Override
70     public String getUnits() {
71         return UNITS;
72     }
73
74     /*
75      * (non-Javadoc)
76      *
77      * @see
78      * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
79      * ()
80      */
81     @Override
82     public Object getDefaultValue() {
83         // FIXME: Return real bits.
84         return null;
85     }
86
87     /*
88      * (non-Javadoc)
89      *
90      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
91      */
92     @Override
93     public QName getQName() {
94         return NAME;
95     }
96
97     /*
98      * (non-Javadoc)
99      *
100      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
101      */
102     @Override
103     public SchemaPath getPath() {
104         return path;
105     }
106
107     /*
108      * (non-Javadoc)
109      *
110      * @see
111      * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
112      */
113     @Override
114     public String getDescription() {
115         return DESCRIPTION;
116     }
117
118     /*
119      * (non-Javadoc)
120      *
121      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
122      */
123     @Override
124     public String getReference() {
125         return REFERENCE;
126     }
127
128     /*
129      * (non-Javadoc)
130      *
131      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
132      */
133     @Override
134     public Status getStatus() {
135         return Status.CURRENT;
136     }
137
138     @Override
139     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
140         return Collections.emptyList();
141     }
142
143     @Override
144     public List<Bit> getBits() {
145         return bits;
146     }
147
148     @Override
149     public int hashCode() {
150         final int prime = 31;
151         int result = 1;
152         result = prime * result + Objects.hashCode(bits);
153         result = prime * result + NAME.hashCode();
154         result = prime * result + path.hashCode();
155         return result;
156     }
157
158     @Override
159     public boolean equals(final Object obj) {
160         if (this == obj) {
161             return true;
162         }
163         if (obj == null) {
164             return false;
165         }
166         if (getClass() != obj.getClass()) {
167             return false;
168         }
169         BitsType other = (BitsType) obj;
170         return Objects.equals(bits, other.bits) && Objects.equals(path, other.path);
171     }
172
173     @Override
174     public String toString() {
175         StringBuilder builder = new StringBuilder();
176         builder.append("BitsType [name=");
177         builder.append(NAME);
178         builder.append(", path=");
179         builder.append(path);
180         builder.append(", description=");
181         builder.append(DESCRIPTION);
182         builder.append(", reference=");
183         builder.append(REFERENCE);
184         builder.append(", bits=");
185         builder.append(bits);
186         builder.append(", units=");
187         builder.append(UNITS);
188         builder.append("]");
189         return builder.toString();
190     }
191 }