2 * Copyright (c) 2015 Pantheon Technologies s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.model.util.type;
10 import com.google.common.base.MoreObjects;
11 import com.google.common.base.Preconditions;
12 import com.google.common.collect.ImmutableList;
13 import java.util.Collection;
14 import java.util.List;
15 import org.opendaylight.yangtools.concepts.Immutable;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
18 import org.opendaylight.yangtools.yang.model.api.Status;
19 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
20 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
22 abstract class AbstractDerivedType<T extends TypeDefinition<T>> implements Immutable, TypeDefinition<T> {
23 private final SchemaPath path;
24 private final T baseType;
25 private final Object defaultValue;
26 private final String description;
27 private final String reference;
28 private final Status status;
29 private final String units;
30 private final List<UnknownSchemaNode> unknownSchemNodes;
32 AbstractDerivedType(final T baseType, final SchemaPath path, final Object defaultValue, final String description,
33 final String reference, final Status status, final String units, final Collection<UnknownSchemaNode> unknownSchemNodes) {
34 this.baseType = Preconditions.checkNotNull(baseType);
35 this.path = Preconditions.checkNotNull(path);
36 this.status = Preconditions.checkNotNull(status);
37 this.defaultValue = defaultValue;
38 this.description = description;
39 this.reference = reference;
41 this.unknownSchemNodes = ImmutableList.copyOf(unknownSchemNodes);
45 public final T getBaseType() {
50 public final Object getDefaultValue() {
51 return defaultValue != null ? defaultValue : baseType.getDefaultValue();
55 public final QName getQName() {
56 return path.getLastComponent();
60 public final SchemaPath getPath() {
65 public final List<UnknownSchemaNode> getUnknownSchemaNodes() {
66 return unknownSchemNodes;
70 public final String getDescription() {
75 public final String getReference() {
80 public final Status getStatus() {
85 public final String getUnits() {
86 return units != null ? units : baseType.getUnits();
90 public final String toString() {
91 return MoreObjects.toStringHelper(this).omitNullValues().add("baseType", baseType).add("default", defaultValue)
92 .add("description", description).add("path", path).add("reference", reference).add("status", status)
93 .add("units", units).toString();