/* * Copyright (c) 2015 Pantheon Technologies s.r.o. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.yangtools.yang.model.ri.type; import static java.util.Objects.requireNonNull; import com.google.common.base.MoreObjects; import java.util.Collection; import java.util.Optional; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.Status; import org.opendaylight.yangtools.yang.model.api.TypeDefinition; import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; abstract class AbstractDerivedType> extends AbstractTypeDefinition { private final @NonNull T baseType; private final Object defaultValue; private final String description; private final String reference; private final @NonNull Status status; private final String units; AbstractDerivedType(final T baseType, final QName qname, final Object defaultValue, final String description, final String reference, final Status status, final String units, final Collection unknownSchemNodes) { super(qname, unknownSchemNodes); this.baseType = requireNonNull(baseType); this.status = requireNonNull(status); this.defaultValue = defaultValue; this.description = description; this.reference = reference; this.units = units; } @Override public final T getBaseType() { return baseType instanceof AbstractRestrictedType ? baseType.getBaseType() : baseType; } /** * Return the stored base type. Unlike {@link #getBaseType()}, this method returns the underlying restricted type. */ final T baseType() { return baseType; } @Override public final Optional getDefaultValue() { return defaultValue != null ? Optional.of(defaultValue) : baseType.getDefaultValue(); } @Override public final Optional getDescription() { return Optional.ofNullable(description); } @Override public final Optional getReference() { return Optional.ofNullable(reference); } @Override public final Status getStatus() { return status; } @Override public final Optional getUnits() { return units != null ? Optional.of(units) : baseType.getUnits(); } @Override public final String toString() { return MoreObjects.toStringHelper(this).omitNullValues() .add("baseType", baseType) .add("default", defaultValue) .add("description", description) .add("qname", getQName()) .add("reference", reference) .add("status", status) .add("units", units).toString(); } }