*/
package org.opendaylight.yangtools.yang.model.api.type;
-import java.util.List;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-
/**
* The binary built-in type represents any binary data, i.e., a sequence of
* octets.
* href="https://tools.ietf.org/html/rfc6020#section-9.8">[RFC-6020] The binary
* Built-In Type</a>
*/
-public interface BinaryTypeDefinition extends TypeDefinition<BinaryTypeDefinition> {
- /**
- * Returns List of number of octets that binary value contains. These are the effective constraints, e.g. they
- * include any range constraints imposed by base types.
- *
- * @return List of number of octets that binary value contains.
- *
- * @see LengthConstraint
- */
- List<LengthConstraint> getLengthConstraints();
+public interface BinaryTypeDefinition extends LengthRestrictedTypeDefinition<BinaryTypeDefinition> {
+
}
--- /dev/null
+/*
+ * Copyright (c) 2017 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.api.type;
+
+import java.util.List;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+
+/**
+ * Interface for {@link TypeDefinition}s which can have their values restricted to a set of allowed lengths.
+ *
+ * @param <T> Concrete {@link TypeDefinition} subinterface
+ */
+public interface LengthRestrictedTypeDefinition<T extends TypeDefinition<T>> extends TypeDefinition<T> {
+ /**
+ * Returns length constraints. These are the effective constraints, e.g. they include any length constraints
+ * implied by base types.
+ *
+ * @return list of length constraint which are specified in the <code>length</code> substatement
+ * of the <code>type</code> statement.
+ */
+ List<LengthConstraint> getLengthConstraints();
+}
package org.opendaylight.yangtools.yang.model.api.type;
import java.util.List;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
/**
- * Contains method for getting data from the <code>string</code> YANG built-in
- * type.
+ * Contains method for getting data from the <code>string</code> YANG built-in type.
*/
-public interface StringTypeDefinition extends TypeDefinition<StringTypeDefinition> {
-
- /**
- * Returns length constraint specified in the string. These are the effective constraints, e.g. they include
- * any length constraints implied by base types.
- *
- * @return list of length constraint which are specified in the
- * <code>length</code> substatement of the <code>type</code>
- * statement
- */
- List<LengthConstraint> getLengthConstraints();
-
+public interface StringTypeDefinition extends LengthRestrictedTypeDefinition<StringTypeDefinition> {
/**
* Returns patterns specified in the string.
*
--- /dev/null
+/*
+ * Copyright (c) 2017 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.util.type;
+
+import com.google.common.collect.ImmutableList;
+import java.util.List;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
+import org.opendaylight.yangtools.yang.model.api.type.LengthRestrictedTypeDefinition;
+
+abstract class AbstractLengthRestrictedBaseType<T extends LengthRestrictedTypeDefinition<T>> extends AbstractBaseType<T>
+ implements LengthRestrictedTypeDefinition<T> {
+
+ AbstractLengthRestrictedBaseType(final QName qname) {
+ super(qname);
+ }
+
+ @Override
+ public final List<LengthConstraint> getLengthConstraints() {
+ return ImmutableList.of();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 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.util.type;
+
+import java.util.Collection;
+import java.util.List;
+import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
+import org.opendaylight.yangtools.yang.model.api.type.LengthRestrictedTypeDefinition;
+
+abstract class AbstractLengthRestrictedDerivedType<T extends LengthRestrictedTypeDefinition<T>>
+ extends AbstractDerivedType<T> implements LengthRestrictedTypeDefinition<T> {
+
+ AbstractLengthRestrictedDerivedType(final T baseType, final SchemaPath path,
+ final Object defaultValue, final String description, final String reference, final Status status,
+ final String units, final Collection<UnknownSchemaNode> unknownSchemaNodes) {
+ super(baseType, path, defaultValue, description, reference, status, units, unknownSchemaNodes);
+ }
+
+ @Nonnull
+ @Override
+ public final List<LengthConstraint> getLengthConstraints() {
+ return baseType().getLengthConstraints();
+ }
+}
import java.util.Collection;
import java.util.List;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
+import org.opendaylight.yangtools.yang.model.api.type.LengthRestrictedTypeDefinition;
-abstract class AbstractLengthRestrictedType<T extends TypeDefinition<T>> extends AbstractRestrictedType<T> {
+abstract class AbstractLengthRestrictedType<T extends LengthRestrictedTypeDefinition<T>>
+ extends AbstractRestrictedType<T> implements LengthRestrictedTypeDefinition<T> {
private final List<LengthConstraint> lengthConstraints;
AbstractLengthRestrictedType(final T baseType, final SchemaPath path,
this.lengthConstraints = ImmutableList.copyOf(lengthConstraints);
}
+ @Override
public final List<LengthConstraint> getLengthConstraints() {
return lengthConstraints;
}
*/
package org.opendaylight.yangtools.yang.model.util.type;
-import com.google.common.collect.ImmutableList;
-import java.util.List;
import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
import org.opendaylight.yangtools.yang.model.util.BaseTypes;
-final class BaseBinaryType extends AbstractBaseType<BinaryTypeDefinition> implements BinaryTypeDefinition {
+final class BaseBinaryType extends AbstractLengthRestrictedBaseType<BinaryTypeDefinition>
+ implements BinaryTypeDefinition {
static final BaseBinaryType INSTANCE = new BaseBinaryType();
private BaseBinaryType() {
super(BaseTypes.BINARY_QNAME);
}
- @Override
- public List<LengthConstraint> getLengthConstraints() {
- return ImmutableList.of();
- }
-
@Override
public int hashCode() {
return TypeDefinitions.hashCode(this);
import com.google.common.collect.ImmutableList;
import java.util.List;
-import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
import org.opendaylight.yangtools.yang.model.util.BaseTypes;
-final class BaseStringType extends AbstractBaseType<StringTypeDefinition> implements StringTypeDefinition {
+final class BaseStringType extends AbstractLengthRestrictedBaseType<StringTypeDefinition>
+ implements StringTypeDefinition {
static final BaseStringType INSTANCE = new BaseStringType();
private BaseStringType() {
super(BaseTypes.STRING_QNAME);
}
- @Override
- public List<LengthConstraint> getLengthConstraints() {
- return ImmutableList.of();
- }
-
@Override
public List<PatternConstraint> getPatternConstraints() {
return ImmutableList.of();
package org.opendaylight.yangtools.yang.model.util.type;
import java.util.Collection;
-import java.util.List;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.Status;
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
-final class DerivedBinaryType extends AbstractDerivedType<BinaryTypeDefinition> implements BinaryTypeDefinition {
+final class DerivedBinaryType extends AbstractLengthRestrictedDerivedType<BinaryTypeDefinition>
+ implements BinaryTypeDefinition {
DerivedBinaryType(final BinaryTypeDefinition baseType, final SchemaPath path, final Object defaultValue,
final String description, final String reference, final Status status, final String units,
final Collection<UnknownSchemaNode> unknownSchemNodes) {
super(baseType, path, defaultValue, description, reference, status, units, unknownSchemNodes);
}
- @Override
- public List<LengthConstraint> getLengthConstraints() {
- return baseType().getLengthConstraints();
- }
-
@Override
public int hashCode() {
return TypeDefinitions.hashCode(this);
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.Status;
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
-final class DerivedStringType extends AbstractDerivedType<StringTypeDefinition> implements StringTypeDefinition {
+final class DerivedStringType extends AbstractLengthRestrictedDerivedType<StringTypeDefinition>
+ implements StringTypeDefinition {
DerivedStringType(final StringTypeDefinition baseType, final SchemaPath path, final Object defaultValue,
final String description, final String reference, final Status status, final String units,
final Collection<UnknownSchemaNode> unknownSchemaNodes) {
return baseType().getPatternConstraints();
}
- @Override
- public List<LengthConstraint> getLengthConstraints() {
- return baseType().getLengthConstraints();
- }
-
@Override
public int hashCode() {
return TypeDefinitions.hashCode(this);
import java.util.function.Function;
import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
+import org.opendaylight.yangtools.yang.model.api.type.LengthRestrictedTypeDefinition;
import org.opendaylight.yangtools.yang.model.util.BaseConstraints;
import org.opendaylight.yangtools.yang.model.util.UnresolvedNumber;
-public abstract class LengthRestrictedTypeBuilder<T extends TypeDefinition<T>>
+public abstract class LengthRestrictedTypeBuilder<T extends LengthRestrictedTypeDefinition<T>>
extends AbstractRestrictedTypeBuilder<T> {
private List<LengthConstraint> lengthAlternatives;
abstract T buildType(List<LengthConstraint> lengthConstraints);
- abstract List<LengthConstraint> getLengthConstraints(T type);
-
abstract List<LengthConstraint> typeLengthConstraints();
private List<LengthConstraint> findLenghts() {
List<LengthConstraint> ret = ImmutableList.of();
T wlk = getBaseType();
while (wlk != null && ret.isEmpty()) {
- ret = getLengthConstraints(wlk);
+ ret = wlk.getLengthConstraints();
wlk = wlk.getBaseType();
}
*/
return JavaLengthConstraints.INTEGER_SIZE_CONSTRAINTS;
}
-
- @Override
- List<LengthConstraint> getLengthConstraints(final BinaryTypeDefinition type) {
- return type.getLengthConstraints();
- }
};
}
return this;
}
- @Override
- List<LengthConstraint> getLengthConstraints(final StringTypeDefinition type) {
- return type.getLengthConstraints();
- }
-
@Override
List<LengthConstraint> typeLengthConstraints() {
/**
final LengthRestrictedTypeBuilder<BinaryTypeDefinition> lengthRestrictedTypeBuilder = RestrictedTypes
.newBinaryBuilder(baseBinaryType1, SCHEMA_PATH);
final BaseBinaryType baseBinaryType = (BaseBinaryType)lengthRestrictedTypeBuilder.build();
- assertEquals(lengthRestrictedTypeBuilder.getLengthConstraints(baseBinaryType1),
- baseBinaryType.getLengthConstraints());
assertEquals(baseBinaryType, baseBinaryType1);
concreteBuilderTest(baseBinaryType1, derivedBinaryType1);
}