/** * Validate the given <code>Attributes</code>. * * @param attributes the <code>Attributes</code> to validate * @return information about whether the <code>Attributes</code> is valid and, * if not, why it is not */ AttributeValidationResult validate(Attributes attributes) { for (String name : requiredAttributes) { if (!attributes.containsKey(name)) { return new MissingRequiredAttribute(name); } } for (Map.Entry<String, String> attribute : attributes.entrySet()) { String name = attribute.getKey(); ValueValidator validator = valueValidators.get(name); if (validator == null) { return new AttributeNotAllowed(name); } String value = attribute.getValue(); if (!validator.validate(value)) { return new InvalidAttributeValue(name, value); } } return AttributeValidationResult.VALID; }
@Override public Pair<String, String> map(final String name) { if (finalAttrAccu.containsKey(name)) { return null; } return pickRandomNonNullMappedElement(r, p.getAttributeValues(), new Mapper<String, Pair<String, String>>() { @Override public Pair<String, String> map(String value) { Attributes b = finalAttrAccu.updateWith( new AttributesUpdateImpl(name, null, value)); assert b != finalAttrAccu; // assert non-destructiveness ValidationResult v = checker.check(b); if (valid && !v.isValid() || !valid && v.isIllFormed()) { return null; } else { return Pair.of(name, value); } } }); } });