@Test public void getRestrictionsTest() throws InvalidLengthConstraintException { final Optional<String> absent = Optional.empty(); final StringTypeBuilder builder = RestrictedTypes.newStringBuilder(BaseTypes.stringType(), ROOT_PATH); builder.addPatternConstraint(BaseConstraints.newPatternConstraint(".*", absent, absent)); builder.setLengthConstraint(mock(ConstraintMetaDefinition.class), ImmutableList.of(ValueRange.of(1, 2))); Restrictions restrictions = BindingGeneratorUtil.getRestrictions(builder.build()); assertNotNull(restrictions); assertEquals(ImmutableSet.of(Range.closed(1, 2)), restrictions.getLengthConstraint().get().getAllowedRanges().asRanges()); assertFalse(restrictions.getRangeConstraint().isPresent()); assertEquals(1, restrictions.getPatternConstraints().size()); assertFalse(restrictions.isEmpty()); assertTrue(restrictions.getPatternConstraints().contains( BaseConstraints.newPatternConstraint(".*", absent, absent))); }
public static Restrictions getRestrictions(final TypeDefinition<?> type) { if (type == null || type.getBaseType() == null) { if (type instanceof DecimalTypeDefinition) { final DecimalTypeDefinition decimal = (DecimalTypeDefinition) type; final DecimalTypeBuilder tmpBuilder = BaseTypes.decimalTypeBuilder(decimal.getPath()); tmpBuilder.setFractionDigits(decimal.getFractionDigits()); final DecimalTypeDefinition tmp = tmpBuilder.build(); if (!tmp.getRangeConstraint().equals(decimal.getRangeConstraint())) { return new Restrictions() { @Override public boolean isEmpty() { return false; } @Override public Optional<? extends RangeConstraint<?>> getRangeConstraint() { return decimal.getRangeConstraint(); } @Override public List<PatternConstraint> getPatternConstraints() { return ImmutableList.of(); } @Override public Optional<LengthConstraint> getLengthConstraint() { return Optional.empty(); } }; } } return EMPTY_RESTRICTIONS; } final Optional<LengthConstraint> length; final List<PatternConstraint> pattern; final Optional<? extends RangeConstraint<?>> range; if (type instanceof BinaryTypeDefinition) { final BinaryTypeDefinition binary = (BinaryTypeDefinition)type; final BinaryTypeDefinition base = binary.getBaseType(); if (base != null && base.getBaseType() != null) { length = currentOrEmpty(binary.getLengthConstraint(), base.getLengthConstraint()); } else { length = binary.getLengthConstraint(); } pattern = ImmutableList.of(); range = Optional.empty(); } else if (type instanceof DecimalTypeDefinition) { length = Optional.empty(); pattern = ImmutableList.of(); final DecimalTypeDefinition decimal = (DecimalTypeDefinition)type; final DecimalTypeDefinition base = decimal.getBaseType(); if (base != null && base.getBaseType() != null) { range = currentOrEmpty(decimal.getRangeConstraint(), base.getRangeConstraint()); } else { range = decimal.getRangeConstraint(); } } else if (type instanceof RangeRestrictedTypeDefinition) { length = Optional.empty(); pattern = ImmutableList.of(); range = extractRangeConstraint((RangeRestrictedTypeDefinition<?, ?>)type); } 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(); } pattern = uniquePatterns(string); range = Optional.empty(); } else { length = Optional.empty(); pattern = ImmutableList.of(); range = Optional.empty(); } if (!length.isPresent() && pattern.isEmpty() && !range.isPresent()) { return EMPTY_RESTRICTIONS; } return new Restrictions() { @Override public Optional<? extends RangeConstraint<?>> getRangeConstraint() { return range; } @Override public List<PatternConstraint> getPatternConstraints() { return pattern; } @Override public Optional<LengthConstraint> getLengthConstraint() { return length; } @Override public boolean isEmpty() { return false; } }; }
BindingGeneratorUtil { public static Restrictions getRestrictions(final TypeDefinition<?> type) { if (type == null || type.getBaseType() == null) { if (type instanceof DecimalTypeDefinition) { final DecimalTypeDefinition decimal = (DecimalTypeDefinition) type; final DecimalTypeBuilder tmpBuilder = BaseTypes.decimalTypeBuilder(decimal.getPath()); tmpBuilder.setFractionDigits(decimal.getFractionDigits()); final DecimalTypeDefinition tmp = tmpBuilder.build(); if (!tmp.getRangeConstraint().equals(decimal.getRangeConstraint())) { return new Restrictions() { @Override public boolean isEmpty() { return false; } @Override public Optional<? extends RangeConstraint<?>> getRangeConstraint() { return decimal.getRangeConstraint(); } @Override public List<PatternConstraint> getPatternConstraints() { return ImmutableList.of(); } @Override public Optional<LengthConstraint> getLengthConstraint() { return Optional.empty(); } }; } } return EMPTY_RESTRICTIONS; } final Optional<LengthConstraint> length; final List<PatternConstraint> pattern; final Optional<? extends RangeConstraint<?>> range; if (type instanceof BinaryTypeDefinition) { final BinaryTypeDefinition binary = (BinaryTypeDefinition)type; final BinaryTypeDefinition base = binary.getBaseType(); if (base != null && base.getBaseType() != null) { length = currentOrEmpty(binary.getLengthConstraint(), base.getLengthConstraint()); } else { length = binary.getLengthConstraint(); } pattern = ImmutableList.of(); range = Optional.empty(); } else if (type instanceof DecimalTypeDefinition) { length = Optional.empty(); pattern = ImmutableList.of(); final DecimalTypeDefinition decimal = (DecimalTypeDefinition)type; final DecimalTypeDefinition base = decimal.getBaseType(); if (base != null && base.getBaseType() != null) { range = currentOrEmpty(decimal.getRangeConstraint(), base.getRangeConstraint()); } else { range = decimal.getRangeConstraint(); } } else if (type instanceof RangeRestrictedTypeDefinition) { length = Optional.empty(); pattern = ImmutableList.of(); range = extractRangeConstraint((RangeRestrictedTypeDefinition<?, ?>)type); } 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(); } pattern = uniquePatterns(string); range = Optional.empty(); } else { length = Optional.empty(); pattern = ImmutableList.of(); range = Optional.empty(); } if (!length.isPresent() && pattern.isEmpty() && !range.isPresent()) { return EMPTY_RESTRICTIONS; } return new Restrictions() { @Override public Optional<? extends RangeConstraint<?>> getRangeConstraint() { return range; } @Override public List<PatternConstraint> getPatternConstraints() { return pattern; } @Override public Optional<LengthConstraint> getLengthConstraint() { return length; } @Override public boolean isEmpty() { return false; } }; } }
BindingGeneratorUtil { public static Restrictions getRestrictions(final TypeDefinition<?> type) { if (type == null || type.getBaseType() == null) { if (type instanceof DecimalTypeDefinition) { final DecimalTypeDefinition decimal = (DecimalTypeDefinition) type; final DecimalTypeBuilder tmpBuilder = BaseTypes.decimalTypeBuilder(decimal.getPath()); tmpBuilder.setFractionDigits(decimal.getFractionDigits()); final DecimalTypeDefinition tmp = tmpBuilder.build(); if (!tmp.getRangeConstraint().equals(decimal.getRangeConstraint())) { return new Restrictions() { @Override public boolean isEmpty() { return false; } @Override public Optional<? extends RangeConstraint<?>> getRangeConstraint() { return decimal.getRangeConstraint(); } @Override public List<PatternConstraint> getPatternConstraints() { return ImmutableList.of(); } @Override public Optional<LengthConstraint> getLengthConstraint() { return Optional.empty(); } }; } } return EMPTY_RESTRICTIONS; } final Optional<LengthConstraint> length; final List<PatternConstraint> pattern; final Optional<? extends RangeConstraint<?>> range; if (type instanceof BinaryTypeDefinition) { final BinaryTypeDefinition binary = (BinaryTypeDefinition)type; final BinaryTypeDefinition base = binary.getBaseType(); if (base != null && base.getBaseType() != null) { length = currentOrEmpty(binary.getLengthConstraint(), base.getLengthConstraint()); } else { length = binary.getLengthConstraint(); } pattern = ImmutableList.of(); range = Optional.empty(); } else if (type instanceof DecimalTypeDefinition) { length = Optional.empty(); pattern = ImmutableList.of(); final DecimalTypeDefinition decimal = (DecimalTypeDefinition)type; final DecimalTypeDefinition base = decimal.getBaseType(); if (base != null && base.getBaseType() != null) { range = currentOrEmpty(decimal.getRangeConstraint(), base.getRangeConstraint()); } else { range = decimal.getRangeConstraint(); } } else if (type instanceof RangeRestrictedTypeDefinition) { length = Optional.empty(); pattern = ImmutableList.of(); range = extractRangeConstraint((RangeRestrictedTypeDefinition<?, ?>)type); } 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(); } pattern = uniquePatterns(string); range = Optional.empty(); } else { length = Optional.empty(); pattern = ImmutableList.of(); range = Optional.empty(); } if (!length.isPresent() && pattern.isEmpty() && !range.isPresent()) { return EMPTY_RESTRICTIONS; } return new Restrictions() { @Override public Optional<? extends RangeConstraint<?>> getRangeConstraint() { return range; } @Override public List<PatternConstraint> getPatternConstraints() { return pattern; } @Override public Optional<LengthConstraint> getLengthConstraint() { return length; } @Override public boolean isEmpty() { return false; } }; } private  BindingGeneratorUtil(); }
BindingGeneratorUtil { public static Restrictions getRestrictions(final TypeDefinition<?> type) { if (type == null || type.getBaseType() == null) { if (type instanceof DecimalTypeDefinition) { final DecimalTypeDefinition decimal = (DecimalTypeDefinition) type; final DecimalTypeBuilder tmpBuilder = BaseTypes.decimalTypeBuilder(decimal.getPath()); tmpBuilder.setFractionDigits(decimal.getFractionDigits()); final DecimalTypeDefinition tmp = tmpBuilder.build(); if (!tmp.getRangeConstraint().equals(decimal.getRangeConstraint())) { return new Restrictions() { @Override public boolean isEmpty() { return false; } @Override public Optional<? extends RangeConstraint<?>> getRangeConstraint() { return decimal.getRangeConstraint(); } @Override public List<PatternConstraint> getPatternConstraints() { return ImmutableList.of(); } @Override public Optional<LengthConstraint> getLengthConstraint() { return Optional.empty(); } }; } } return EMPTY_RESTRICTIONS; } final Optional<LengthConstraint> length; final List<PatternConstraint> pattern; final Optional<? extends RangeConstraint<?>> range; if (type instanceof BinaryTypeDefinition) { final BinaryTypeDefinition binary = (BinaryTypeDefinition)type; final BinaryTypeDefinition base = binary.getBaseType(); if (base != null && base.getBaseType() != null) { length = currentOrEmpty(binary.getLengthConstraint(), base.getLengthConstraint()); } else { length = binary.getLengthConstraint(); } pattern = ImmutableList.of(); range = Optional.empty(); } else if (type instanceof DecimalTypeDefinition) { length = Optional.empty(); pattern = ImmutableList.of(); final DecimalTypeDefinition decimal = (DecimalTypeDefinition)type; final DecimalTypeDefinition base = decimal.getBaseType(); if (base != null && base.getBaseType() != null) { range = currentOrEmpty(decimal.getRangeConstraint(), base.getRangeConstraint()); } else { range = decimal.getRangeConstraint(); } } else if (type instanceof RangeRestrictedTypeDefinition) { length = Optional.empty(); pattern = ImmutableList.of(); range = extractRangeConstraint((RangeRestrictedTypeDefinition<?, ?>)type); } 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(); } pattern = uniquePatterns(string); range = Optional.empty(); } else { length = Optional.empty(); pattern = ImmutableList.of(); range = Optional.empty(); } if (!length.isPresent() && pattern.isEmpty() && !range.isPresent()) { return EMPTY_RESTRICTIONS; } return new Restrictions() { @Override public Optional<? extends RangeConstraint<?>> getRangeConstraint() { return range; } @Override public List<PatternConstraint> getPatternConstraints() { return pattern; } @Override public Optional<LengthConstraint> getLengthConstraint() { return length; } @Override public boolean isEmpty() { return false; } }; } private  BindingGeneratorUtil(); static String resolveJavaReservedWordEquivalency(final String parameterName); static String packageNameForGeneratedType(final String basePackageName, final SchemaPath schemaPath); static String packageNameForAugmentedGeneratedType(final String basePackageName,
            final SchemaPath schemaPath); static long computeDefaultSUID(final GeneratedTypeBuilderBase<?> to); static Restrictions getRestrictions(final TypeDefinition<?> type); static String encodeAngleBrackets(String description); static String replaceAllIllegalChars(final String str); }
BindingGeneratorUtil { public static Restrictions getRestrictions(final TypeDefinition<?> type) { if (type == null || type.getBaseType() == null) { if (type instanceof DecimalTypeDefinition) { final DecimalTypeDefinition decimal = (DecimalTypeDefinition) type; final DecimalTypeBuilder tmpBuilder = BaseTypes.decimalTypeBuilder(decimal.getPath()); tmpBuilder.setFractionDigits(decimal.getFractionDigits()); final DecimalTypeDefinition tmp = tmpBuilder.build(); if (!tmp.getRangeConstraint().equals(decimal.getRangeConstraint())) { return new Restrictions() { @Override public boolean isEmpty() { return false; } @Override public Optional<? extends RangeConstraint<?>> getRangeConstraint() { return decimal.getRangeConstraint(); } @Override public List<PatternConstraint> getPatternConstraints() { return ImmutableList.of(); } @Override public Optional<LengthConstraint> getLengthConstraint() { return Optional.empty(); } }; } } return EMPTY_RESTRICTIONS; } final Optional<LengthConstraint> length; final List<PatternConstraint> pattern; final Optional<? extends RangeConstraint<?>> range; if (type instanceof BinaryTypeDefinition) { final BinaryTypeDefinition binary = (BinaryTypeDefinition)type; final BinaryTypeDefinition base = binary.getBaseType(); if (base != null && base.getBaseType() != null) { length = currentOrEmpty(binary.getLengthConstraint(), base.getLengthConstraint()); } else { length = binary.getLengthConstraint(); } pattern = ImmutableList.of(); range = Optional.empty(); } else if (type instanceof DecimalTypeDefinition) { length = Optional.empty(); pattern = ImmutableList.of(); final DecimalTypeDefinition decimal = (DecimalTypeDefinition)type; final DecimalTypeDefinition base = decimal.getBaseType(); if (base != null && base.getBaseType() != null) { range = currentOrEmpty(decimal.getRangeConstraint(), base.getRangeConstraint()); } else { range = decimal.getRangeConstraint(); } } else if (type instanceof RangeRestrictedTypeDefinition) { length = Optional.empty(); pattern = ImmutableList.of(); range = extractRangeConstraint((RangeRestrictedTypeDefinition<?, ?>)type); } 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(); } pattern = uniquePatterns(string); range = Optional.empty(); } else { length = Optional.empty(); pattern = ImmutableList.of(); range = Optional.empty(); } if (!length.isPresent() && pattern.isEmpty() && !range.isPresent()) { return EMPTY_RESTRICTIONS; } return new Restrictions() { @Override public Optional<? extends RangeConstraint<?>> getRangeConstraint() { return range; } @Override public List<PatternConstraint> getPatternConstraints() { return pattern; } @Override public Optional<LengthConstraint> getLengthConstraint() { return length; } @Override public boolean isEmpty() { return false; } }; } private  BindingGeneratorUtil(); static String resolveJavaReservedWordEquivalency(final String parameterName); static String packageNameForGeneratedType(final String basePackageName, final SchemaPath schemaPath); static String packageNameForAugmentedGeneratedType(final String basePackageName,
            final SchemaPath schemaPath); static long computeDefaultSUID(final GeneratedTypeBuilderBase<?> to); static Restrictions getRestrictions(final TypeDefinition<?> type); static String encodeAngleBrackets(String description); static String replaceAllIllegalChars(final String str);  }