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 java.util.Collection;
13 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
14 import org.opendaylight.yangtools.yang.model.api.Status;
15 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
16 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
18 abstract class AbstractDerivedType<T extends TypeDefinition<T>> extends AbstractTypeDefinition<T> {
19 private final T baseType;
20 private final Object defaultValue;
21 private final String description;
22 private final String reference;
23 private final Status status;
24 private final String units;
26 AbstractDerivedType(final T baseType, final SchemaPath path, final Object defaultValue, final String description,
27 final String reference, final Status status, final String units, final Collection<UnknownSchemaNode> unknownSchemNodes) {
28 super(path, unknownSchemNodes);
29 this.baseType = Preconditions.checkNotNull(baseType);
30 this.status = Preconditions.checkNotNull(status);
31 this.defaultValue = defaultValue;
32 this.description = description;
33 this.reference = reference;
38 public final T getBaseType() {
39 return baseType instanceof AbstractRestrictedType ? baseType.getBaseType() : baseType;
43 * Return the stored base type. Unlike {@link #getBaseType()}, this method returns the underlying restricted type.
52 public final Object getDefaultValue() {
53 return defaultValue != null ? defaultValue : baseType.getDefaultValue();
57 public final String getDescription() {
62 public final String getReference() {
67 public final Status getStatus() {
72 public final String getUnits() {
73 return units != null ? units : baseType.getUnits();
77 public final String toString() {
78 return MoreObjects.toStringHelper(this).omitNullValues()
79 .add("baseType", baseType)
80 .add("default", defaultValue)
81 .add("description", description)
82 .add("path", getPath())
83 .add("reference", reference)
84 .add("status", status)
85 .add("units", units).toString();