This removes classes no longer used anywhere.
Change-Id: I911d7e721f2c66059afdb0b54d9b15427fbe4706
Signed-off-by: Robert Varga <rovarga@cisco.com>
package org.opendaylight.yangtools.yang.data.impl.codecs;
-import static org.junit.Assert.*;
-
-import org.junit.Test;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.getCodec;
-import org.opendaylight.yangtools.yang.data.api.codec.BinaryCodec;
-import org.opendaylight.yangtools.yang.model.util.BinaryType;
-
import com.google.common.io.BaseEncoding;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.data.api.codec.BinaryCodec;
+import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
/**
* Unit tests for BinaryCodecString.
@SuppressWarnings("unchecked")
@Test
public void testSerialize() {
- BinaryCodec<String> codec = getCodec( BinaryType.getInstance(), BinaryCodec.class);
+ BinaryCodec<String> codec = getCodec(BaseTypes.binaryType(), BinaryCodec.class);
- assertEquals( "serialize", BaseEncoding.base64().encode( new byte[]{1,2,3,4} ),
- codec.serialize( new byte[]{1,2,3,4} ) );
- assertEquals( "serialize", "", codec.serialize( null ) );
+ assertEquals("serialize", BaseEncoding.base64().encode(new byte[] { 1, 2, 3, 4 }),
+ codec.serialize( new byte[] { 1, 2, 3, 4 }));
+ assertEquals( "serialize", "", codec.serialize(null));
}
@SuppressWarnings("unchecked")
@Test
public void testDererialize() {
- BinaryCodec<String> codec = getCodec( BinaryType.getInstance(), BinaryCodec.class);
+ BinaryCodec<String> codec = getCodec(BaseTypes.binaryType(), BinaryCodec.class);
- assertArrayEquals( "deserialize", new byte[]{1,2,3,4},
- codec.deserialize( BaseEncoding.base64().encode( new byte[]{1,2,3,4} ) ) );
- assertEquals( "deserialize", null, codec.deserialize( null ) );
+ assertArrayEquals("deserialize", new byte[] {1, 2, 3, 4 },
+ codec.deserialize(BaseEncoding.base64().encode( new byte[] { 1, 2, 3, 4 })));
+ assertEquals("deserialize", null, codec.deserialize(null));
}
}
package org.opendaylight.yangtools.yang.data.impl.codecs;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import com.google.common.collect.ImmutableSet;
import java.util.Collections;
import org.junit.Test;
-
import org.opendaylight.yangtools.yang.data.api.codec.BitsCodec;
-import com.google.common.collect.ImmutableSet;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
+import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
+import org.opendaylight.yangtools.yang.model.util.type.BitsTypeBuilder;
/**
* Unit tests for BitsCodecString.
*/
public class BitsCodecStringTest {
+ private static BitsTypeDefinition toBitsTypeDefinition(final String... bits) {
+ final BitsTypeBuilder b = BaseTypes.bitsTypeBuilder(mock(SchemaPath.class));
+
+ long i = 0;
+ for (String bit : bits) {
+ BitsTypeDefinition.Bit mockBit = mock(BitsTypeDefinition.Bit.class);
+ when(mockBit.getName()).thenReturn(bit);
+ when(mockBit.getPosition()).thenReturn(i);
+ b.addBit(mockBit);
+ ++i;
+ }
+
+ return b.build();
+ }
+
@SuppressWarnings("unchecked")
@Test
public void testSerialize() {
- BitsCodec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec( TypeDefinitionAwareCodecTestHelper.toBitsTypeDefinition( "foo" ), BitsCodec.class );
+ BitsCodec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(
+ toBitsTypeDefinition("foo"), BitsCodec.class);
ImmutableSet<String> toSerialize = ImmutableSet.of("foo", "bar");
@Test
public void testDeserialize() {
- BitsCodec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec( TypeDefinitionAwareCodecTestHelper.toBitsTypeDefinition( "bit1", "bit2" ), BitsCodec.class );
+ BitsCodec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(
+ toBitsTypeDefinition("bit1", "bit2"), BitsCodec.class);
assertEquals("deserialize", ImmutableSet.of("bit1", "bit2"), codec.deserialize(" bit1 bit2 "));
package org.opendaylight.yangtools.yang.data.impl.codecs;
-import static org.junit.Assert.*;
-
+import static org.junit.Assert.assertEquals;
import org.junit.Test;
-
import org.opendaylight.yangtools.yang.data.api.codec.BooleanCodec;
-import org.opendaylight.yangtools.yang.model.util.BooleanType;
+import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
/**
* Unit tests for BooleanCodecString.
@SuppressWarnings("unchecked")
@Test
public void testSerialize() {
- BooleanCodec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec( BooleanType.getInstance(), BooleanCodec.class);
+ BooleanCodec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.booleanType(), BooleanCodec.class);
- assertEquals( "serialize", "", codec.serialize( null ) );
- assertEquals( "serialize", "true", codec.serialize( true ) );
- assertEquals( "serialize", "false", codec.serialize( false ) );
+ assertEquals("serialize", "", codec.serialize(null));
+ assertEquals("serialize", "true", codec.serialize(true));
+ assertEquals("serialize", "false", codec.serialize(false));
}
@SuppressWarnings("unchecked")
@Test
public void testDeserialize() {
- BooleanCodec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec( BooleanType.getInstance(), BooleanCodec.class);
+ BooleanCodec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.booleanType(), BooleanCodec.class);
- assertEquals( "deserialize", Boolean.TRUE, codec.deserialize( "true" ) );
- assertEquals( "deserialize", Boolean.TRUE, codec.deserialize( "TRUE" ) );
- assertEquals( "deserialize", Boolean.FALSE, codec.deserialize( "FALSE" ) );
- assertEquals( "deserialize", Boolean.FALSE, codec.deserialize( "false" ) );
- assertEquals( "deserialize", null, codec.deserialize( null ) );
+ assertEquals("deserialize", Boolean.TRUE, codec.deserialize("true"));
+ assertEquals("deserialize", Boolean.TRUE, codec.deserialize("TRUE"));
+ assertEquals("deserialize", Boolean.FALSE, codec.deserialize("FALSE"));
+ assertEquals("deserialize", Boolean.FALSE, codec.deserialize("false"));
+ assertEquals("deserialize", null, codec.deserialize(null));
TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "foo");
TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "");
}
package org.opendaylight.yangtools.yang.data.impl.codecs;
-import static org.junit.Assert.*;
-
+import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.opendaylight.yangtools.yang.data.api.codec.EmptyCodec;
-import org.opendaylight.yangtools.yang.model.util.EmptyType;
+import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
/**
* Unit tests for EmptyCodecString.
@SuppressWarnings("unchecked")
@Test
public void testSerialize() {
- EmptyCodec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec( EmptyType.getInstance(), EmptyCodec.class);
+ EmptyCodec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.emptyType(), EmptyCodec.class);
- assertEquals( "serialize", "", codec.serialize( null ) );
+ assertEquals("serialize", "", codec.serialize(null));
}
@SuppressWarnings("unchecked")
@Test
public void testDeserialize() {
- EmptyCodec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec( EmptyType.getInstance(), EmptyCodec.class);
+ EmptyCodec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.emptyType(), EmptyCodec.class);
- assertEquals( "deserialize", null, codec.deserialize( "" ) );
- assertEquals( "deserialize", null, codec.deserialize( null ) );
+ assertEquals("deserialize", null, codec.deserialize(""));
+ assertEquals("deserialize", null, codec.deserialize(null));
- TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx( codec, "foo" );
+ TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "foo");
}
-
}
package org.opendaylight.yangtools.yang.data.impl.codecs;
-import static org.junit.Assert.*;
-
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.data.api.codec.EnumCodec;
-import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.getCodec;
+import static org.junit.Assert.assertEquals;
import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx;
+import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.getCodec;
import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.toEnumTypeDefinition;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.data.api.codec.EnumCodec;
/**
* Unit tests for EnumCodecString.
@SuppressWarnings("unchecked")
@Test
public void testSerialize() {
- EnumCodec<String> codec = getCodec( toEnumTypeDefinition( "enum1", "enum2" ), EnumCodec.class);
+ EnumCodec<String> codec = getCodec(toEnumTypeDefinition("enum1", "enum2"), EnumCodec.class);
- assertEquals( "serialize", "enum1", codec.serialize( "enum1" ) );
- assertEquals( "serialize", "", codec.serialize( null ) );
+ assertEquals("serialize", "enum1", codec.serialize("enum1"));
+ assertEquals("serialize", "", codec.serialize(null));
}
@SuppressWarnings("unchecked")
public void testDeserialize() {
EnumCodec<String> codec = getCodec( toEnumTypeDefinition( "enum1", "enum2" ), EnumCodec.class);
- assertEquals( "deserialize", "enum1", codec.deserialize( "enum1" ) );
- assertEquals( "deserialize", "enum2", codec.deserialize( "enum2" ) );
+ assertEquals("deserialize", "enum1", codec.deserialize("enum1"));
+ assertEquals("deserialize", "enum2", codec.deserialize("enum2"));
- deserializeWithExpectedIllegalArgEx( codec, "enum3" );
+ deserializeWithExpectedIllegalArgEx(codec, "enum3");
}
}
package org.opendaylight.yangtools.yang.data.impl.codecs;
-import static org.junit.Assert.*;
-
+import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.opendaylight.yangtools.yang.data.api.codec.Int32Codec;
-import org.opendaylight.yangtools.yang.model.util.Int32;
+import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
/**
* Unit tests for Int32CodecString.
@SuppressWarnings("unchecked")
@Test
public void testSerialize() {
- Int32Codec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(Int32.getInstance(), Int32Codec.class);
+ Int32Codec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.int32Type(), Int32Codec.class);
assertEquals("serialize", "10", codec.serialize(Integer.valueOf( 10 )));
assertEquals("serialize", "", codec.serialize(null));
final String integer = "1174404318";
final String negInteger = "-1174404318";
- Int32Codec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(Int32.getInstance(), Int32Codec.class);
+ Int32Codec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.int32Type(), Int32Codec.class);
assertEquals("deserialize", codec.deserialize(hexa), Integer.valueOf("+045FFFCDE", 16));
assertEquals("deserialize", codec.deserialize(negHexa), Integer.valueOf("-045FFFCDE", 16));
package org.opendaylight.yangtools.yang.data.impl.codecs;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx;
import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.getCodec;
-
import org.junit.Test;
import org.opendaylight.yangtools.yang.data.api.codec.Int64Codec;
-import org.opendaylight.yangtools.yang.model.util.Int64;
+import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
/**
* Unit tests for Int64CodecString.
@SuppressWarnings("unchecked")
@Test
public void testSerialize() {
- Int64Codec<String> codec = getCodec(Int64.getInstance(), Int64Codec.class);
+ Int64Codec<String> codec = getCodec(BaseTypes.int64Type(), Int64Codec.class);
assertEquals("serialize", "12345", codec.serialize(Long.valueOf( 12345 )));
assertEquals("serialize", "", codec.serialize(null));
final String integer = "+129664115727546";
final String negInteger = "-129664115727546";
- Int64Codec<String> codec = getCodec(Int64.getInstance(), Int64Codec.class);
+ Int64Codec<String> codec = getCodec(BaseTypes.int64Type(), Int64Codec.class);
assertEquals("deserialize", codec.deserialize(hexa), Long.valueOf("075EDC78edCBA", 16));
assertEquals("deserialize", codec.deserialize(negHexa), Long.valueOf("-075EDC78edCBA", 16));
package org.opendaylight.yangtools.yang.data.impl.codecs;
-import static org.junit.Assert.*;
-
+import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.opendaylight.yangtools.yang.data.api.codec.Int8Codec;
-import org.opendaylight.yangtools.yang.model.util.Int8;
+import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
/**
* Unit tests for Int8CodecString.
@SuppressWarnings("unchecked")
@Test
public void testSerialize() {
- Int8Codec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(Int8.getInstance(), Int8Codec.class);
+ Int8Codec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.int8Type(), Int8Codec.class);
assertEquals("serialize", "10", codec.serialize(Byte.valueOf( (byte) 10 )));
assertEquals("serialize", "", codec.serialize(null));
final String integer = "64";
final String negInteger = "-64";
- Int8Codec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(Int8.getInstance(), Int8Codec.class);
+ Int8Codec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.int8Type(), Int8Codec.class);
assertEquals("deserialize", codec.deserialize(hexa), Byte.valueOf("040", 16));
assertEquals("deserialize", codec.deserialize(negHexa), Byte.valueOf("-040", 16));
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-
-import java.util.List;
-
import org.opendaylight.yangtools.concepts.Codec;
import org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodec;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
-import org.opendaylight.yangtools.yang.model.util.BitsType;
-import org.opendaylight.yangtools.yang.model.util.EnumerationType;
-import org.opendaylight.yangtools.yang.model.util.UnionType;
-
-import com.google.common.base.Optional;
-import com.google.common.collect.Lists;
+import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
+import org.opendaylight.yangtools.yang.model.util.type.EnumerationTypeBuilder;
public class TypeDefinitionAwareCodecTestHelper {
@SuppressWarnings("unchecked")
- public static <T> T getCodec( TypeDefinition<?> def, Class<T> clazz ) {
- Object codec = TypeDefinitionAwareCodec.from( def );
- assertNotNull( codec );
- assertTrue( clazz.isAssignableFrom( codec.getClass() ) );
+ public static <T> T getCodec( final TypeDefinition<?> def, final Class<T> clazz) {
+ Object codec = TypeDefinitionAwareCodec.from(def);
+ assertNotNull(codec);
+ assertTrue(clazz.isAssignableFrom(codec.getClass()));
return (T)codec;
}
- public static void deserializeWithExpectedIllegalArgEx( Codec<String,?> codec, String param ) {
+ public static void deserializeWithExpectedIllegalArgEx(final Codec<String,?> codec, final String param) {
try {
- codec.deserialize( param );
- fail( "Expected IllegalArgumentException" );
+ codec.deserialize(param);
+ fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected ...
}
}
- public static EnumTypeDefinition toEnumTypeDefinition( String... enums ) {
- List<EnumTypeDefinition.EnumPair> enumList = Lists.newArrayList();
- for (String en: enums ) {
- EnumTypeDefinition.EnumPair mockEnum = mock( EnumTypeDefinition.EnumPair.class );
- when( mockEnum.getName() ).thenReturn( en );
- enumList.add( mockEnum );
- }
-
- return EnumerationType.create( mock( SchemaPath.class ), enumList,
- Optional.absent() );
- }
-
- public static UnionTypeDefinition toUnionTypeDefinition( TypeDefinition<?>... types ) {
- return UnionType.create( Lists.newArrayList( types ) );
- }
-
- public static BitsTypeDefinition toBitsTypeDefinition( String... bits ) {
- List<BitsTypeDefinition.Bit> bitList = Lists.newArrayList();
- for (String bit: bits ) {
- BitsTypeDefinition.Bit mockBit = mock( BitsTypeDefinition.Bit.class );
- when( mockBit.getName() ).thenReturn( bit );
- bitList.add( mockBit );
+ public static EnumTypeDefinition toEnumTypeDefinition(final String... enums) {
+ final EnumerationTypeBuilder b = BaseTypes.enumerationTypeBuilder(mock(SchemaPath.class));
+ int i = 0;
+ for (String en : enums) {
+ EnumTypeDefinition.EnumPair mockEnum = mock(EnumTypeDefinition.EnumPair.class);
+ when(mockEnum.getName()).thenReturn(en);
+ when(mockEnum.getValue()).thenReturn(i);
+ b.addEnum(mockEnum);
+ i++;
}
- return BitsType.create( mock( SchemaPath.class ), bitList );
+ return b.build();
}
}
package org.opendaylight.yangtools.yang.data.impl.codecs;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx;
import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.getCodec;
-
import org.junit.Test;
import org.opendaylight.yangtools.yang.data.api.codec.Uint32Codec;
-import org.opendaylight.yangtools.yang.model.util.Uint32;
+import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
/**
* Unit tests for Uint32CodecString.
@SuppressWarnings("unchecked")
@Test
public void testSerialize() {
- Uint32Codec<String> codec = getCodec(Uint32.getInstance(), Uint32Codec.class);
+ Uint32Codec<String> codec = getCodec(BaseTypes.uint32Type(), Uint32Codec.class);
assertEquals("serialize", "10", codec.serialize(Long.valueOf( 10 )));
assertEquals("serialize", "", codec.serialize(null));
final String octal = "010577776336";
final String integer = "1174404318";
- Uint32Codec<String> codec = getCodec(Uint32.getInstance(), Uint32Codec.class);
+ Uint32Codec<String> codec = getCodec(BaseTypes.uint32Type(), Uint32Codec.class);
assertEquals("deserialize", codec.deserialize(hexa), Long.valueOf("45FFFCDE", 16));
assertEquals("deserialize", codec.deserialize(octal), Long.valueOf(octal, 8));
assertEquals("deserialize", codec.deserialize(integer), Long.valueOf(integer, 10));
package org.opendaylight.yangtools.yang.data.impl.codecs;
-import static org.junit.Assert.*;
-
+import static org.junit.Assert.assertEquals;
import java.math.BigInteger;
-
import org.junit.Test;
import org.opendaylight.yangtools.yang.data.api.codec.Uint64Codec;
-import org.opendaylight.yangtools.yang.model.util.Uint64;
+import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
/**
* Unit tests for Uint64CodecString.
@SuppressWarnings("unchecked")
@Test
public void testSerialize() {
- Uint64Codec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(Uint64.getInstance(), Uint64Codec.class);
+ Uint64Codec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.uint64Type(), Uint64Codec.class);
assertEquals("serialize", "123456789", codec.serialize(BigInteger.valueOf( 123456789 )));
assertEquals("serialize", "", codec.serialize(null));
final String octal = "03536670743556272";
final String integer = "129664115727546";
- Uint64Codec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(Uint64.getInstance(), Uint64Codec.class);
+ Uint64Codec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.uint64Type(), Uint64Codec.class);
assertEquals("deserialize", codec.deserialize(hexa), new BigInteger("75EDC78edCBA", 16));
assertEquals("deserialize", codec.deserialize(octal), new BigInteger(octal, 8));
package org.opendaylight.yangtools.yang.data.impl.codecs;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx;
import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.getCodec;
-
import org.junit.Test;
import org.opendaylight.yangtools.yang.data.api.codec.Uint8Codec;
-import org.opendaylight.yangtools.yang.model.util.Uint8;
+import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
/**
* Unit tests for Uint8CodecString.
@SuppressWarnings({ "unchecked" })
@Test
public void testSerialize() {
- Uint8Codec<String> codec = getCodec(Uint8.getInstance(), Uint8Codec.class);
+ Uint8Codec<String> codec = getCodec(BaseTypes.uint8Type(), Uint8Codec.class);
assertEquals("serialize", "10", codec.serialize(Short.valueOf((short) 10 )));
assertEquals("serialize", "", codec.serialize(null));
final String octal = "0100";
final String integer = "64";
- Uint8Codec<String> codec = getCodec(Uint8.getInstance(), Uint8Codec.class);
+ Uint8Codec<String> codec = getCodec(BaseTypes.uint8Type(), Uint8Codec.class);
assertEquals("deserialize", codec.deserialize(hexa), Short.valueOf("040", 16));
assertEquals("deserialize", codec.deserialize(octal), Short.valueOf(octal, 8));
import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx;
import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.getCodec;
import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.toEnumTypeDefinition;
-import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.toUnionTypeDefinition;
-
+import java.util.Arrays;
import org.junit.Test;
import org.opendaylight.yangtools.yang.data.api.codec.UnionCodec;
-import org.opendaylight.yangtools.yang.model.util.EmptyType;
-import org.opendaylight.yangtools.yang.model.util.Int32;
-import org.opendaylight.yangtools.yang.model.util.Int64;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
+import org.opendaylight.yangtools.yang.model.util.UnionType;
+import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
/**
* Unit tests forUnionCodecString.
* @author Thomas Pantelis
*/
public class UnionCodecStringTest {
+ private static UnionTypeDefinition toUnionTypeDefinition(final TypeDefinition<?>... types) {
+ return UnionType.create(Arrays.asList(types));
+ }
@SuppressWarnings("unchecked")
@Test
public void testSerialize() {
- UnionCodec<String> codec =
- getCodec( toUnionTypeDefinition( toEnumTypeDefinition( "enum1", "enum2" ),
- toUnionTypeDefinition( Int32.getInstance(),
- Int64.getInstance() ),
- EmptyType.getInstance() ),
- UnionCodec.class);
+ UnionCodec<String> codec = getCodec(toUnionTypeDefinition(toEnumTypeDefinition("enum1", "enum2"),
+ toUnionTypeDefinition(BaseTypes.int32Type(),BaseTypes.int64Type()), BaseTypes.emptyType()),
+ UnionCodec.class);
- assertEquals( "serialize", "enum1", codec.serialize( "enum1" ) );
- assertEquals( "serialize", "123", codec.serialize( "123" ) );
- assertEquals( "serialize", "123", codec.serialize( 123 ) );
- assertEquals( "serialize", "", codec.serialize( null ) );
- assertEquals( "serialize", "", codec.serialize( "" ) );
+ assertEquals("serialize", "enum1", codec.serialize("enum1"));
+ assertEquals("serialize", "123", codec.serialize("123"));
+ assertEquals("serialize", "123", codec.serialize(123));
+ assertEquals("serialize", "", codec.serialize(null));
+ assertEquals("serialize", "", codec.serialize("" ));
}
@SuppressWarnings("unchecked")
@Test
public void testDeserialize() {
- UnionCodec<String> codec =
- getCodec( toUnionTypeDefinition( toEnumTypeDefinition( "enum1", "enum2" ),
- toUnionTypeDefinition( Int32.getInstance(),
- Int64.getInstance() ),
- EmptyType.getInstance() ),
- UnionCodec.class);
+ UnionCodec<String> codec = getCodec(toUnionTypeDefinition(toEnumTypeDefinition("enum1", "enum2"),
+ toUnionTypeDefinition(BaseTypes.int32Type(),BaseTypes.int64Type()), BaseTypes.emptyType()),
+ UnionCodec.class);
- assertEquals( "deserialize", "enum1", codec.deserialize( "enum1" ) );
- assertEquals( "deserialize", "123", codec.deserialize( "123" ) );
- assertEquals( "deserialize", "-123", codec.deserialize( "-123" ) );
- assertEquals( "deserialize", "41234567890", codec.deserialize( "41234567890" ) );
- assertEquals( "deserialize", "", codec.deserialize( "" ) );
- assertEquals( "deserialize", null, codec.deserialize( null ) );
+ assertEquals("deserialize", "enum1", codec.deserialize("enum1"));
+ assertEquals("deserialize", "123", codec.deserialize("123"));
+ assertEquals("deserialize", "-123", codec.deserialize("-123"));
+ assertEquals("deserialize", "41234567890", codec.deserialize("41234567890"));
+ assertEquals("deserialize", "", codec.deserialize(""));
+ assertEquals("deserialize", null, codec.deserialize(null));
- deserializeWithExpectedIllegalArgEx( codec, "enum3" );
- deserializeWithExpectedIllegalArgEx( codec, "123o" );
- deserializeWithExpectedIllegalArgEx( codec, "true" );
+ deserializeWithExpectedIllegalArgEx(codec, "enum3");
+ deserializeWithExpectedIllegalArgEx(codec, "123o");
+ deserializeWithExpectedIllegalArgEx(codec, "true");
}
}
* 9223372036854775807, inclusively.</li>
* </ul>
*
- * @deprecated Used only by deprecated {@link Int8} and friends.
+ * @deprecated Used only by deprecated {@link Int16}.
*/
@Deprecated
abstract class AbstractSignedInteger implements IntegerTypeDefinition {
* inclusively.</li>
* </ul>
*
- * @deprecated Used only by deprecated {@link Uint8} and friends.
+ * @deprecated Used only by deprecated {@link Uint16}.
*/
@Deprecated
abstract class AbstractUnsignedInteger implements UnsignedIntegerTypeDefinition {
*/
package org.opendaylight.yangtools.yang.model.util;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet;
import java.net.URI;
public static boolean isYangBuildInType(final TypeDefinition<?> type) {
return type != null && BUILT_IN_TYPES.contains(type.getQName());
}
-
- /**
- * Returns default instance of built-in for supplied type
- *
- * See package documentation for description of base build-in types
- * with default instance.
- *
- * @param typeName
- * @return Returns default instance or {@link Optional#absent()} if default
- * instance does not exists
- *
- * @deprecated Use parser-specific lookup tables.
- */
- @Deprecated
- public static Optional<TypeDefinition<?>> defaultBaseTypeFor(final String typeName) {
- return Optional.fromNullable(defaultBaseTypeForImpl(typeName));
- }
-
- @Deprecated
- private static TypeDefinition<?> defaultBaseTypeForImpl(final String typeName) {
- Preconditions.checkNotNull(typeName, "typeName must not be null.");
-
- if (typeName.startsWith("int")) {
- if ("int8".equals(typeName)) {
- return Int8.getInstance();
- } else if ("int16".equals(typeName)) {
- return Int16.getInstance();
- } else if ("int32".equals(typeName)) {
- return Int32.getInstance();
- } else if ("int64".equals(typeName)) {
- return Int64.getInstance();
- }
- } else if (typeName.startsWith("uint")) {
- if ("uint8".equals(typeName)) {
- return Uint8.getInstance();
- } else if ("uint16".equals(typeName)) {
- return Uint16.getInstance();
- } else if ("uint32".equals(typeName)) {
- return Uint32.getInstance();
- } else if ("uint64".equals(typeName)) {
- return Uint64.getInstance();
- }
- } else if ("string".equals(typeName)) {
- return StringType.getInstance();
- } else if ("binary".equals(typeName)) {
- return BinaryType.getInstance();
- } else if ("boolean".equals(typeName)) {
- return BooleanType.getInstance();
- } else if ("empty".equals(typeName)) {
- return EmptyType.getInstance();
- } else if ("instance-identifier".equals(typeName)) {
- return InstanceIdentifierType.getInstance();
- }
- return null;
- }
-
}
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. 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;
-
-import com.google.common.base.Optional;
-import java.util.Collections;
-import java.util.List;
-import java.util.Objects;
-import org.opendaylight.yangtools.yang.common.QName;
-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;
-
-/**
- * The <code>default</code> implementation of Binary Type Definition interface.
- *
- * @see BinaryTypeDefinition
- * @deprecated Use {@link org.opendaylight.yangtools.yang.model.util.type.BaseTypes#binaryType()} instead
- */
-@Deprecated
-public final class BinaryType implements BinaryTypeDefinition {
- private static final String DESCRIPTION = "The binary built-in type represents any binary data, i.e., a sequence of octets.";
- private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.8";
- private static final String UNITS = "";
-
- private static final QName QNAME = BaseTypes.BINARY_QNAME;
-
- private static final BinaryType INSTANCE = new BinaryType();
-
- private static final SchemaPath PATH = SchemaPath.create(Collections.singletonList(QNAME), true);
- private final List<Byte> bytes = Collections.emptyList();
- private final List<LengthConstraint> lengthConstraints;
-
- private BinaryType() {
- this.lengthConstraints = Collections.singletonList(
- BaseConstraints.newLengthConstraint(0, Long.MAX_VALUE, Optional.of(""), Optional.of("")));
- }
-
- public static BinaryType getInstance() {
- return INSTANCE;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
- */
- @Override
- public BinaryTypeDefinition getBaseType() {
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
- */
- @Override
- public String getUnits() {
- return UNITS;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
- * ()
- */
- @Override
- public Object getDefaultValue() {
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
- */
- @Override
- public QName getQName() {
- return QNAME;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
- */
- @Override
- public SchemaPath getPath() {
- return PATH;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
- */
- @Override
- public String getDescription() {
- return DESCRIPTION;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
- */
- @Override
- public String getReference() {
- return REFERENCE;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
- */
- @Override
- public Status getStatus() {
- return Status.CURRENT;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.opendaylight.yangtools.yang.model.base.type.api.BinaryTypeDefinition
- * #getLengthConstraint ()
- */
- @Override
- public List<LengthConstraint> getLengthConstraints() {
- return lengthConstraints;
- }
-
- @Override
- public List<UnknownSchemaNode> getUnknownSchemaNodes() {
- return Collections.emptyList();
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + Objects.hashCode(bytes);
- result = prime * result + Objects.hashCode(lengthConstraints);
- result = prime * result + QNAME.hashCode();
- result = prime * result + PATH.hashCode();
- return result;
- }
-
- @Override
- public boolean equals(final Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- BinaryType other = (BinaryType) obj;
- return Objects.equals(bytes, other.bytes) && Objects.equals(lengthConstraints, other.lengthConstraints);
- }
-
- @Override
- public String toString() {
- return "BinaryType [name=" +
- QNAME +
- ", description=" +
- DESCRIPTION +
- ", reference=" +
- REFERENCE +
- ", bytes=" +
- bytes +
- ", lengthConstraints=" +
- lengthConstraints +
- ", units=" +
- UNITS +
- "]";
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. 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;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Objects;
-import org.opendaylight.yangtools.yang.common.QName;
-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.BitsTypeDefinition;
-
-/**
- * The <code>default</code> implementation of Bits Type Definition interface.
- *
- * @see BitsTypeDefinition
- * @deprecated Use {@link org.opendaylight.yangtools.yang.model.util.type.BaseTypes#bitsTypeBuilder(SchemaPath)} instead
- */
-@Deprecated
-public final class BitsType implements BitsTypeDefinition {
- private static final QName NAME = BaseTypes.BITS_QNAME;
- private static final String DESCRIPTION = "The bits built-in type represents a bit set. "
- + "That is, a bits value is a set of flags identified by small integer position "
- + "numbers starting at 0. Each bit number has an assigned name.";
-
- private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.7";
- private static final String UNITS = "";
- private final SchemaPath path;
- private final List<Bit> bits;
-
- /**
- * Constructor with explicit definition of bits assigned to BitsType.
- *
- * @param path
- * @param bits
- */
- private BitsType(final SchemaPath path, final List<Bit> bits) {
- super();
- this.bits = ImmutableList.copyOf(bits);
- this.path = Preconditions.checkNotNull(path, "path must not be null");
- }
-
- public static BitsType create(final SchemaPath path, final List<Bit> bits) {
- return new BitsType(path,bits);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
- */
- @Override
- public BitsTypeDefinition getBaseType() {
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
- */
- @Override
- public String getUnits() {
- return UNITS;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
- * ()
- */
- @Override
- public Object getDefaultValue() {
- // FIXME: Return real bits.
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
- */
- @Override
- public QName getQName() {
- return NAME;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
- */
- @Override
- public SchemaPath getPath() {
- return path;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
- */
- @Override
- public String getDescription() {
- return DESCRIPTION;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
- */
- @Override
- public String getReference() {
- return REFERENCE;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
- */
- @Override
- public Status getStatus() {
- return Status.CURRENT;
- }
-
- @Override
- public List<UnknownSchemaNode> getUnknownSchemaNodes() {
- return Collections.emptyList();
- }
-
- @Override
- public List<Bit> getBits() {
- return bits;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + Objects.hashCode(bits);
- result = prime * result + NAME.hashCode();
- result = prime * result + path.hashCode();
- return result;
- }
-
- @Override
- public boolean equals(final Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- BitsType other = (BitsType) obj;
- return Objects.equals(bits, other.bits) && Objects.equals(path, other.path);
- }
-
- @Override
- public String toString() {
- return "BitsType [name=" +
- NAME +
- ", path=" +
- path +
- ", description=" +
- DESCRIPTION +
- ", reference=" +
- REFERENCE +
- ", bits=" +
- bits +
- ", units=" +
- UNITS +
- "]";
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. 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;
-
-import java.util.Collections;
-import java.util.List;
-import org.opendaylight.yangtools.yang.common.QName;
-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.BooleanTypeDefinition;
-
-/**
- * The <code>default</code> implementation of Boolean Type Definition interface.
- *
- * @see BooleanTypeDefinition
- * @deprecated Use {@link org.opendaylight.yangtools.yang.model.util.type.BaseTypes#booleanType()} instead
- */
-@Deprecated
-public final class BooleanType implements BooleanTypeDefinition {
- private static final BooleanType INSTANCE = new BooleanType();
- private static final SchemaPath PATH = SchemaPath.create(true, BaseTypes.BOOLEAN_QNAME);
- private static final String DESCRIPTION = "The boolean built-in type represents a boolean value.";
- private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.5";
- private static final String UNITS = "";
-
- /**
- * Default constructor with default value set to "false".
- */
- private BooleanType() {
- }
-
- /**
- * Returns default instance of boolean built-in type.
- * @return default instance of boolean built-in type.
- */
- public static BooleanType getInstance() {
- return INSTANCE;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
- */
- @Override
- public BooleanTypeDefinition getBaseType() {
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
- */
- @Override
- public String getUnits() {
- return UNITS;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
- * ()
- */
- @Override
- public Object getDefaultValue() {
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
- */
- @Override
- public QName getQName() {
- return BaseTypes.BOOLEAN_QNAME;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
- */
- @Override
- public SchemaPath getPath() {
- return PATH;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
- */
- @Override
- public String getDescription() {
- return DESCRIPTION;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
- */
- @Override
- public String getReference() {
- return REFERENCE;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
- */
- @Override
- public Status getStatus() {
- return Status.CURRENT;
- }
-
- @Override
- public List<UnknownSchemaNode> getUnknownSchemaNodes() {
- return Collections.emptyList();
- }
-
- @Override
- public String toString() {
- return "BooleanType [name=" +
- BaseTypes.BOOLEAN_QNAME +
- ", path=" +
- PATH +
- "]";
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. 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;
-
-import java.util.Collections;
-import java.util.List;
-import org.opendaylight.yangtools.concepts.Immutable;
-import org.opendaylight.yangtools.yang.common.QName;
-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.EmptyTypeDefinition;
-
-/**
- * @deprecated Use {@link org.opendaylight.yangtools.yang.model.util.type.BaseTypes#emptyType()} instead
- */
-@Deprecated
-public final class EmptyType implements EmptyTypeDefinition, Immutable {
- private static final EmptyType INSTANCE = new EmptyType();
- private static final QName NAME = BaseTypes.EMPTY_QNAME;
- private static final SchemaPath PATH = SchemaPath.create(Collections.singletonList(NAME), true);
- private static final String DESCRIPTION = "The empty built-in type represents a leaf that does not have any value, it conveys information by its presence or absence.";
- private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#page-131";
-
- private EmptyType() {
- }
-
- public static EmptyType getInstance() {
- return INSTANCE;
- }
-
- @Override
- public EmptyTypeDefinition getBaseType() {
- return null;
- }
-
- @Override
- public String getUnits() {
- return null;
- }
-
- @Override
- public Object getDefaultValue() {
- return null;
- }
-
- @Override
- public QName getQName() {
- return NAME;
- }
-
- @Override
- public SchemaPath getPath() {
- return PATH;
- }
-
- @Override
- public String getDescription() {
- return DESCRIPTION;
- }
-
- @Override
- public String getReference() {
- return REFERENCE;
- }
-
- @Override
- public Status getStatus() {
- return Status.CURRENT;
- }
-
- @Override
- public List<UnknownSchemaNode> getUnknownSchemaNodes() {
- return Collections.emptyList();
- }
-
- @Override
- public String toString() {
- return "type empty " + NAME;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. 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;
-
-import com.google.common.base.Preconditions;
-import java.util.Collections;
-import java.util.List;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
-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.IdentityrefTypeDefinition;
-
-/**
- * The <code>default</code> implementation of Identityref Type Definition
- * interface.
- *
- * @see IdentityrefTypeDefinition
- * @deprecated Use {@link org.opendaylight.yangtools.yang.model.util.type.BaseTypes#identityrefTypeBuilder(SchemaPath)} instead
- */
-@Deprecated
-public final class IdentityrefType implements IdentityrefTypeDefinition {
- private static final QName NAME = BaseTypes.IDENTITYREF_QNAME;
- private static final String DESCRIPTION = "The identityref type is used to reference an existing identity.";
- private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.10";
- private static final String UNITS = "";
-
- private final IdentitySchemaNode identity;
- private final SchemaPath path;
-
- private IdentityrefType(final SchemaPath path, final IdentitySchemaNode baseIdentity) {
- this.path = Preconditions.checkNotNull(path, "Path must be specified");
- this.identity = Preconditions.checkNotNull(baseIdentity,"baseIdentity must be specified.");
- }
-
- /**
- * Constructs a new {@link IdentityrefTypeDefinition} definition.
- *
- * @param path Path to the definition.
- * @param baseIdentity Base Identity, all derived identities are valid arguments for instance of this type.
- * @return New identityref definition.
- */
- public static IdentityrefType create(final SchemaPath path, final IdentitySchemaNode baseIdentity) {
- return new IdentityrefType(path, baseIdentity);
- }
-
- @Override
- public String getUnits() {
- return UNITS;
- }
-
- @Override
- public Object getDefaultValue() {
- return null;
- }
-
- @Override
- public QName getQName() {
- return NAME;
- }
-
- @Override
- public SchemaPath getPath() {
- return path;
- }
-
- @Override
- public String getDescription() {
- return DESCRIPTION;
- }
-
- @Override
- public String getReference() {
- return REFERENCE;
- }
-
- @Override
- public Status getStatus() {
- return Status.CURRENT;
- }
-
- @Override
- public List<UnknownSchemaNode> getUnknownSchemaNodes() {
- return Collections.emptyList();
- }
-
- @Override
- public IdentitySchemaNode getIdentity() {
- return identity;
- }
-
- @Override
- public IdentityrefTypeDefinition getBaseType() {
- return null;
- }
-
- @Override
- public String toString() {
- return "identityref " + identity.getQName().getLocalName();
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. 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;
-
-import java.util.Collections;
-import java.util.List;
-import org.opendaylight.yangtools.concepts.Immutable;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
-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.InstanceIdentifierTypeDefinition;
-
-/**
- * The <code>default</code> implementation of Instance Identifier Type
- * Definition interface.
- *
- * Instance Identifier has only two possible variants - one with
- * {@link #requireInstance()} which returns true, other one
- * returns false.
- *
- * @see InstanceIdentifierTypeDefinition
- * @deprecated Use {@link org.opendaylight.yangtools.yang.model.util.type.BaseTypes#instanceIdentifierType()} instead
- */
-@Deprecated
-public final class InstanceIdentifierType implements InstanceIdentifierTypeDefinition, Immutable {
-
- private static final QName NAME = BaseTypes.INSTANCE_IDENTIFIER_QNAME;
- private static final SchemaPath PATH = SchemaPath.create(true, NAME);
- private static final String DESCRIPTION = "The instance-identifier built-in type is used to "
- + "uniquely identify a particular instance node in the data tree.";
- private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.13";
- private static final String UNITS = "";
-
- private static final InstanceIdentifierType INSTANCE_WITH_REQUIRED_TRUE = new InstanceIdentifierType(true);
- private static final InstanceIdentifierType INSTANCE_WITH_REQUIRED_FALSE = new InstanceIdentifierType(false);
-
- private final Boolean requireInstance;
-
- private InstanceIdentifierType(final boolean requiredInstance) {
- this.requireInstance = requiredInstance;
- }
-
- public static InstanceIdentifierType getInstance() {
- return INSTANCE_WITH_REQUIRED_TRUE;
- }
-
- public static InstanceIdentifierType create(final boolean requireInstance) {
- return requireInstance ? INSTANCE_WITH_REQUIRED_TRUE : INSTANCE_WITH_REQUIRED_FALSE;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
- */
- @Override
- public InstanceIdentifierTypeDefinition getBaseType() {
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
- */
- @Override
- public String getUnits() {
- return UNITS;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue()
- */
- @Override
- public Object getDefaultValue() {
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
- */
- @Override
- public QName getQName() {
- return NAME;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
- */
- @Override
- public SchemaPath getPath() {
- return PATH;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
- */
- @Override
- public String getDescription() {
- return DESCRIPTION;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
- */
- @Override
- public String getReference() {
- return REFERENCE;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
- */
- @Override
- public Status getStatus() {
- return Status.CURRENT;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.opendaylight.yangtools.yang.model.api.SchemaNode#getExtensionSchemaNodes()
- */
- @Override
- public List<UnknownSchemaNode> getUnknownSchemaNodes() {
- return Collections.emptyList();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.opendaylight.yangtools.yang.model.api.type.
- * InstanceIdentifierTypeDefinition# getPathStatement()
- */
- @Override
- @Deprecated
- public RevisionAwareXPath getPathStatement() {
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.opendaylight.yangtools.yang.model.api.type.
- * InstanceIdentifierTypeDefinition# requireInstance()
- */
- @Override
- public boolean requireInstance() {
- return requireInstance;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + requireInstance.hashCode();
- return result;
- }
-
- @Override
- public boolean equals(final Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- InstanceIdentifierType other = (InstanceIdentifierType) obj;
- return requireInstance.equals(other.requireInstance);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. 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;
-
-import org.opendaylight.yangtools.concepts.Immutable;
-
-/**
- * Implementation of Yang int32 built-in type. <br>
- * int32 represents integer values between -2147483648 and 2147483647,
- * inclusively. The Java counterpart of Yang int32 built-in type is
- * {@link Integer}.
- *
- * @see AbstractSignedInteger
- * @deprecated Use {@link org.opendaylight.yangtools.yang.model.util.type.BaseTypes#int32Type()} instead
- */
-@Deprecated
-public final class Int32 extends AbstractSignedInteger implements Immutable {
- private static final String DESCRIPTION = "int32 represents integer values between -2147483648 and 2147483647, inclusively.";
-
-
- private static final Int32 INSTANCE = new Int32();
-
- private Int32() {
- super(BaseTypes.INT32_QNAME, Int32.DESCRIPTION, Integer.MIN_VALUE, Integer.MAX_VALUE, "");
- }
-
- /**
- * Returns default instance of int32 type.
- * @return default instance of int32 type.
- */
- public static Int32 getInstance() {
- return INSTANCE;
- }
-
- @Override
- public Object getDefaultValue() {
- return null;
- }
-
- @Override
- public String toString() {
- return "type " + BaseTypes.INT32_QNAME;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. 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;
-
-import org.opendaylight.yangtools.concepts.Immutable;
-
-/**
- * Implementation of Yang int64 built-in type. <br>
- * int64 represents integer values between -9223372036854775808 and
- * 9223372036854775807, inclusively. The Java counterpart of Yang int64 built-in
- * type is {@link Long}.
- *
- * @deprecated Use {@link org.opendaylight.yangtools.yang.model.util.type.BaseTypes#int64Type()} instead
- */
-@Deprecated
-public final class Int64 extends AbstractSignedInteger implements Immutable {
- private static final String DESCRIPTION = "int64 represents integer values between -9223372036854775808 and 9223372036854775807, inclusively.";
-
- private Int64() {
- super(BaseTypes.INT64_QNAME, DESCRIPTION, Long.MIN_VALUE, Long.MAX_VALUE, "");
- }
-
-
- private static final Int64 INSTANCE = new Int64();
-
- /**
- * Returns default instance of int64 type.
- * @return default instance of int64 type.
- */
- public static Int64 getInstance() {
- return INSTANCE;
- }
-
- @Override
- public Object getDefaultValue() {
- return null;
- }
-
- @Override
- public String toString() {
- return "type " + BaseTypes.INT64_QNAME;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. 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;
-
-import org.opendaylight.yangtools.concepts.Immutable;
-
-/**
- * Implementation of Yang int8 built-in type. <br>
- * int8 represents integer values between -128 and 127, inclusively. The Java
- * counterpart of Yang int8 built-in type is {@link Byte}.
- *
- * @see AbstractSignedInteger
- * @deprecated Use {@link org.opendaylight.yangtools.yang.model.util.type.BaseTypes#int8Type()} instead
- */
-@Deprecated
-public final class Int8 extends AbstractSignedInteger implements Immutable {
- private static final String DESCRIPTION = "represents integer values between -128 and 127, inclusively.";
-
- private Int8() {
- super(BaseTypes.INT8_QNAME, DESCRIPTION, Byte.MIN_VALUE, Byte.MAX_VALUE, "");
- }
-
- private static final Int8 INSTANCE = new Int8();
-
- /**
- * Returns default instance of int8 type.
- * @return default instance of int8 type.
- */
- public static Int8 getInstance() {
- return INSTANCE;
- }
-
- @Override
- public Object getDefaultValue() {
- return null;
- }
-
- @Override
- public String toString() {
- return "type " + BaseTypes.INT8_QNAME;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. 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;
-
-import com.google.common.base.Preconditions;
-import java.util.Collections;
-import java.util.List;
-import java.util.Objects;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
-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.LeafrefTypeDefinition;
-
-/**
- * The <code>default</code> implementation of Instance Leafref Type Definition
- * interface.
- *
- * @see LeafrefTypeDefinition
- * @deprecated Use {@link org.opendaylight.yangtools.yang.model.util.type.BaseTypes#leafrefTypeBuilder(SchemaPath)} instead
- */
-@Deprecated
-public final class Leafref implements LeafrefTypeDefinition {
- private static final QName NAME = BaseTypes.constructQName("leafref");
- private static final SchemaPath PATH = SchemaPath.create(true, NAME);
- private static final String DESCRIPTION = "The leafref type is used to reference a particular leaf instance in the data tree.";
- private static final String REF = "https://tools.ietf.org/html/rfc6020#section-9.9";
-
- private final RevisionAwareXPath xpath;
- private final SchemaPath path;
-
- @Deprecated
- public Leafref(final RevisionAwareXPath xpath) {
- this(PATH, xpath);
- }
-
- private Leafref(final SchemaPath path, final RevisionAwareXPath target) {
- this.path = Preconditions.checkNotNull(path,"path must be specified");
- this.xpath = Preconditions.checkNotNull(target,"target must not be null.");
- }
-
- public static Leafref create(final SchemaPath path, final RevisionAwareXPath target) {
- return new Leafref(path,target);
- }
-
- @Override
- public LeafrefTypeDefinition getBaseType() {
- return null;
- }
-
- @Override
- public String getUnits() {
- return "";
- }
-
- @Override
- public Object getDefaultValue() {
- return null;
- }
-
- @Override
- public QName getQName() {
- return NAME;
- }
-
- @Override
- public SchemaPath getPath() {
- return path;
- }
-
- @Override
- public String getDescription() {
- return DESCRIPTION;
- }
-
- @Override
- public String getReference() {
- return REF;
- }
-
- @Override
- public Status getStatus() {
- return Status.CURRENT;
- }
-
- @Override
- public List<UnknownSchemaNode> getUnknownSchemaNodes() {
- return Collections.emptyList();
- }
-
- @Override
- public RevisionAwareXPath getPathStatement() {
- return xpath;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + Objects.hashCode(xpath);
- return result;
- }
-
- @Override
- public boolean equals(final Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- Leafref other = (Leafref) obj;
- return Objects.equals(xpath, other.xpath);
- }
-
- @Override
- public String toString() {
- return "type " +
- NAME +
- " [xpath=" +
- xpath +
- "]";
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. 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;
-
-import org.opendaylight.yangtools.concepts.Immutable;
-
-/**
- * Implementation of Yang uint32 built-in type. <br>
- * uint32 represents integer values between 0 and 4294967295, inclusively.
- *
- * @deprecated Use {@link org.opendaylight.yangtools.yang.model.util.type.BaseTypes#uint32Type()} instead
- */
-@Deprecated
-public final class Uint32 extends AbstractUnsignedInteger implements Immutable {
- public static final long MAX_VALUE = 4294967295L;
- private static final String DESCRIPTION = "uint32 represents integer values between 0 and 4294967295, inclusively.";
-
- private static final Uint32 INSTANCE = new Uint32();
-
-
- private Uint32() {
- super(BaseTypes.UINT32_QNAME, DESCRIPTION, MAX_VALUE, "");
- }
-
- public static Uint32 getInstance() {
- return INSTANCE;
- }
-
- @Override
- public Object getDefaultValue() {
- return null;
- }
-
- @Override
- public String toString() {
- return "type " + BaseTypes.UINT32_QNAME;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. 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;
-
-import java.math.BigInteger;
-import org.opendaylight.yangtools.concepts.Immutable;
-
-/**
- * Implementation of Yang uint64 built-in type. <br>
- * uint64 represents integer values between 0 and 18446744073709551615,
- * inclusively. The Java counterpart of Yang uint64 built-in type is
- * {@link BigInteger}.
- *
- * @deprecated Use {@link org.opendaylight.yangtools.yang.model.util.type.BaseTypes#uint64Type()} instead
- */
-@Deprecated
-public final class Uint64 extends AbstractUnsignedInteger implements Immutable {
- public static final BigInteger MAX_VALUE = new BigInteger("18446744073709551615");
- private static final String DESCRIPTION = "uint64 represents integer values between 0 and 18446744073709551615, inclusively.";
-
- private static final Uint64 INSTANCE = new Uint64();
-
- private Uint64() {
- super(BaseTypes.UINT64_QNAME, DESCRIPTION, MAX_VALUE, "");
- }
-
- public static Uint64 getInstance() {
- return INSTANCE;
- }
-
- @Override
- public Object getDefaultValue() {
- return null;
- }
-
- @Override
- public String toString() {
- return "type " + BaseTypes.UINT64_QNAME;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. 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;
-
-import org.opendaylight.yangtools.concepts.Immutable;
-
-/**
- * Implementation of Yang uint8 built-in type. <br>
- * uint8 represents integer values between 0 and 255, inclusively.
- *
- * @see AbstractUnsignedInteger
- * @deprecated Use {@link org.opendaylight.yangtools.yang.model.util.type.BaseTypes#uint8Type()} instead
- */
-@Deprecated
-public final class Uint8 extends AbstractUnsignedInteger implements Immutable {
- public static final int MAX_VALUE = 255;
- private static final String DESCRIPTION = "uint8 represents integer values between 0 and 255, inclusively.";
-
- private static final Uint8 INSTANCE = new Uint8();
-
- private Uint8() {
- super(BaseTypes.UINT8_QNAME, DESCRIPTION, MAX_VALUE, "");
- }
-
- public static Uint8 getInstance() {
- return INSTANCE;
- }
-
- @Override
- public Object getDefaultValue() {
- return null;
- }
-
- @Override
- public String toString() {
- return "type " + BaseTypes.UINT8_QNAME;
- }
-
-}
*/
/**
* Utility classes and implementations for concepts defined in yang-model-api.
- *
- *
- * <h2>Base Types</h2>
- *
- * YANG specification defines several base types, for which YANG model does not
- * exists, but have same properties as derived types. This package provides
- * implementation of {@link org.opendaylight.yangtools.yang.model.api.TypeDefinition}
- * interface and it's subinterfaces which represent YANG base types and
- * types derived from them.
- * <p>
- * YANG Specification implicitly defines two types of base types - ones with default version,
- * and ones which needs to be derived.
- *
- * <h3>Base built-in types with default instance and semantics</h3>
- *
- * <dl>
- * <dt>empty</dt>
- * <dd>A leaf that does not have any value - {@link org.opendaylight.yangtools.yang.model.util.EmptyType}</dd>
- * <dt>binary</dt>
- * <dd>Any binary data - {@link org.opendaylight.yangtools.yang.model.util.BinaryType}
- * <dt>boolean</dt>
- * <dd>"true" or "false" - {@link org.opendaylight.yangtools.yang.model.util.BinaryType}</dd>
- * <dt>int8</dt>
- * <dd>8-bit signed integer - {@link org.opendaylight.yangtools.yang.model.util.Int8}</dd>
- * <dt>int16</dt>
- * <dd>16-bit signed integer - {@link org.opendaylight.yangtools.yang.model.util.Int16}</dd>
- * <dt>int32</dt>
- * <dd>32-bit signed integer - {@link org.opendaylight.yangtools.yang.model.util.Int32}</dd>
- * <dt>int64</dt>
- * <dd>64-bit signed integer - {@link org.opendaylight.yangtools.yang.model.util.Int64}</dd>
- * <dt>uint8</dt>
- * <dd>8-bit unsigned integer -{@link org.opendaylight.yangtools.yang.model.util.Uint8}</dd>
- * <dt>uint16</dt>
- * <dd>16-bit unsigned integer - {@link org.opendaylight.yangtools.yang.model.util.Int16}</dd>
- * <dt>uint32</dt>
- * <dd>32-bit unsigned integer - {@link org.opendaylight.yangtools.yang.model.util.Int32}</dd>
- * <dt>uint64</dt>
- * <dd>64-bit unsigned integer -{@link org.opendaylight.yangtools.yang.model.util.Int64}</dd>
- * <dt>instance-identifier</dt>
- * <dd>References a data tree node - {@link org.opendaylight.yangtools.yang.model.util.InstanceIdentifierType}</dd>
- * <dt>string</dt>
- * <dd>{@link org.opendaylight.yangtools.yang.model.util.StringType}</dd>
- * </dl>
- *
- * Common trait of base types with default instance is, that there is no requirement
- * for user input in YANG schema to further modify this types.
- * <p>
- * The implementation classes for these base types contains static method <code>getInstance()</code>
- * which provides reusable {@link org.opendaylight.yangtools.concepts.Immutable} instance of type.
- *
- * <h3>Base built-in types without default instance</h3>
- *
- * <dl>
- * <dt>bits</dt>
- * <dd>A set of bits or flags - {@link org.opendaylight.yangtools.yang.model.util.BitsType}</dd>
- * <dt>decimal64</dt>
- * <dd>64-bit signed decimal number - {@link org.opendaylight.yangtools.yang.model.util.Decimal64}</dd>
- * <dt>enumeration</dt>
- * <dd>Enumerated strings - {@link org.opendaylight.yangtools.yang.model.util.EnumerationType}</dd>
- * <dt>union</dt>
- * <dd>Choice of member types - {@link org.opendaylight.yangtools.yang.model.util.UnionType}</dd>
- * <dt>identity-ref</dt>
- * <dd>A reference to an abstract identity - {@link org.opendaylight.yangtools.yang.model.util.IdentityrefType}</dd>
- * <dt>leafref</dt>
- * <dd>A reference to a leaf instance - {@link org.opendaylight.yangtools.yang.model.util.Leafref}</dd>
- * </dl>
- *
- * Common trait of these base types without default instance is, that they require
- * user input in YANG schema to create instance of this types, and may have infinity number of
- * possible permutations.
- * <p>
- * The implementations have static factory method <code>create(SchemaPath,...)</code>
- * which provides {@link org.opendaylight.yangtools.concepts.Immutable} instance of type.
- *
*/
package org.opendaylight.yangtools.yang.model.util;
\ No newline at end of file
*/
package org.opendaylight.yangtools.yang.model.util;
-import com.google.common.base.Optional;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
public class BaseTypesTest {
@Test
- public void canCreateBaseTypes() {
- Optional<?> int8 = BaseTypes.defaultBaseTypeFor("int8");
- assertEquals(Optional.of(Int8.getInstance()), int8);
-
- Optional<?> int16 = BaseTypes.defaultBaseTypeFor("int16");
- assertEquals(Optional.of(Int16.getInstance()), int16);
-
- Optional<?> int32 = BaseTypes.defaultBaseTypeFor("int32");
- assertEquals(Optional.of(Int32.getInstance()), int32);
-
- Optional<?> int64 = BaseTypes.defaultBaseTypeFor("int64");
- assertEquals(Optional.of(Int64.getInstance()), int64);
-
- Optional<?> int128 = BaseTypes.defaultBaseTypeFor("int128");
- assertEquals("wrong type", Optional.absent(), int128);
-
- Optional<?> uint8 = BaseTypes.defaultBaseTypeFor("uint8");
- assertEquals(Optional.of(Uint8.getInstance()), uint8);
-
- Optional<?> uint16 = BaseTypes.defaultBaseTypeFor("uint16");
- assertEquals(Optional.of(Uint16.getInstance()), uint16);
-
- Optional<?> uint32 = BaseTypes.defaultBaseTypeFor("uint32");
- assertEquals(Optional.of(Uint32.getInstance()), uint32);
-
- Optional<?> uint64 = BaseTypes.defaultBaseTypeFor("uint64");
- assertEquals(Optional.of(Uint64.getInstance()), uint64);
-
- Optional<?> uint128 = BaseTypes.defaultBaseTypeFor("uint128");
- assertEquals("wrong type", Optional.absent(), uint128);
-
- Optional<?> stringType = BaseTypes.defaultBaseTypeFor("string");
- assertEquals(Optional.of(StringType.getInstance()), stringType);
-
- Optional<?> binaryType = BaseTypes.defaultBaseTypeFor("binary");
- assertEquals(Optional.of(BinaryType.getInstance()), binaryType);
-
- Optional<?> booleanType = BaseTypes.defaultBaseTypeFor("boolean");
- assertEquals(Optional.of(BooleanType.getInstance()), booleanType);
-
- Optional<?> emptyType = BaseTypes.defaultBaseTypeFor("empty");
- assertEquals(Optional.of(EmptyType.getInstance()), emptyType);
-
- Optional<?> instance_identifier = BaseTypes.defaultBaseTypeFor("instance_identifier");
- assertEquals(Optional.absent(), instance_identifier);
-
- Optional<?> whatever = BaseTypes.defaultBaseTypeFor("whatever");
- assertEquals("wrong type", Optional.absent(), whatever);
-
+ public void testIsYangBuildInType() {
assertFalse("whatever is not build-in type", BaseTypes.isYangBuildInType("whatever"));
assertTrue("int8 is build-in type", BaseTypes.isYangBuildInType("int8"));
}
-}
\ No newline at end of file
+}
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-
+import static org.opendaylight.yangtools.yang.model.util.type.BaseTypes.binaryType;
import java.util.Collections;
-import java.util.List;
import org.junit.Test;
import org.opendaylight.yangtools.yang.model.api.Status;
-import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
+import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
public class BinaryTypeTest {
@Test
public void canCreateBinaryType() {
- BinaryType binType = BinaryType.getInstance();
- BinaryType binType1 = BinaryType.getInstance();
- String stringBinType = binType.toString();
-
-
- List<LengthConstraint> lengthConstraints = binType.getLengthConstraints();
- assertTrue(lengthConstraints.toString().contains("max=9223372036854775807"));
- assertTrue(lengthConstraints.toString().contains("min=0"));
+ BinaryTypeDefinition binType = binaryType();
+ BinaryTypeDefinition binType1 = binaryType();
+ assertEquals(0, binType.getLengthConstraints().size());
assertNull(binType.getDefaultValue());
assertEquals("CURRENT", Status.CURRENT, binType.getStatus());
assertEquals("Base type is null", null, binType.getBaseType());
assertEquals("getQName gives BINARY_QNAME", BaseTypes.BINARY_QNAME, binType.getQName());
- assertEquals("empty string", "", binType.getUnits());
+ assertNull("Units should be null", binType.getUnits());
assertEquals("getPath gives List of BINARY_QNAME",
Collections.singletonList(BaseTypes.BINARY_QNAME), binType.getPath().getPathFromRoot());
- assertTrue("BinType.toString should contain Description", stringBinType.contains(binType.getDescription()));
- assertTrue("BinType.toString should contain Reference", stringBinType.contains(binType.getReference()));
-
assertTrue("binType1 should equal to binType",
binType.equals(binType1) && binType1.equals(binType));
assertTrue("Hash code of binType and binType1 should be equal",
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
-
+import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.doReturn;
import java.util.Collections;
-import java.util.List;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
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;
+import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
public class BitsTypeTest {
@Test
public void canCreateBitsType(){
MockitoAnnotations.initMocks(this);
+ doReturn("test").when(bit).getName();
QName qName = QName.create("TestQName");
SchemaPath schemaPath = SchemaPath.create(Collections.singletonList(qName), true);
- List<BitsTypeDefinition.Bit> listBit = Collections.singletonList(bit);
- BitsType bitsType = BitsType.create(schemaPath, listBit);
- assertNotEquals("Description is not null", null, bitsType.getDescription());
- assertEquals("QName", BaseTypes.BITS_QNAME, bitsType.getQName());
- assertEquals("Should be empty string", "", bitsType.getUnits());
+ BitsTypeDefinition bitsType = BaseTypes.bitsTypeBuilder(schemaPath).addBit(bit).build();
+
+ assertNull("Description is not null", bitsType.getDescription());
+ assertEquals("QName", qName, bitsType.getQName());
+ assertNull("Should be null", bitsType.getUnits());
assertNotEquals("Description should not be null", null, bitsType.toString());
- assertNotEquals("Reference is not null", null, bitsType.getReference());
- assertEquals("BaseType should be null", null, bitsType.getBaseType());
- assertEquals("Default value should be null", null, bitsType.getDefaultValue());
+ assertNull("Reference is not null", bitsType.getReference());
+ assertNull("BaseType should be null", bitsType.getBaseType());
+ assertNull("Default value should be null", bitsType.getDefaultValue());
assertEquals("getPath should equal schemaPath", schemaPath, bitsType.getPath());
assertEquals("Status should be CURRENT", Status.CURRENT, bitsType.getStatus());
assertEquals("Should be empty list", Collections.EMPTY_LIST, bitsType.getUnknownSchemaNodes());
- assertEquals("Values should be [enumPair]", listBit, bitsType.getBits());
+ assertEquals("Values should be [enumPair]", Collections.singletonList(bit), bitsType.getBits());
assertEquals("Hash code of bitsType should be equal",
bitsType.hashCode(), bitsType.hashCode());
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.opendaylight.yangtools.yang.model.util.type.BaseTypes.booleanType;
import java.util.Collections;
import org.junit.Test;
import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
public class BooleanTypeTest {
@Test
public void canCreateBooleanType() {
- BooleanType boolType = BooleanType.getInstance();
+ BooleanTypeDefinition boolType = booleanType();
String stringBoolType = boolType.toString();
assertEquals("getPath gives List of BOOLEAN_QNAME",
assertEquals("getQName gives BOOLEAN_QNAME", BaseTypes.BOOLEAN_QNAME, boolType.getQName());
- assertEquals("The boolean built-in type represents a boolean value.", boolType.getDescription());
+ assertNull(boolType.getDescription());
String strPath = boolType.getPath().toString();
assertTrue("Should contain string of getPath", stringBoolType.contains(strPath));
- assertEquals("Should be empty string", "", boolType.getUnits());
+ assertNull("Should be null", boolType.getUnits());
assertEquals("Base type is null", null, boolType.getBaseType());
*/
package org.opendaylight.yangtools.yang.model.util;
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.model.api.Status;
-
-import java.util.Collections;
-
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.opendaylight.yangtools.yang.model.util.type.BaseTypes.emptyType;
+import java.util.Collections;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
public class EmptyTypeTest {
@Test
public void canCreateEmptyType() {
- EmptyType emptyType = EmptyType.getInstance();
+ EmptyTypeDefinition emptyType = emptyType();
assertEquals("QName", BaseTypes.EMPTY_QNAME, emptyType.getQName());
assertEquals("Path", Collections.singletonList(BaseTypes.EMPTY_QNAME),
assertEquals("BaseType", null, emptyType.getBaseType());
assertEquals("DefaultValue", null, emptyType.getDefaultValue());
assertEquals("Status", Status.CURRENT, emptyType.getStatus());
- assertTrue("Reference", emptyType.getReference().contains("rfc6020"));
+ assertNull("Reference", emptyType.getReference());
assertEquals("Units", null, emptyType.getUnits());
- assertNotEquals("Description is not null", null, emptyType.getDescription());
+ assertNull("Description is not null", emptyType.getDescription());
assertEquals("UnknownSchemaNodes", Collections.EMPTY_LIST, emptyType.getUnknownSchemaNodes());
assertTrue("toString", emptyType.toString().contains("empty"));
}
*/
package org.opendaylight.yangtools.yang.model.util;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import com.google.common.base.Optional;
+import java.util.Collections;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
-
-import java.util.Collections;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
+import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
public class ExtendedTypeTest {
@Test
String revision = "2014-08-26";
String localName = "testType";
QName testType = QName.create(namespace, revision, localName);
- Int32 int32 = Int32.getInstance();
+ IntegerTypeDefinition int32 = BaseTypes.int32Type();
String description = "This type is used for testing purpose";
Optional<String> desc = Optional.of(description);
String reference = "Test Reference";
*/
package org.opendaylight.yangtools.yang.model.util;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-
import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
+import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
public class Int8Test {
@Test
public void testInt8() {
- Int8 int8 = Int8.getInstance();
- Int8 int8Second = Int8.getInstance();
+ IntegerTypeDefinition int8 = BaseTypes.int8Type();
+ IntegerTypeDefinition int8Second = BaseTypes.int8Type();
assertTrue("The method 'getInstance()' has to return the same instance", int8 == int8Second);
assertTrue("The method 'getBaseType()' is returning incorrect value", int8.getBaseType() == null);
assertTrue("The method 'getDefaultType()' is returning incorrect value", int8.getDefaultValue() == null);
- assertEquals("The method 'toString()' is returning incorrect value",
- "type (urn:ietf:params:xml:ns:yang:1)int8", int8.toString());
-
}
-
}
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
+import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
public class LeafrefTest {
final RevisionAwareXPathImpl revision = new RevisionAwareXPathImpl("/test:Cont1/test:List1", false);
final RevisionAwareXPathImpl revision2 = new RevisionAwareXPathImpl("/test:Cont1/test:List2", false);
- final Leafref leafref = Leafref.create(schemaPath, revision);
- final Leafref leafref2 = Leafref.create(schemaPath, revision2);
- final Leafref leafref3 = Leafref.create(schemaPath, revision);
- final Leafref leafref4 = leafref;
+ final LeafrefTypeDefinition leafref = BaseTypes.leafrefTypeBuilder(schemaPath).setPathStatement(revision).build();
+ final LeafrefTypeDefinition leafref2 = BaseTypes.leafrefTypeBuilder(schemaPath).setPathStatement(revision2).build();
+ final LeafrefTypeDefinition leafref3 = BaseTypes.leafrefTypeBuilder(schemaPath).setPathStatement(revision).build();
+ final LeafrefTypeDefinition leafref4 = leafref;
assertNotNull("Object 'leafref' shouldn't be null.", leafref);
assertNull("Base type of 'leafref' should be null.", leafref.getBaseType());
- assertTrue("Units of 'leafref' should be empty.", leafref.getUnits().isEmpty());
+ assertNull("Units of 'leafref' should be empty.", leafref.getUnits());
assertNull("Leafref does not have a default value", leafref.getDefaultValue());
- assertEquals("QName of 'leafref' is value '(urn:ietf:params:xml:ns:yang:1)leafref'.",
- BaseTypes.constructQName("leafref"), leafref.getQName());
+ assertEquals(QName.create("List1"), leafref.getQName());
assertEquals("SchemaPath of 'leafref' is '/Cont1/List1'.", schemaPath, leafref.getPath());
- assertEquals("Description of 'leafref' is 'The leafref type is used to reference a particular leaf instance in the data tree.'",
- "The leafref type is used to reference a particular leaf instance in the data tree.", leafref.getDescription());
- assertEquals("Reference of 'leafref' is 'https://tools.ietf.org/html/rfc6020#section-9.9'.", "https://tools.ietf.org/html/rfc6020#section-9.9", leafref.getReference());
+ assertNull(leafref.getDescription());
+ assertNull(leafref.getReference());
assertEquals("Status of 'leafref' is current.", Status.CURRENT, leafref.getStatus());
assertTrue("Object 'leafref' shouldn't have any unknown schema nodes.", leafref.getUnknownSchemaNodes().isEmpty());
assertEquals("Revision aware XPath of 'leafref' should be '/test:Cont1/test:List1'.", revision, leafref.getPathStatement());
*/
package org.opendaylight.yangtools.yang.model.util;
+import static org.junit.Assert.assertEquals;
+import java.util.Collections;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
-
-import java.util.Collections;
-
-import static org.junit.Assert.assertEquals;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
public class SchemaContextUtilTest {
@Mock private SchemaContext mockSchemaContext;
assertEquals("Should be null. Module bookstore not found", null,
SchemaContextUtil.findDataSchemaNode(mockSchemaContext, mockModule, xPath));
- SchemaNode schemaNode = Int32.getInstance();
+ SchemaNode schemaNode = BaseTypes.int32Type();
RevisionAwareXPath xPathRelative = new RevisionAwareXPathImpl("../prefix", false);
assertEquals("Should be null, Module prefix not found", null,
SchemaContextUtil.findDataSchemaNodeForRelativeXPath(
*/
package org.opendaylight.yangtools.yang.model.util;
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.model.api.Status;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.ArrayList;
-
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
+import static org.opendaylight.yangtools.yang.model.util.type.BaseTypes.int32Type;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
public class UnionTypeTest {
@Test
public void canCreateUnion() {
List<TypeDefinition<?>> listTypes = new ArrayList<>();
- Int32 int32 = Int32.getInstance();
+ IntegerTypeDefinition int32 = int32Type();
listTypes.add(int32);
UnionType unionType = UnionType.create(listTypes);
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
-import org.opendaylight.yangtools.yang.model.util.Int32;
import org.opendaylight.yangtools.yang.model.util.RevisionAwareXPathImpl;
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
+import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.stmt.TestUtils;
assertEquals("Should be null. Module bookstore not found", null,
SchemaContextUtil.findDataSchemaNode(mockSchemaContext, mockModule, xPath));
- SchemaNode schemaNode = Int32.getInstance();
+ SchemaNode schemaNode = BaseTypes.int32Type();
RevisionAwareXPath xPathRelative = new RevisionAwareXPathImpl("../prefix", false);
assertEquals("Should be null, Module prefix not found", null,
SchemaContextUtil.findDataSchemaNodeForRelativeXPath(mockSchemaContext, mockModule, schemaNode,
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
-
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.util.Int32;
import org.opendaylight.yangtools.yang.model.util.RevisionAwareXPathImpl;
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
+import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
public class SchemaContextUtilTest {
@Mock
assertEquals("Should be null. Module bookstore not found", null,
SchemaContextUtil.findDataSchemaNode(mockSchemaContext, mockModule, xPath));
- SchemaNode schemaNode = Int32.getInstance();
+ SchemaNode schemaNode = BaseTypes.int32Type();
RevisionAwareXPath xPathRelative = new RevisionAwareXPathImpl("../prefix", false);
assertEquals("Should be null, Module prefix not found", null,
SchemaContextUtil.findDataSchemaNodeForRelativeXPath(mockSchemaContext, mockModule, schemaNode,