Skip to content

Instantly share code, notes, and snippets.

@thomaspoignant
Created November 2, 2016 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomaspoignant/5afc1031bebc830ed2f2bfa64fbf81bc to your computer and use it in GitHub Desktop.
Save thomaspoignant/5afc1031bebc830ed2f2bfa64fbf81bc to your computer and use it in GitHub Desktop.
Example of a Static Factory Method, for the this article https://medium.com/@thomaspoignant/static-factory-methods-59e88d2d737f#.9sxp2fho6
public class RandomLongGenerator {
private final long min;
private final long max;
private RandomIntGenerator(long min, long max) {
this.min = min;
this.max = max;
}
public static RandomLongGenerator between(long max, long min) {
return new RandomLongGenerator(min, max);
}
public static RandomLongGenerator biggerThan(long min) {
return new RandomLongGenerator(min, Long.MAX_VALUE);
}
public static RandomLongGenerator smallerThan(int max) {
return new RandomLongGenerator(Long.MIN_VALUE, max);
}
public int next() {...}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment