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 java.util.Optional;
14 import javax.annotation.Nonnull;
15 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
16 import org.opendaylight.yangtools.yang.model.api.Status;
17 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
18 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
20 abstract class AbstractDerivedType<T extends TypeDefinition<T>> extends AbstractTypeDefinition<T> {
21 private final T baseType;
22 private final Object defaultValue;
23 private final String description;
24 private final String reference;
25 private final Status status;
26 private final String units;
28 AbstractDerivedType(final T baseType, final SchemaPath path, final Object defaultValue, final String description,
29 final String reference, final Status status, final String units,
30 final Collection<UnknownSchemaNode> unknownSchemNodes) {
31 super(path, unknownSchemNodes);
32 this.baseType = Preconditions.checkNotNull(baseType);
33 this.status = Preconditions.checkNotNull(status);
34 this.defaultValue = defaultValue;
35 this.description = description;
36 this.reference = reference;
41 public final T getBaseType() {
42 return baseType instanceof AbstractRestrictedType ? baseType.getBaseType() : baseType;
46 * Return the stored base type. Unlike {@link #getBaseType()}, this method returns the underlying restricted type.
53 public final Optional<? extends Object> getDefaultValue() {
54 return defaultValue != null ? Optional.of(defaultValue) : baseType.getDefaultValue();
58 public final Optional<String> getDescription() {
59 return Optional.ofNullable(description);
63 public final Optional<String> getReference() {
64 return Optional.ofNullable(reference);
69 public final Status getStatus() {
74 public final Optional<String> getUnits() {
75 return units != null ? Optional.of(units) : baseType.getUnits();
79 public final String toString() {
80 return MoreObjects.toStringHelper(this).omitNullValues()
81 .add("baseType", baseType)
82 .add("default", defaultValue)
83 .add("description", description)
84 .add("path", getPath())
85 .add("reference", reference)
86 .add("status", status)
87 .add("units", units).toString();