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 com.google.common.base.Verify.verifyNotNull;
12 import com.google.common.annotations.Beta;
13 import java.util.Objects;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
19 * Builder of {@link TypeDefinition}s for use in leaf statements. While similar to {@link DerivedTypeBuilder}, this
20 * builder does not support adding of unknown nodes and will return the base type if the type is not modified, hence
21 * not preserving the schema path.
23 * @param <T> Resulting {@link TypeDefinition}
26 public abstract class ConcreteTypeBuilder<T extends TypeDefinition<T>> extends DerivedTypeBuilder<T> {
27 ConcreteTypeBuilder(final T baseType, final QName qname) {
28 super(baseType, qname);
30 setStatus(baseType.getStatus());
31 baseType.getDescription().ifPresent(this::setDescription);
32 baseType.getReference().ifPresent(this::setReference);
36 * Build the resulting type.
38 * @return A new type instance
40 abstract @NonNull T buildType();
43 public final T build() {
44 final T base = getBaseType();
45 if (Objects.equals(getDefaultValue(), base.getDefaultValue().orElse(null))
46 && Objects.equals(getUnits(), base.getUnits().orElse(null))) {
50 return verifyNotNull(buildType());