static int hashCode(final @NonNull StringTypeDefinition type) { return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits().orElse(null), type.getDefaultValue().orElse(null), type.getLengthConstraint().orElse(null), type.getPatternConstraints()); }
@Override public boolean equals(final Object obj) { return StringTypeDefinition.equals(this, obj); } }
private static boolean containsConstraint(final StringTypeDefinition type, final PatternConstraint constraint) { for (StringTypeDefinition wlk = type; wlk != null; wlk = wlk.getBaseType()) { if (wlk.getPatternConstraints().contains(constraint)) { return true; } } return false; }
private static TypeDefinition<?> baseTypeIfNotConstrained(final @NonNull StringTypeDefinition type) { final StringTypeDefinition base = type.getBaseType(); final List<PatternConstraint> patterns = type.getPatternConstraints(); final Optional<LengthConstraint> optLengths = type.getLengthConstraint(); if ((patterns.isEmpty() || patterns.equals(base.getPatternConstraints())) && (!optLengths.isPresent() || optLengths.equals(base.getLengthConstraint()))) { return base; } return type; }
private void emitStringRestrictions(final StringTypeDefinition typeDef) { typeDef.getLengthConstraint().ifPresent(this::emitLength); for (final PatternConstraint pattern : typeDef.getPatternConstraints()) { emitPatternNode(pattern); } }
@Override public List<PatternConstraint> getPatternConstraints() { return baseType().getPatternConstraints(); }
} else if (type instanceof StringTypeDefinition) { final StringTypeDefinition string = (StringTypeDefinition)type; final StringTypeDefinition base = string.getBaseType(); if (base != null && base.getBaseType() != null) { length = currentOrEmpty(string.getLengthConstraint(), base.getLengthConstraint()); } else { length = string.getLengthConstraint();
StringStringCodec(final StringTypeDefinition typeDef) { super(Optional.of(typeDef), String.class); lengthConstraint = typeDef.getLengthConstraint().orElse(null); }
private static void processStringType(final StringTypeDefinition stringType, final JSONObject property) throws JSONException { StringTypeDefinition type = stringType; List<LengthConstraint> lengthConstraints = stringType.getLengthConstraints(); while (lengthConstraints.isEmpty() && type.getBaseType() != null) { type = type.getBaseType(); lengthConstraints = type.getLengthConstraints(); } // FIXME: json-schema is not expressive enough to capture min/max laternatives. We should find the true minimum // and true maximum implied by the constraints and use that. for (LengthConstraint lengthConstraint : lengthConstraints) { Number min = lengthConstraint.getMin(); Number max = lengthConstraint.getMax(); property.putOpt(MIN_LENGTH_KEY, min); property.putOpt(MAX_LENGTH_KEY, max); } property.put(TYPE_KEY, STRING); }
static boolean equals(final @NonNull StringTypeDefinition type, final @Nullable Object obj) { if (type == obj) { return true; } final StringTypeDefinition other = TypeDefinitions.castIfEquals(StringTypeDefinition.class, type, obj); return other != null && type.getLengthConstraint().equals(other.getLengthConstraint()) && type.getPatternConstraints().equals(other.getPatternConstraints()); }
private static TypeDefinition<?> baseTypeIfNotConstrained(final @NonNull StringTypeDefinition type) { final StringTypeDefinition base = type.getBaseType(); final List<PatternConstraint> patterns = type.getPatternConstraints(); final Optional<LengthConstraint> optLengths = type.getLengthConstraint(); if ((patterns.isEmpty() || patterns.equals(base.getPatternConstraints())) && (!optLengths.isPresent() || optLengths.equals(base.getLengthConstraint()))) { return base; } return type; }
private static boolean containsConstraint(final StringTypeDefinition type, final PatternConstraint constraint) { for (StringTypeDefinition wlk = type; wlk != null; wlk = wlk.getBaseType()) { if (wlk.getPatternConstraints().contains(constraint)) { return true; } } return false; }
StringPatternCheckingCodec(final StringTypeDefinition typeDef) { super(typeDef); final List<PatternConstraint> constraints = typeDef.getPatternConstraints(); final Builder<CompiledPatternContext> builder = ImmutableList.builderWithExpectedSize(constraints.size()); for (final PatternConstraint yangPattern : typeDef.getPatternConstraints()) { try { builder.add(new CompiledPatternContext(yangPattern)); } catch (final PatternSyntaxException e) { LOG.debug("Unable to compile {} pattern, excluding it from validation.", yangPattern, e); } } patterns = builder.build(); }
} else if (type instanceof StringTypeDefinition) { final StringTypeDefinition string = (StringTypeDefinition)type; final StringTypeDefinition base = string.getBaseType(); if (base != null && base.getBaseType() != null) { length = currentOrEmpty(string.getLengthConstraint(), base.getLengthConstraint()); } else { length = string.getLengthConstraint();
StringStringCodec(final StringTypeDefinition typeDef) { super(Optional.of(typeDef), String.class); lengthConstraint = typeDef.getLengthConstraint().orElse(null); }
static int hashCode(final @NonNull StringTypeDefinition type) { return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits().orElse(null), type.getDefaultValue().orElse(null), type.getLengthConstraint().orElse(null), type.getPatternConstraints()); }
static boolean equals(final @NonNull StringTypeDefinition type, final @Nullable Object obj) { if (type == obj) { return true; } final StringTypeDefinition other = TypeDefinitions.castIfEquals(StringTypeDefinition.class, type, obj); return other != null && type.getLengthConstraint().equals(other.getLengthConstraint()) && type.getPatternConstraints().equals(other.getPatternConstraints()); }
private static List<PatternConstraint> uniquePatterns(final StringTypeDefinition type) { final List<PatternConstraint> constraints = type.getPatternConstraints(); if (constraints.isEmpty()) { return constraints; } final Builder<PatternConstraint> builder = ImmutableList.builder(); boolean filtered = false; for (final PatternConstraint c : constraints) { if (containsConstraint(type.getBaseType(), c)) { filtered = true; } else { builder.add(c); } } return filtered ? builder.build() : constraints; }
StringPatternCheckingCodec(final StringTypeDefinition typeDef) { super(typeDef); final List<PatternConstraint> constraints = typeDef.getPatternConstraints(); final Builder<CompiledPatternContext> builder = ImmutableList.builderWithExpectedSize(constraints.size()); for (final PatternConstraint yangPattern : typeDef.getPatternConstraints()) { try { builder.add(new CompiledPatternContext(yangPattern)); } catch (final PatternSyntaxException e) { LOG.debug("Unable to compile {} pattern, excluding it from validation.", yangPattern, e); } } patterns = builder.build(); }
@Override public boolean equals(final Object obj) { return StringTypeDefinition.equals(this, obj); }