Introduce model.util.type package
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / type / LengthRestrictedTypeBuilder.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 java.util.Collection;
12 import java.util.List;
13 import javax.annotation.Nonnull;
14 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
15 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
16 import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
17
18 public abstract class LengthRestrictedTypeBuilder<T extends TypeDefinition<T>> extends AbstractRestrictedTypeBuilder<T> {
19     private Collection<LengthConstraint> lengthAlternatives;
20
21     LengthRestrictedTypeBuilder(final T baseType, final SchemaPath path) {
22         super(Preconditions.checkNotNull(baseType), path);
23     }
24
25     public final void setLengthAlternatives(@Nonnull final Collection<LengthConstraint> lengthAlternatives) {
26         Preconditions.checkState(this.lengthAlternatives == null, "Range alternatives already defined as %s",
27                 lengthAlternatives);
28         this.lengthAlternatives = Preconditions.checkNotNull(lengthAlternatives);
29         touch();
30     }
31
32     final List<LengthConstraint> calculateLenghtConstraints(final List<LengthConstraint> baseLengthConstraints) {
33         if (lengthAlternatives == null || lengthAlternatives.isEmpty()) {
34             return baseLengthConstraints;
35         }
36
37         // FIXME: calculate lengths
38         throw new UnsupportedOperationException();
39     }
40 }