import com.google.common.collect.ImmutableSet;
import java.util.Collections;
import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.Uint32;
import org.opendaylight.yangtools.yang.data.api.codec.BitsCodec;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
for (String bit : bits) {
BitsTypeDefinition.Bit mockBit = mock(BitsTypeDefinition.Bit.class);
when(mockBit.getName()).thenReturn(bit);
- when(mockBit.getPosition()).thenReturn(pos);
+ when(mockBit.getPosition()).thenReturn(Uint32.valueOf(pos));
b.addBit(mockBit);
++pos;
}
import java.util.Objects;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.yangtools.yang.common.Uint32;
import org.opendaylight.yangtools.yang.model.api.DocumentedNode;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
*
* @return The position value of bit in range from 0 to 4294967295.
*/
- long getPosition();
+ @NonNull Uint32 getPosition();
}
}
import java.util.Collection;
import org.opendaylight.yangtools.concepts.Builder;
import org.opendaylight.yangtools.concepts.Mutable;
+import org.opendaylight.yangtools.yang.common.Uint32;
import org.opendaylight.yangtools.yang.model.api.Status;
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit;
@Beta
public final class BitBuilder implements Builder<Bit>, Mutable {
private final String name;
- private final long position;
+ private final Uint32 position;
private ImmutableList<UnknownSchemaNode> unknownSchemaNodes = ImmutableList.of();
private Status status = Status.CURRENT;
private String description;
private String reference;
- private BitBuilder(final String name, final long position) {
+ private BitBuilder(final String name, final Uint32 position) {
this.name = requireNonNull(name);
- this.position = position;
+ this.position = requireNonNull(position);
}
- public static BitBuilder create(final String name, final long position) {
+ public static BitBuilder create(final String name, final Uint32 position) {
return new BitBuilder(name, position);
}
*/
package org.opendaylight.yangtools.yang.model.util.type;
-import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
import com.google.common.collect.ImmutableList;
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.Immutable;
+import org.opendaylight.yangtools.yang.common.Uint32;
import org.opendaylight.yangtools.yang.model.api.Status;
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit;
private final String description;
private final String reference;
private final @NonNull Status status;
- private final long position;
+ private final @NonNull Uint32 position;
- BitImpl(final String name, final long position, final String description,
+ BitImpl(final String name, final Uint32 position, final String description,
final String reference, final Status status, final List<UnknownSchemaNode> unknownNodes) {
this.name = requireNonNull(name);
- checkArgument(position >= 0L && position <= 4294967295L, "Invalid position %s", position);
- this.position = position;
+ this.position = requireNonNull(position);
this.description = description;
this.reference = reference;
this.status = requireNonNull(status);
}
@Override
- public long getPosition() {
+ public Uint32 getPosition() {
return position;
}
@Override
public int hashCode() {
- return 31 * name.hashCode() + Long.hashCode(position);
+ return 31 * name.hashCode() + position.hashCode();
}
@Override
import java.util.Map;
import java.util.TreeMap;
import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.common.Uint32;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit;
@Override
public BitsTypeDefinition buildType() {
final Map<String, Bit> map = builder.build();
- final Map<Long, Bit> positionMap = new TreeMap<>();
+ final Map<Uint32, Bit> positionMap = new TreeMap<>();
for (Bit b : map.values()) {
final Bit conflict = positionMap.put(b.getPosition(), b);
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.Uint32;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.Status;
import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
@Test
public void canCreateBitsType() {
doReturn("test").when(bit).getName();
- doReturn(0L).when(bit).getPosition();
+ doReturn(Uint32.ZERO).when(bit).getPosition();
doReturn("toString").when(bit).toString();
QName qname = QName.create("namespace", "localname");
import java.net.URISyntaxException;
import java.util.Optional;
import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.Uint32;
import org.opendaylight.yangtools.yang.model.api.Status;
public class BitImplTest {
+ private static final Uint32 FIFTY_FIVE = Uint32.valueOf(55);
@Test
// We're testing equals()
// hashCode method test
- BitImpl biA = new BitImpl("someNameA2", 55L, "description", "reference", Status.CURRENT, emptyList());
+ BitImpl biA = new BitImpl("someNameA2", FIFTY_FIVE, "description", "reference", Status.CURRENT, emptyList());
assertEquals("biA should equals to itsefl", biA, biA);
assertFalse("biA shouldn't equal to null", biA.equals(null));
assertFalse("biA shouldn't equal to object of other type", biA.equals("str"));
// // test schemaPath
- biA = new BitImpl("someNameA2", 55L, "description", "reference", Status.CURRENT, emptyList());
- BitImpl biB = new BitImpl("someNameB2", 55L, "description", "reference", Status.CURRENT, emptyList());
+ biA = new BitImpl("someNameA2", FIFTY_FIVE, "description", "reference", Status.CURRENT, emptyList());
+ BitImpl biB = new BitImpl("someNameB2", FIFTY_FIVE, "description", "reference", Status.CURRENT, emptyList());
assertFalse("biA shouldn't equal to biB", biA.equals(biB));
- biA = new BitImpl("someNameB2", 55L, "description", "reference", Status.CURRENT, emptyList());
- biB = new BitImpl("someNameB2", 55L, "description", "reference", Status.CURRENT, emptyList());
+ biA = new BitImpl("someNameB2", FIFTY_FIVE, "description", "reference", Status.CURRENT, emptyList());
+ biB = new BitImpl("someNameB2", FIFTY_FIVE, "description", "reference", Status.CURRENT, emptyList());
assertEquals("biA should equal to biB", biA, biB);
- biA = new BitImpl("someNameA2", 55L, "description", "reference", Status.CURRENT, emptyList());
- biB = new BitImpl("someNameB2", 55L, "description", "reference", Status.CURRENT, emptyList());
+ biA = new BitImpl("someNameA2", FIFTY_FIVE, "description", "reference", Status.CURRENT, emptyList());
+ biB = new BitImpl("someNameB2", FIFTY_FIVE, "description", "reference", Status.CURRENT, emptyList());
assertFalse("biA shouldn't equal to biB", biA.equals(biB));
- biA = new BitImpl("someNameA2", 55L, "description", "reference", Status.CURRENT, emptyList());
- biB = new BitImpl("someNameA2", 55L, "description", "reference", Status.CURRENT, emptyList());
+ biA = new BitImpl("someNameA2", FIFTY_FIVE, "description", "reference", Status.CURRENT, emptyList());
+ biB = new BitImpl("someNameA2", FIFTY_FIVE, "description", "reference", Status.CURRENT, emptyList());
assertEquals("biA should equal to biB", biA, biB);
- biA = new BitImpl("someNameA2", 55L, "description", "reference", Status.CURRENT, emptyList());
+ biA = new BitImpl("someNameA2", FIFTY_FIVE, "description", "reference", Status.CURRENT, emptyList());
// test of getter methods
assertEquals("Incorrect value for qname.", "someNameA2", biA.getName());
import org.junit.Test;
import org.opendaylight.yangtools.concepts.Builder;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.Uint32;
import org.opendaylight.yangtools.yang.model.api.ConstraintMetaDefinition;
import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
import org.opendaylight.yangtools.yang.model.api.PathExpression;
private static final QName Q_NAME = QName.create("test.namespace", "2016-01-01", "test-name");
private static final SchemaPath SCHEMA_PATH = SchemaPath.create(true, Q_NAME);
private static final PathExpression REVISION_AWARE_XPATH = new PathExpressionImpl("/test", true);
- private static final Bit BIT_A = BitBuilder.create(Q_NAME.getLocalName(), 55L).setDescription("description")
- .setReference("reference").build();
+ private static final Bit BIT_A = BitBuilder.create(Q_NAME.getLocalName(), Uint32.valueOf(55L))
+ .setDescription("description")
+ .setReference("reference")
+ .build();
private static final Optional<String> ABSENT = Optional.empty();
@Test
@Test(expected = InvalidBitDefinitionException.class)
public void invalidBitDefinitionExceptionTest() {
- final BitsTypeBuilder bitsTypeBuilder = BaseTypes.bitsTypeBuilder(SCHEMA_PATH);
- bitsTypeBuilder.addBit(BIT_A);
- bitsTypeBuilder.addBit(BitBuilder.create("test-name-1", 55L).build());
+ final BitsTypeBuilder bitsTypeBuilder = BaseTypes.bitsTypeBuilder(SCHEMA_PATH)
+ .addBit(BIT_A)
+ .addBit(BitBuilder.create("test-name-1", Uint32.valueOf(55)).build());
+
bitsTypeBuilder.build();
}
final class BitEffectiveStatementImpl extends AbstractEffectiveDocumentedNode<String, BitStatement>
implements BitEffectiveStatement {
-
BitEffectiveStatementImpl(final StmtContext<String, BitStatement, ?> ctx) {
super(ctx);
}
super(ctx);
final BitsTypeBuilder builder = BaseTypes.bitsTypeBuilder(ctx.getSchemaPath().get());
- Long highestPosition = null;
+ Uint32 highestPosition = null;
for (final EffectiveStatement<?, ?> stmt : effectiveSubstatements()) {
if (stmt instanceof BitEffectiveStatement) {
final BitEffectiveStatement bitSubStmt = (BitEffectiveStatement) stmt;
final Optional<Uint32> declaredPosition = bitSubStmt.getDeclaredPosition();
- final long effectivePos;
+ final Uint32 effectivePos;
if (declaredPosition.isEmpty()) {
if (highestPosition != null) {
- SourceException.throwIf(highestPosition == 4294967295L, ctx.getStatementSourceReference(),
- "Bit %s must have a position statement", bitSubStmt);
- effectivePos = highestPosition + 1;
+ SourceException.throwIf(Uint32.MAX_VALUE.equals(highestPosition),
+ ctx.getStatementSourceReference(), "Bit %s must have a position statement", bitSubStmt);
+ effectivePos = Uint32.fromIntBits(highestPosition.intValue() + 1);
} else {
- effectivePos = 0L;
+ effectivePos = Uint32.ZERO;
}
} else {
- effectivePos = declaredPosition.get().toJava();
+ effectivePos = declaredPosition.get();
}
final Bit bit = EffectiveTypeUtil.buildBit(bitSubStmt, effectivePos);
- SourceException.throwIf(bit.getPosition() < 0L && bit.getPosition() > 4294967295L,
- ctx.getStatementSourceReference(), "Bit %s has illegal position", bit);
-
- if (highestPosition == null || highestPosition < bit.getPosition()) {
+ if (highestPosition == null || highestPosition.compareTo(bit.getPosition()) < 0) {
highestPosition = bit.getPosition();
}
// FIXME: this looks like a duplicate of BitsSpecificationEffectiveStatement
final Optional<Uint32> declared = bitSubStmt.getDeclaredPosition();
- final long effectivePos;
+ final Uint32 effectivePos;
if (declared.isEmpty()) {
effectivePos = getBaseTypeBitPosition(bitSubStmt.argument(), baseType, ctx);
} else {
- effectivePos = declared.get().toJava();
+ effectivePos = declared.get();
}
builder.addBit(EffectiveTypeUtil.buildBit(bitSubStmt, effectivePos));
typeDefinition = builder.build();
}
- private static long getBaseTypeBitPosition(final String bitName, final BitsTypeDefinition baseType,
+ private static Uint32 getBaseTypeBitPosition(final String bitName, final BitsTypeDefinition baseType,
final StmtContext<?, ?, ?> ctx) {
for (Bit baseTypeBit : baseType.getBits()) {
if (bitName.equals(baseTypeBit.getName())) {
import com.google.common.annotations.Beta;
import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.common.Uint32;
import org.opendaylight.yangtools.yang.model.api.DocumentedNode;
import org.opendaylight.yangtools.yang.model.api.DocumentedNode.WithStatus;
import org.opendaylight.yangtools.yang.model.api.stmt.BitEffectiveStatement;
// Hidden on purpose
}
- static @NonNull Bit buildBit(final @NonNull BitEffectiveStatement stmt, final long effectivePos) {
+ static @NonNull Bit buildBit(final @NonNull BitEffectiveStatement stmt, final Uint32 effectivePos) {
verify(stmt instanceof DocumentedNode.WithStatus);
final DocumentedNode.WithStatus bit = (WithStatus) stmt;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Revision;
+import org.opendaylight.yangtools.yang.common.Uint32;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
}
private static Bit createBit(final String name, final long position) {
- return BitBuilder.create(name, position).build();
+ return BitBuilder.create(name, Uint32.valueOf(position)).build();
}
private static void assertContainsBits(final Collection<? extends Bit> bitList, final Bit... bits) {
import java.util.List;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.Uint32;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
final String name = bit.getName();
switch (name) {
case "zero":
- assertEquals(0, bit.getPosition());
+ assertEquals(Uint32.ZERO, bit.getPosition());
break;
case "twenty":
- assertEquals(20, bit.getPosition());
+ assertEquals(Uint32.valueOf(20), bit.getPosition());
break;
case "twenty-one":
- assertEquals(21, bit.getPosition());
+ assertEquals(Uint32.valueOf(21), bit.getPosition());
break;
case "two":
- assertEquals(2, bit.getPosition());
+ assertEquals(Uint32.TWO, bit.getPosition());
break;
case "twenty-two":
- assertEquals(22, bit.getPosition());
+ assertEquals(Uint32.valueOf(22), bit.getPosition());
break;
default:
fail("Unexpected bit name.");
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.Uint32;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
assertFalse(bitEff.equals(bitEffSecond));
assertNotNull(bitEff.toString());
assertEquals("one", bitEff.getName());
- assertEquals(0, bitEff.getPosition());
+ assertEquals(Uint32.ZERO, bitEff.getPosition());
}
@Test
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Revision;
+import org.opendaylight.yangtools.yang.common.Uint32;
import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
Bit bit1 = bits.next();
assertEquals("disable-nagle", bit1.getName());
- assertEquals(0L, bit1.getPosition());
+ assertEquals(Uint32.ZERO, bit1.getPosition());
Bit bit2 = bits.next();
assertEquals("auto-sense-speed", bit2.getName());
- assertEquals(1L, bit2.getPosition());
+ assertEquals(Uint32.ONE, bit2.getPosition());
Bit bit3 = bits.next();
assertEquals("only-10-Mb", bit3.getName());
- assertEquals(2L, bit3.getPosition());
+ assertEquals(Uint32.TWO, bit3.getPosition());
assertFalse(bits.hasNext());
}
Bit bit0 = bits.next();
assertEquals("create", bit0.getName());
- assertEquals(0L, bit0.getPosition());
+ assertEquals(Uint32.ZERO, bit0.getPosition());
Bit bit1 = bits.next();
assertEquals("delete", bit1.getName());
- assertEquals(365L, bit1.getPosition());
+ assertEquals(Uint32.valueOf(365), bit1.getPosition());
Bit bit2 = bits.next();
assertEquals("read", bit2.getName());
- assertEquals(500L, bit2.getPosition());
+ assertEquals(Uint32.valueOf(500), bit2.getPosition());
Bit bit3 = bits.next();
assertEquals("update", bit3.getName());
- assertEquals(501L, bit3.getPosition());
+ assertEquals(Uint32.valueOf(501), bit3.getPosition());
Bit bit4 = bits.next();
assertEquals("exec", bit4.getName());
- assertEquals(502L, bit4.getPosition());
+ assertEquals(Uint32.valueOf(502), bit4.getPosition());
assertFalse(bits.hasNext());
}