All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.dropwizard.validation.ConstraintViolations Maven / Gradle / Ivy

There is a newer version: 0.0.3
Show newest version
package io.dropwizard.validation;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.validation.ConstraintViolation;

public class ConstraintViolations {

    private ConstraintViolations() { /* singleton */ }

    public static  String format(ConstraintViolation v) {
        if (v.getConstraintDescriptor().getAnnotation() instanceof ValidationMethod) {
            return v.getMessage();
        } else {
            return String.format("%s %s", v.getPropertyPath(), v.getMessage());
        }
    }

    public static  List format(Set> violations) {

        final Set errors = new HashSet<>();
        for (ConstraintViolation v : violations) {
            errors.add(format(v));
        }
        return new ArrayList<>(errors);
    }

    public static List formatUntyped(Set> violations) {

        final Set errors = new HashSet<>();
        for (ConstraintViolation v : violations) {
            errors.add(format(v));
        }
      return new ArrayList<>(errors);
    }

    public static  Set> copyOf(Set> violations) {
        final Set> copiedSet = new HashSet<>();
        for (ConstraintViolation violation : violations) {
          copiedSet.add(violation);
        }
        return copiedSet;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy