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 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 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; }
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; }
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 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 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 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 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()); }
} 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 {
} 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 {