6

Is there a library out there that already provides the interfaces we need for the command pattern in Java?

For example:

 public interface Func1<T,R> { public R execute(T input); }

 public interface Func2<T1,T2,R> { public R execute(T1 input1, T2 input2); }

 public interface Predicate1<T> { public boolean execute(T input); }

 ....

Thanks.

2
  • 4
    This doesn't look like a command pattern library, this looks like a functional programming library. Commented May 1, 2012 at 22:05
  • 1
    Try Guava, they have Predicate and might also have those others. Commented May 1, 2012 at 22:06

1 Answer 1

6

Guava has your first and third interfaces (called Function and Predicate). Your second one, IMHO, is not useful, because you would just have to combine T1 and T2 in a single object, and use the first interface instead.

More interesting, Guava also has a whole lot of methods using these two interfaces, like Iterables.any(Iterable, Predicate), Iterables.transform(Iterable, Function), etc.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.