package org.opendaylight.yangtools.yang.data.api.codec;
import org.opendaylight.yangtools.concepts.Codec;
+import org.opendaylight.yangtools.yang.common.Empty;
-public interface EmptyCodec<T> extends Codec<T,Void> {
+public interface EmptyCodec<T> extends Codec<T, Empty> {
@Override
- T serialize(Void data);
+ T serialize(Empty data);
@Override
- Void deserialize(T data);
+ Empty deserialize(T data);
}
*/
package org.opendaylight.yangtools.yang.data.api.codec;
+import javax.annotation.Nonnull;
import org.opendaylight.yangtools.concepts.Codec;
public interface StringCodec<T> extends Codec<T,String> {
@Override
- T serialize(String data);
+ T serialize(@Nonnull String data);
@Override
- String deserialize(T data);
+ String deserialize(@Nonnull T data);
}
*/
package org.opendaylight.yangtools.yang.data.api.schema;
+import javax.annotation.Nonnull;
import javax.xml.transform.dom.DOMSource;
import org.opendaylight.yangtools.yang.data.api.AttributesContainer;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
* AN normalizedNode.
*/
public interface AnyXmlNode extends AttributesContainer, DataContainerChild<NodeIdentifier, DOMSource> {
-
- @Override
- NodeIdentifier getIdentifier();
-
/**
* Return value represented as a DOMSource. Returned source contains top level element
* that duplicates the anyxml node.
* @return anyxml node value represented as DOMSource.
*/
@Override
- DOMSource getValue();
+ @Nonnull DOMSource getValue();
}
package org.opendaylight.yangtools.yang.data.api.schema;
import java.util.Collection;
+import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
* This is sufficient to identify instance of augmentation, since RFC6020 states that <code>augment</code>
* that augment statement must not add multiple nodes from same namespace / module to the target node.
*
- * @return Identifier which uniquelly identifies augmentation in particular subtree.
+ * @return Identifier which uniquely identifies augmentation in particular subtree.
*/
@Override
- AugmentationIdentifier getIdentifier();
+ @Nonnull AugmentationIdentifier getIdentifier();
}
*/
package org.opendaylight.yangtools.yang.data.api.schema;
+import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
/**
*/
public interface DataContainerChild<K extends PathArgument,V> extends NormalizedNode<K, V> {
@Override
- K getIdentifier();
+ @Nonnull K getIdentifier();
}
package org.opendaylight.yangtools.yang.data.api.schema;
import java.util.Collection;
+import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
/**
* @return Iteration of all child nodes
*/
@Override
- Collection<DataContainerChild<? extends PathArgument, ?>> getValue();
+ @Nonnull Collection<DataContainerChild<? extends PathArgument, ?>> getValue();
}
*/
package org.opendaylight.yangtools.yang.data.api.schema;
+import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.data.api.AttributesContainer;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
* @return Returned value of this leaf node. Value SHOULD meet criteria defined by schema.
*/
@Override
- T getValue();
+ @Nonnull T getValue();
}
*/
package org.opendaylight.yangtools.yang.data.api.schema;
+import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.data.api.AttributesContainer;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
* @return {@link NodeWithValue} which identifies this leaf set entry.
*/
@Override
- NodeWithValue getIdentifier();
+ @Nonnull NodeWithValue getIdentifier();
}
*
* @param <T> Type of leaf node values.
*/
-public interface LeafSetNode<T> extends
- MixinNode, //
- DataContainerChild<NodeIdentifier, Collection<LeafSetEntryNode<T>>>, //
- NormalizedNodeContainer<NodeIdentifier, NodeWithValue,LeafSetEntryNode<T>> {
+public interface LeafSetNode<T> extends MixinNode, DataContainerChild<NodeIdentifier, Collection<LeafSetEntryNode<T>>>,
+ NormalizedNodeContainer<NodeIdentifier, NodeWithValue, LeafSetEntryNode<T>> {
}
*/
package org.opendaylight.yangtools.yang.data.api.schema;
+import javax.annotation.Nonnull;
import org.opendaylight.yangtools.concepts.Identifiable;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
* @return Node identifier, non-null.
*/
@Override
- K getIdentifier();
+ @Nonnull K getIdentifier();
/**
* Value of node.
*
* @return Value of the node, may be null.
*/
- V getValue();
+ @Nonnull V getValue();
}
*/
package org.opendaylight.yangtools.yang.data.api.schema;
+import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
/**
*
*/
@Override
- V getValue();
+ @Nonnull V getValue();
}
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
+import org.opendaylight.yangtools.yang.common.Empty;
-final class EmptyJSONCodec implements JSONCodec<Void> {
+final class EmptyJSONCodec implements JSONCodec<Empty> {
static final EmptyJSONCodec INSTANCE = new EmptyJSONCodec();
}
@Override
- public Class<Void> getDataType() {
- return Void.class;
+ public Class<Empty> getDataType() {
+ return Empty.class;
}
@Override
- public Void parseValue(final Object ctx, final String input) {
- return null;
+ public Empty parseValue(final Object ctx, final String input) {
+ return Empty.getInstance();
}
@Override
- public void writeValue(final JsonWriter ctx, final Void value) throws IOException {
+ public void writeValue(final JsonWriter ctx, final Empty value) throws IOException {
ctx.beginArray();
ctx.value((String) null);
ctx.endArray();
import java.util.Collections;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.Empty;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
final String inputJson = loadTextFile("/complexjson/type-empty.json");
final ContainerNode awaitedStructure = containerBuilder()
.withNodeIdentifier(new NodeIdentifier(CONT_1))
- .addChild(leafNode(EMPTY_LEAF, null))
+ .addChild(leafNode(EMPTY_LEAF, Empty.getInstance()))
.build();
verifyTransformationToNormalizedNode(inputJson, awaitedStructure);
import java.util.Iterator;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.Empty;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
final StringWriter writer = new StringWriter();
final ContainerNode emptyStructure = Builders.containerBuilder()
.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CONT_1))
- .addChild(ImmutableNodes.leafNode(EMPTY_LEAF, null)).build();
+ .addChild(ImmutableNodes.leafNode(EMPTY_LEAF, Empty.getInstance())).build();
final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, emptyStructure);
final JsonObject cont1 = resolveCont1(jsonOutput);
final JsonElement emptyObj = cont1.get("empty");
* 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.data.codec.xml;
+import static java.util.Objects.requireNonNull;
+
import javax.xml.namespace.NamespaceContext;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
+import org.opendaylight.yangtools.yang.common.Empty;
-final class EmptyXmlCodec implements XmlCodec<Void> {
+final class EmptyXmlCodec implements XmlCodec<Empty> {
static final EmptyXmlCodec INSTANCE = new EmptyXmlCodec();
}
@Override
- public Class<Void> getDataType() {
- return Void.class;
+ public Class<Empty> getDataType() {
+ return Empty.class;
}
@Override
- public Void parseValue(final NamespaceContext ctx, final String str) {
- return null;
+ public Empty parseValue(final NamespaceContext ctx, final String str) {
+ return Empty.getInstance();
}
@Override
- public void writeValue(final XMLStreamWriter ctx, final Void value) throws XMLStreamException {
+ public void writeValue(final XMLStreamWriter ctx, final Empty value) throws XMLStreamException {
+ requireNonNull(value);
ctx.writeCharacters("");
}
}
package org.opendaylight.yangtools.yang.data.impl.codec;
import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNull;
-import com.google.common.base.Strings;
import java.util.Optional;
+import org.opendaylight.yangtools.yang.common.Empty;
import org.opendaylight.yangtools.yang.data.api.codec.EmptyCodec;
import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
-final class EmptyStringCodec extends TypeDefinitionAwareCodec<Void, EmptyTypeDefinition> implements
+final class EmptyStringCodec extends TypeDefinitionAwareCodec<Empty, EmptyTypeDefinition> implements
EmptyCodec<String> {
static final EmptyStringCodec INSTANCE = new EmptyStringCodec();
private EmptyStringCodec() {
- super(Optional.empty(), Void.class);
+ super(Optional.empty(), Empty.class);
}
@Override
- public String serialize(final Void data) {
+ public String serialize(final Empty data) {
+ requireNonNull(data);
return "";
}
@Override
- public Void deserialize(final String stringRepresentation) {
- checkArgument(Strings.isNullOrEmpty(stringRepresentation), "The value must be empty");
- return null;
+ public Empty deserialize(final String stringRepresentation) {
+ checkArgument(stringRepresentation.isEmpty(), "The value must be empty");
+ return Empty.getInstance();
}
}
\ No newline at end of file
package org.opendaylight.yangtools.yang.data.impl.codec;
import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNull;
import com.google.common.annotations.Beta;
import com.google.common.collect.ImmutableRangeSet;
import com.google.common.collect.RangeSet;
import com.google.common.collect.TreeRangeSet;
import java.util.Collection;
-import java.util.Objects;
import java.util.Optional;
import org.opendaylight.yangtools.yang.data.api.codec.StringCodec;
import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
@Override
public final String deserialize(final String stringRepresentation) {
- if (stringRepresentation == null) {
- // FIXME: These seems buggy, but someone may be using this behaviour
- return "";
- }
- validate(stringRepresentation);
+ validate(requireNonNull(stringRepresentation));
return stringRepresentation;
}
@Override
public final String serialize(final String data) {
- return Objects.toString(data, "");
+ return requireNonNull(data);
}
void validate(final String str) {
*/
package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl;
+import static com.google.common.base.Preconditions.checkState;
+import static java.util.Objects.requireNonNull;
+
import java.util.Collections;
import java.util.Map;
import org.opendaylight.yangtools.yang.common.QName;
private V value;
protected final I getNodeIdentifier() {
+ checkState(nodeIdentifier != null, "Identifier has not been set");
return nodeIdentifier;
}
protected final V getValue() {
+ checkState(value != null, "Value has not been set");
return value;
}
}
@Override
- public NormalizedNodeAttrBuilder<I,V,R> withValue(final V value) {
- this.value = value;
+ public NormalizedNodeAttrBuilder<I, V, R> withValue(final V value) {
+ this.value = requireNonNull(value);
return this;
}
@Override
- public NormalizedNodeAttrBuilder<I,V,R> withNodeIdentifier(final I nodeIdentifier) {
- this.nodeIdentifier = nodeIdentifier;
+ public NormalizedNodeAttrBuilder<I, V, R> withNodeIdentifier(final I nodeIdentifier) {
+ this.nodeIdentifier = requireNonNull(nodeIdentifier);
return this;
}
@Override
- public NormalizedNodeAttrBuilder<I,V,R> withAttributes(final Map<QName, String> attributes) {
- this.attributes = attributes;
+ public NormalizedNodeAttrBuilder<I, V, R> withAttributes(final Map<QName, String> attributes) {
+ this.attributes = requireNonNull(attributes);
return this;
}
}
*/
package org.opendaylight.yangtools.yang.data.impl.schema.nodes;
-import javax.annotation.Nullable;
+import static java.util.Objects.requireNonNull;
+
+import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
public abstract class AbstractImmutableNormalizedValueNode<K extends PathArgument, V> extends
AbstractImmutableNormalizedNode<K, V> {
- private static final Logger LOG = LoggerFactory.getLogger(AbstractImmutableNormalizedValueNode.class);
- @Nullable
+ @Nonnull
private final V value;
- protected AbstractImmutableNormalizedValueNode(final K nodeIdentifier, @Nullable final V value) {
+ protected AbstractImmutableNormalizedValueNode(final K nodeIdentifier, @Nonnull final V value) {
super(nodeIdentifier);
-
- /*
- * Null value is allowed for empty type definition so it should be debug,
- * but still we are logging it in case we need to debug missing values.
- */
- // FIXME: one we do not map YANG 'void' to java.lang.Void we should be enforcing non-null here
- if (value == null) {
- LOG.debug("The value of node {} is null", nodeIdentifier.getNodeType());
- }
- this.value = value;
+ this.value = requireNonNull(value);
}
- @Nullable
@Override
public final V getValue() {
return wrapValue(value);
}
- @Nullable
+ @Nonnull
protected final V value() {
return value;
}
import static org.junit.Assert.assertEquals;
import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.Empty;
import org.opendaylight.yangtools.yang.data.api.codec.EmptyCodec;
import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
public void testSerialize() {
EmptyCodec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.emptyType(), EmptyCodec.class);
- assertEquals("serialize", "", codec.serialize(null));
+ assertEquals("serialize", "", codec.serialize(Empty.getInstance()));
}
@SuppressWarnings("unchecked")
public void testDeserialize() {
EmptyCodec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.emptyType(), EmptyCodec.class);
- assertEquals("deserialize", null, codec.deserialize(""));
- assertEquals("deserialize", null, codec.deserialize(null));
+ assertEquals("deserialize", Empty.getInstance(), codec.deserialize(""));
TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "foo");
}
assertEquals("serialize", "foo", codec.serialize("foo"));
assertEquals("serialize", "", codec.serialize(""));
- assertEquals("serialize", "", codec.serialize(null));
}
@SuppressWarnings("unchecked")
assertEquals("deserialize", "bar", codec.deserialize("bar"));
assertEquals("deserialize", "", codec.deserialize(""));
- assertEquals("deserialize", "", codec.deserialize(null));
}
}
import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.toEnumTypeDefinition;
import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.Empty;
import org.opendaylight.yangtools.yang.data.api.codec.UnionCodec;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
assertEquals("deserialize", 123, codec.deserialize("123"));
assertEquals("deserialize", -123, codec.deserialize("-123"));
assertEquals("deserialize", 41234567890L, codec.deserialize("41234567890"));
- assertEquals("deserialize", null, codec.deserialize(""));
- assertEquals("deserialize", null, codec.deserialize(null));
+ assertEquals("deserialize", Empty.getInstance(), codec.deserialize(""));
deserializeWithExpectedIllegalArgEx(codec, "enum3");
deserializeWithExpectedIllegalArgEx(codec, "123o");
@Test
public void testInAugment() throws Exception {
+ final LeafNode<?> leaf = Builders.leafBuilder().withNodeIdentifier(augmentedLeaf).withValue("").build();
final ContainerNode expectedFilter = Builders
.containerBuilder()
.withNodeIdentifier(rootContainer)
Builders.augmentationBuilder()
.withNodeIdentifier(augmentation)
.withChild(
- Builders.leafBuilder().withNodeIdentifier(augmentedLeaf)
- .build()).build()).build()).build();
+ leaf).build()).build()).build();
final NormalizedNode<?, ?> filter = ImmutableNodes.fromInstanceId(ctx,
- YangInstanceIdentifier.create(rootContainer, outerContainer, augmentation, augmentedLeaf));
+ YangInstanceIdentifier.create(rootContainer, outerContainer, augmentation, augmentedLeaf), leaf);
assertEquals(expectedFilter, filter);
}
@Test
public void testListChoice() throws Exception {
+ final LeafNode<?> leaf = Builders.leafBuilder().withNodeIdentifier(leafFromCase).withValue("").build();
final ContainerNode expectedFilter = Builders
.containerBuilder()
.withNodeIdentifier(rootContainer)
.withChild(
Builders.choiceBuilder()
.withNodeIdentifier(choice)
- .withChild(
- Builders.leafBuilder()
- .withNodeIdentifier(leafFromCase)
- .build()).build()).build()).build())
+ .withChild(leaf)
+ .build())
+ .build())
+ .build())
.build();
final NormalizedNode<?, ?> filter = ImmutableNodes.fromInstanceId(ctx,
- YangInstanceIdentifier.create(rootContainer, outerList, outerListWithKey, choice, leafFromCase));
+ YangInstanceIdentifier.create(rootContainer, outerList, outerListWithKey, choice, leafFromCase), leaf);
assertEquals(expectedFilter, filter);
}
.withChild(
Builders.leafBuilder()
.withNodeIdentifier(leafFromCase)
+ .withValue("")
.build()).build()).build()).build())
.build();
// This test is based on using different references; we're testing equals()
@SuppressWarnings({"RedundantStringConstructorCall", "EqualsWithItself"})
public void equalsByteTest() {
-
- LeafNode<byte[]> leafNodeNull = ImmutableNodes.leafNode(LEAF_QNAME, null);
- LeafNode<byte[]> equalLeafNodeNull = ImmutableNodes.leafNode(SAME_LEAF_QNAME, null);
-
- assertTrue(leafNodeNull.equals(leafNodeNull));
- assertTrue(leafNodeNull.equals(equalLeafNodeNull));
- assertTrue(equalLeafNodeNull.equals(leafNodeNull));
-
byte[] value = "test".getBytes();
byte[] equalValue = "test".getBytes();
Byte[] value2 = new Byte[] { new Byte("1"), new Byte("2") };
Byte[] equalValue2 = new Byte[] { new Byte("1"), new Byte("2") };
- LeafNode<Byte[]> leafNode2 = ImmutableNodes
- .leafNode(LEAF_QNAME, value2);
+ LeafNode<Byte[]> leafNode2 = ImmutableNodes.leafNode(LEAF_QNAME, value2);
LeafNode<Byte[]> equalLeafNode2 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue2);
assertTrue(leafNode2.equals(leafNode2));
assertFalse(leafNode4.equals(leafNode5));
assertFalse(leafNode6.equals(leafNode5));
- LeafNode<byte[]> leafNodeNull = ImmutableNodes.leafNode(SAME_LEAF_QNAME, null);
- assertFalse(leafNodeNull.equals(leafNode));
- assertFalse(leafNode.equals(leafNodeNull));
-
byte[] byteValue = new byte[] { 1, 1 };
LeafNode<byte[]> byteLeafNode = ImmutableNodes.leafNode(SAME_LEAF_QNAME, byteValue);
*/
package org.opendaylight.yangtools.yang.data.util;
+import static java.util.Objects.requireNonNull;
+
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
/**
}
public void setValue(final Object value) {
- this.value = value;
+ this.value = requireNonNull(value);
}
public Object getValue() {
return value;
}
-
}