class Matchers {

  static <P> Matcher[] toArray(Iterable<? extends Matcher<P>> matchers) {
    if (matchers == null) throw new NullPointerException("matchers == null");
    if (matchers instanceof Collection) {
      return (Matcher[]) ((Collection) matchers).toArray(new Matcher[0]);
    }
    List<Matcher<P>> result = new ArrayList<>();
    for (Matcher<P> matcher : matchers) result.add(matcher);
    return result.toArray(new Matcher[0]);
  }

}