}
@Override
+ @SuppressWarnings("unchecked")
public LeafNode<T> build() {
- return new ImmutableLeafNode<>(getNodeIdentifier(), getValue(), getAttributes());
- }
+ final T value = getValue();
+ if (value instanceof byte[]) {
+ return (LeafNode<T>) new ImmutableBinaryLeafNode(getNodeIdentifier(), (byte[]) value, getAttributes());
+ }
- private static final class ImmutableLeafNode<T> extends AbstractImmutableNormalizedValueAttrNode<NodeIdentifier, T> implements LeafNode<T> {
+ return new ImmutableLeafNode<>(getNodeIdentifier(), value, getAttributes());
+ }
+ private static final class ImmutableLeafNode<T>
+ extends AbstractImmutableNormalizedValueAttrNode<NodeIdentifier, T> implements LeafNode<T> {
ImmutableLeafNode(final NodeIdentifier nodeIdentifier, final T value, final Map<QName, String> attributes) {
super(nodeIdentifier, value, attributes);
}
}
+
+ private static final class ImmutableBinaryLeafNode
+ extends AbstractImmutableNormalizedValueAttrNode<NodeIdentifier, byte[]> implements LeafNode<byte[]> {
+ ImmutableBinaryLeafNode(final NodeIdentifier nodeIdentifier, final byte[] value,
+ final Map<QName, String> attributes) {
+ super(nodeIdentifier, value, attributes);
+ }
+
+ @Override
+ protected byte[] wrapValue(final byte[] value) {
+ return value.clone();
+ }
+ }
}
@Override
protected int valueHashCode() {
- final int result = getValue() != null ? getValue().hashCode() : 1;
+ final V local = value();
+ final int result = local != null ? local.hashCode() : 1;
// FIXME: are attributes part of hashCode/equals?
return result;
}
// We can not call directly getValue.equals because of Empty Type
// Definition leaves which allways have NULL value
- if (!Objects.deepEquals(getValue(), other.getValue())) {
+ if (!Objects.deepEquals(value(), other.getValue())) {
return false;
}
// FIXME: are attributes part of hashCode/equals?
return true;
}
-
}
protected AbstractImmutableNormalizedValueNode(final K nodeIdentifier, @Nullable 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) {
- /*
- * 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.
- */
- LOG.debug("The value of node {} is null",nodeIdentifier.getNodeType());
+ LOG.debug("The value of node {} is null", nodeIdentifier.getNodeType());
}
this.value = value;
}
@Nullable
@Override
public final V getValue() {
+ return wrapValue(value);
+ }
+
+ @Nullable
+ protected final V value() {
+ return value;
+ }
+
+ protected V wrapValue(final V value) {
return value;
}
}