Last active
December 23, 2015 02:39
-
-
Save dylon/6568095 to your computer and use it in GitHub Desktop.
Demonstrates how to use lombok-pg 0.11.3's @Validate and @Validate.With annotations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import lombok.Validate; | |
public class ValidateTest { | |
public static void main(final String... args) { | |
foo(0); //-> Passes validation (0 is the most-even number) | |
foo(1); //-> IllegalArgumentException: The object 'i' (argument #1) is invalid | |
} | |
@Validate //-> Required for @Validate.With(*) to be detected | |
private static void foo(@Validate.With("isEven") final Integer i) { | |
// @Validate.With(*) will only work on objects (not primitive types) and | |
// will only work with concrete, non-empty methods. It will, however, work | |
// with a method that does nothing but return void :) | |
// | |
// It also will not let you use validation methods from other classes, | |
// which is lame ... | |
return; | |
} | |
private static boolean isEven(final Integer i) { | |
return null != i && (i & 1) == 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment