Я создал небольшой служебный класс, чтобы решить именно эту проблему.
public class HibernateValidator {
private ConcurrentHashMap<Class, List<FieldConstraint>> constraints = new ConcurrentHashMap<>();
public List<ValidationViolation> validate(Object entity) {
List<FieldConstraint> constraints = getFieldConstraints(entity);
return constraints.stream()
.flatMap(x -> validate(entity, x))
.collect(Collectors.toList());
}
private Stream<ValidationViolation> validate(Object entity, FieldConstraint x) {
String value;
try {
x.getField().setAccessible(true);
value = (String) x.getField().get(entity);
} catch (IllegalAccessException e) {
throw new RuntimeException("Can't get value", e);
}
if (value != null && value.length() > x.getSize()) {
return Stream.of(ValidationViolation.builder()
.fieldName(x.getField().getName())
.build());
} else {
return Stream.empty();
}
}
private List<FieldConstraint> getFieldConstraints(Object entity) {
return constraints.computeIfAbsent(entity.getClass(),
clazz -> Stream.of(clazz.getDeclaredFields())
.filter(x -> x.getType().equals(String.class))
.flatMap(x -> {
Column annotation = x.getAnnotation(Column.class);
if (annotation == null) {
return Stream.empty();
} else {
return Stream.of(FieldConstraint.builder()
.field(x)
.size(annotation.length())
.build());
}
})
.collect(Collectors.toList()));
}
@Data
@Builder
public static class ValidationViolation {
private final String fieldName;
}
@Data
@Builder
private static class FieldConstraint {
private final Field field;
private final int size;
}
}
Nehe имеет хорошее учебное руководство о том, как сделать это, и его сайт обычно является хорошим ресурсом для вопросов о OpenGL.
да,
и необходимо также изменить разрезать ножницами настройки, чтобы иметь чистое разделение между двумя представлениями, если они находятся в том же окне.
// normal mode
if(!divided_view_port)
glViewport(0, 0, w, h);
else
{
// right bottom
glViewport(w/2, h/2, w, h);
glLoadIdentity ();
gluLookAt(5.0f, 5.0f, 5.0f,
0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f);
display();
// left bottom
glViewport(0, h/2, w/2, h);
glLoadIdentity();
gluLookAt (5.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f);
display();
// top right
glViewport(w/2, 0, w, h/2);
glLoadIdentity();
gluLookAt(0.0f, 0.0f, 5.0f,
0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f);
display();
// top left
glViewport(0, 0, w/2, h/2);
glLoadIdentity();
gluLookAt(0.0f, 5.0f, 0.0f,
0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f);
display();
}
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w <= h)
glOrtho(-2.0, 2.0,
-2.0 * (GLfloat) h / (GLfloat) w, 2.0 * (GLfloat) h / (GLfloat) w,
-10.0, 100.0);
else
glOrtho(-2.0 * (GLfloat) w / (GLfloat) h, 2.0 * (GLfloat) w / (GLfloat) h,
-2.0, 2.0,
-10.0, 100.0);
glMatrixMode(GL_MODELVIEW);