Introduce model.util.type package
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / type / DecimalTypeBuilder.java
1 /*
2  * Copyright (c) 2015 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.model.util.type;
9
10 import com.google.common.base.Preconditions;
11 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
12 import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
13
14 public final class DecimalTypeBuilder extends TypeBuilder<DecimalTypeDefinition> {
15     private Integer fractionDigits;
16
17     DecimalTypeBuilder(final SchemaPath path) {
18         super(null, path);
19     }
20
21     public DecimalTypeBuilder setFractionDigits(final int fractionDigits) {
22         Preconditions.checkState(this.fractionDigits == null, "Fraction digits already defined to %s",
23                 this.fractionDigits);
24         this.fractionDigits = fractionDigits;
25         return this;
26     }
27
28     @Override
29     public BaseDecimalType build() {
30         Preconditions.checkState(fractionDigits != null, "Fraction digits not defined");
31         return new BaseDecimalType(getPath(), getUnknownSchemaNodes(), fractionDigits);
32     }
33 }