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