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.ri.type;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.base.MoreObjects;
13 import java.util.Collection;
14 import java.util.Optional;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.Status;
18 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
19 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
21 abstract class AbstractDerivedType<T extends TypeDefinition<T>> extends AbstractTypeDefinition<T> {
22 private final @NonNull T baseType;
23 private final Object defaultValue;
24 private final String description;
25 private final String reference;
26 private final @NonNull Status status;
27 private final String units;
29 AbstractDerivedType(final T baseType, final QName qname, final Object defaultValue, final String description,
30 final String reference, final Status status, final String units,
31 final Collection<? extends UnknownSchemaNode> unknownSchemNodes) {
32 super(qname, unknownSchemNodes);
33 this.baseType = requireNonNull(baseType);
34 this.status = requireNonNull(status);
35 this.defaultValue = defaultValue;
36 this.description = description;
37 this.reference = reference;
42 public final T getBaseType() {
43 return baseType instanceof AbstractRestrictedType ? baseType.getBaseType() : baseType;
47 * Return the stored base type. Unlike {@link #getBaseType()}, this method returns the underlying restricted type.
54 public final Optional<? extends Object> getDefaultValue() {
55 return defaultValue != null ? Optional.of(defaultValue) : baseType.getDefaultValue();
59 public final Optional<String> getDescription() {
60 return Optional.ofNullable(description);
64 public final Optional<String> getReference() {
65 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("qname", getQName())
85 .add("reference", reference)
86 .add("status", status)
87 .add("units", units).toString();