@Override public final Optional<? extends Object> getDefaultValue() { return baseType.getDefaultValue(); }
@Override public final Optional<? extends Object> getDefaultValue() { return baseType.getDefaultValue(); }
@Override public final Optional<? extends Object> getDefaultValue() { return defaultValue != null ? Optional.of(defaultValue) : baseType.getDefaultValue(); }
@Override public final Optional<? extends Object> getDefaultValue() { return defaultValue != null ? Optional.of(defaultValue) : baseType.getDefaultValue(); }
DerivedTypeBuilder(final T baseType, final SchemaPath path) { super(requireNonNull(baseType), path); checkArgument(baseType instanceof AbstractBaseType || baseType instanceof AbstractDerivedType || baseType instanceof AbstractRestrictedType, "Derived type can be built only from a base, derived, or restricted type, not %s", baseType); // http://tools.ietf.org/html/rfc6020#section-7.3.4 defaultValue = baseType.getDefaultValue().orElse(null); // In similar vein, it makes sense to propagate units units = baseType.getUnits().orElse(null); }
DerivedTypeBuilder(final T baseType, final SchemaPath path) { super(requireNonNull(baseType), path); checkArgument(baseType instanceof AbstractBaseType || baseType instanceof AbstractDerivedType || baseType instanceof AbstractRestrictedType, "Derived type can be built only from a base, derived, or restricted type, not %s", baseType); // http://tools.ietf.org/html/rfc6020#section-7.3.4 defaultValue = baseType.getDefaultValue().orElse(null); // In similar vein, it makes sense to propagate units units = baseType.getUnits().orElse(null); }
static @NonNull ToStringHelper toStringHelper(final @NonNull TypeDefinition<?> type) { return MoreObjects.toStringHelper(type).omitNullValues() .add("path", type.getPath()) .add("baseType", type.getBaseType()) .add("default", type.getDefaultValue().orElse(null)) .add("description", type.getDescription().orElse(null)) .add("reference", type.getReference().orElse(null)) .add("status", type.getStatus()) .add("units", type.getUnits().orElse(null)); }
@Override public String getTypeDefaultConstruction(final LeafSchemaNode node) { return getTypeDefaultConstruction(node, (String) node.getType().getDefaultValue().orElse(null)); }
static @NonNull ToStringHelper toStringHelper(final @NonNull TypeDefinition<?> type) { return MoreObjects.toStringHelper(type).omitNullValues() .add("path", type.getPath()) .add("baseType", type.getBaseType()) .add("default", type.getDefaultValue().orElse(null)) .add("description", type.getDescription().orElse(null)) .add("reference", type.getReference().orElse(null)) .add("status", type.getStatus()) .add("units", type.getUnits().orElse(null)); }
static <T extends TypeDefinition<T>> @Nullable T castIfEquals(final @NonNull Class<T> clazz, final @NonNull T type, final @Nullable Object obj) { if (!clazz.isInstance(obj)) { return null; } final @NonNull T other = clazz.cast(obj); return Objects.equals(type.getPath(), other.getPath()) && Objects.equals(type.getBaseType(), other.getBaseType()) && Objects.equals(type.getDefaultValue(), other.getDefaultValue()) && Objects.equals(type.getUnknownSchemaNodes(), other.getUnknownSchemaNodes()) && Objects.equals(type.getUnits(), other.getUnits()) ? other : null; }
private static Object createDefaultObject(final DataSchemaNode schema, final Codec<Object, Object> codec, final SchemaContext schemaContext) { if (schema instanceof LeafSchemaNode) { TypeDefinition<?> type = ((LeafSchemaNode) schema).getType(); Optional<? extends Object> defaultValue = type.getDefaultValue(); if (defaultValue.isPresent()) { if (type instanceof IdentityrefTypeDefinition) { return qnameDomValueFromString(codec, schema, (String) defaultValue.get(), schemaContext); } return domValueFromString(codec, type, defaultValue.get()); } while (type.getBaseType() != null && !type.getDefaultValue().isPresent()) { type = type.getBaseType(); } defaultValue = type.getDefaultValue(); if (defaultValue.isPresent()) { if (type instanceof IdentityrefTypeDefinition) { return qnameDomValueFromString(codec, schema, (String) defaultValue.get(), schemaContext); } return domValueFromString(codec, type, defaultValue.get()); } } return null; }
static <T extends TypeDefinition<T>> @Nullable T castIfEquals(final @NonNull Class<T> clazz, final @NonNull T type, final @Nullable Object obj) { if (!clazz.isInstance(obj)) { return null; } final @NonNull T other = clazz.cast(obj); return Objects.equals(type.getPath(), other.getPath()) && Objects.equals(type.getBaseType(), other.getBaseType()) && Objects.equals(type.getDefaultValue(), other.getDefaultValue()) && Objects.equals(type.getUnknownSchemaNodes(), other.getUnknownSchemaNodes()) && Objects.equals(type.getUnits(), other.getUnits()) ? other : null; }
static int basicHashCode(final @NonNull TypeDefinition<?> type) { return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits().orElse(null), type.getDefaultValue().orElse(null)); }
@Override public final T build() { final T base = getBaseType(); if (Objects.equals(getDefaultValue(), base.getDefaultValue().orElse(null)) && Objects.equals(getUnits(), base.getUnits().orElse(null))) { return base; } return verifyNotNull(buildType()); } }
@Override public final T build() { final T base = getBaseType(); if (Objects.equals(getDefaultValue(), base.getDefaultValue().orElse(null)) && Objects.equals(getUnits(), base.getUnits().orElse(null))) { return base; } return verifyNotNull(buildType()); } }
private static Object createDefaultObject(final DataSchemaNode schema, final Codec<Object, Object> codec, final SchemaContext schemaContext) { if (schema instanceof LeafSchemaNode) { Optional<? extends Object> defaultValue = ((LeafSchemaNode) schema).getType().getDefaultValue(); TypeDefinition<?> type = ((LeafSchemaNode) schema).getType(); if (defaultValue.isPresent()) { if (type instanceof IdentityrefTypeDefinition) { return qnameDomValueFromString(codec, schema, (String) defaultValue.get(), schemaContext); } return domValueFromString(codec, type, defaultValue.get()); } while (type.getBaseType() != null && !type.getDefaultValue().isPresent()) { type = type.getBaseType(); } defaultValue = type.getDefaultValue(); if (defaultValue.isPresent()) { if (type instanceof IdentityrefTypeDefinition) { return qnameDomValueFromString(codec, schema, (String) defaultValue.get(), schemaContext); } return domValueFromString(codec, type, defaultValue); } } return null; }
static int basicHashCode(final @NonNull TypeDefinition<?> type) { return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits().orElse(null), type.getDefaultValue().orElse(null)); }
private void emitRefineLeafNodes(final LeafSchemaNode value) { final LeafSchemaNode original = getOriginalChecked(value); // emitMustNodes(child.getConstraints().getMustConstraints()); if (Objects.deepEquals(original.getType().getDefaultValue(), value.getType().getDefaultValue())) { emitDefaultNode(value.getType().getDefaultValue()); } if (Objects.deepEquals(original.isConfiguration(), value.isConfiguration())) { emitConfigNode(value.isConfiguration()); } emitDocumentedNodeRefine(original, value); if (Objects.deepEquals(original.isMandatory(), value.isMandatory())) { emitMandatoryNode(value.isMandatory()); } }
private void emitTypedefNode(final TypeDefinition<?> typedef) { super.writer.startTypedefNode(typedef.getQName()); // Differentiate between derived type and existing type // name. emitTypeNodeDerived(typedef); typedef.getUnits().ifPresent(this::emitUnitsNode); typedef.getDefaultValue().ifPresent(this::emitDefaultNode); emitDocumentedNode(typedef); emitUnknownStatementNodes(typedef.getUnknownSchemaNodes()); super.writer.endNode(); }
private void emitLeaf(final LeafSchemaNode child) { super.writer.startLeafNode(child.getQName()); child.getWhenCondition().ifPresent(this::emitWhen); // FIXME: BUG-2444: *(ifFeatureNode ) emitTypeNode(child.getPath(), child.getType()); child.getType().getUnits().ifPresent(this::emitUnitsNode); child.getMustConstraints().forEach(this::emitMust); child.getType().getDefaultValue().ifPresent(this::emitDefaultNode); emitConfigNode(child.isConfiguration()); emitMandatoryNode(child.isMandatory()); emitDocumentedNode(child); emitUnknownStatementNodes(child.getUnknownSchemaNodes()); super.writer.endNode(); }