Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public final class ShapesIntersection implements Maybe<Rectangle> {
- public ShapesIntersection(Shape a, Shape b) {
- this.a = a;
- this.b = b;
- }
- @Override
- public boolean isPresent() {
- // find out if shapes intersect
- }
- @Override
- public Rectangle get() {
- // find the common piece of two shapes
- }
- }
- public inteface Maybe<T> {
- T get();
- boolean isPresent();
- default Optional<T> asOptional() {
- return isPresent() ?
- Optional.of(get()) :
- Optional.empty();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement