/** * Value pattern, checks for equality. * * @param <T> type of the prototype * @param prototype the value that should be equal to the underlying object * @return a new {@code Pattern0} instance */ @GwtIncompatible public static <T> Pattern0<T> $(T prototype) { return new Pattern0<T>() { private static final long serialVersionUID = 1L; @Override public T apply(T obj) { return obj; } @Override public boolean isDefinedAt(T obj) { return Objects.equals(obj, prototype); } }; }
/** * Shortcut for {@code System.out.printf(format, args)}. See {@link PrintStream#printf(String, Object...)}. * * @param format A format string as described in {@link Formatter}. * @param args Arguments referenced by the format specifiers */ @GwtIncompatible public static void printf(String format, Object... args) { System.out.printf(format, args); }
/** * Sends the string representations of this to the {@link PrintWriter}. * If this value consists of multiple elements, each element is displayed in a new line. * * @param writer The PrintWriter to write to * @throws IllegalStateException if {@code PrintWriter.checkError()} is true after writing to writer. */ @GwtIncompatible("java.io.PrintWriter is not implemented") default void out(PrintWriter writer) { for (T t : this) { writer.println(String.valueOf(t)); if (writer.checkError()) { throw new IllegalStateException("Error writing to PrintWriter"); } } }
@GwtIncompatible public static <T, R> Case<T, R> Case(Pattern0<T> pattern, Function<? super T, ? extends R> f) { Objects.requireNonNull(pattern, "pattern is null"); Objects.requireNonNull(f, "f is null"); return new Case0<>(pattern, f); }
@GwtIncompatible public static <T, T1, T2, T3, R> Case<T, R> Case(Pattern3<T, T1, T2, T3> pattern, Supplier<? extends R> supplier) { Objects.requireNonNull(pattern, "pattern is null"); Objects.requireNonNull(supplier, "supplier is null"); return new Case3<>(pattern, (_1, _2, _3) -> supplier.get()); }
@GwtIncompatible public static <T, T1, T2, T3, T4, R> Case<T, R> Case(Pattern4<T, T1, T2, T3, T4> pattern, R retVal) { Objects.requireNonNull(pattern, "pattern is null"); return new Case4<>(pattern, (_1, _2, _3, _4) -> retVal); }
@GwtIncompatible public static <T, R> Case<T, R> Case(Pattern0<T> pattern, Supplier<? extends R> supplier) { Objects.requireNonNull(pattern, "pattern is null"); Objects.requireNonNull(supplier, "supplier is null"); return new Case0<>(pattern, ignored -> supplier.get()); }
@GwtIncompatible public static <T, T1, T2, R> Case<T, R> Case(Pattern2<T, T1, T2> pattern, Supplier<? extends R> supplier) { Objects.requireNonNull(pattern, "pattern is null"); Objects.requireNonNull(supplier, "supplier is null"); return new Case2<>(pattern, (_1, _2) -> supplier.get()); }
@GwtIncompatible public static <T, T1, T2, T3, R> Case<T, R> Case(Pattern3<T, T1, T2, T3> pattern, Function3<? super T1, ? super T2, ? super T3, ? extends R> f) { Objects.requireNonNull(pattern, "pattern is null"); Objects.requireNonNull(f, "f is null"); return new Case3<>(pattern, f); }
@GwtIncompatible public static <T, T1, T2, T3, T4, T5, R> Case<T, R> Case(Pattern5<T, T1, T2, T3, T4, T5> pattern, Supplier<? extends R> supplier) { Objects.requireNonNull(pattern, "pattern is null"); Objects.requireNonNull(supplier, "supplier is null"); return new Case5<>(pattern, (_1, _2, _3, _4, _5) -> supplier.get()); }
@GwtIncompatible public static <T, T1, T2, T3, T4, T5, T6, T7, R> Case<T, R> Case(Pattern7<T, T1, T2, T3, T4, T5, T6, T7> pattern, Supplier<? extends R> supplier) { Objects.requireNonNull(pattern, "pattern is null"); Objects.requireNonNull(supplier, "supplier is null"); return new Case7<>(pattern, (_1, _2, _3, _4, _5, _6, _7) -> supplier.get()); }
@GwtIncompatible public static <T, T1, T2, T3, T4, T5, T6, T7, T8, R> Case<T, R> Case(Pattern8<T, T1, T2, T3, T4, T5, T6, T7, T8> pattern, Supplier<? extends R> supplier) { Objects.requireNonNull(pattern, "pattern is null"); Objects.requireNonNull(supplier, "supplier is null"); return new Case8<>(pattern, (_1, _2, _3, _4, _5, _6, _7, _8) -> supplier.get()); }
@GwtIncompatible public static <T, T1, R> Case<T, R> Case(Pattern1<T, T1> pattern, Function<? super T1, ? extends R> f) { Objects.requireNonNull(pattern, "pattern is null"); Objects.requireNonNull(f, "f is null"); return new Case1<>(pattern, f); }
@GwtIncompatible public static <T, T1, T2, T3, T4, R> Case<T, R> Case(Pattern4<T, T1, T2, T3, T4> pattern, Supplier<? extends R> supplier) { Objects.requireNonNull(pattern, "pattern is null"); Objects.requireNonNull(supplier, "supplier is null"); return new Case4<>(pattern, (_1, _2, _3, _4) -> supplier.get()); }
@GwtIncompatible public static <T, T1, T2, T3, T4, T5, R> Case<T, R> Case(Pattern5<T, T1, T2, T3, T4, T5> pattern, R retVal) { Objects.requireNonNull(pattern, "pattern is null"); return new Case5<>(pattern, (_1, _2, _3, _4, _5) -> retVal); }
@GwtIncompatible public static <T, T1, T2, T3, T4, T5, T6, R> Case<T, R> Case(Pattern6<T, T1, T2, T3, T4, T5, T6> pattern, Supplier<? extends R> supplier) { Objects.requireNonNull(pattern, "pattern is null"); Objects.requireNonNull(supplier, "supplier is null"); return new Case6<>(pattern, (_1, _2, _3, _4, _5, _6) -> supplier.get()); }
@GwtIncompatible public static <T, T1, T2, T3, T4, T5, T6, T7, R> Case<T, R> Case(Pattern7<T, T1, T2, T3, T4, T5, T6, T7> pattern, Function7<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? extends R> f) { Objects.requireNonNull(pattern, "pattern is null"); Objects.requireNonNull(f, "f is null"); return new Case7<>(pattern, f); }
@GwtIncompatible public static <T, T1, T2, T3, T4, T5, T6, T7, T8, R> Case<T, R> Case(Pattern8<T, T1, T2, T3, T4, T5, T6, T7, T8> pattern, R retVal) { Objects.requireNonNull(pattern, "pattern is null"); return new Case8<>(pattern, (_1, _2, _3, _4, _5, _6, _7, _8) -> retVal); }
/** * Sends the string representations of this to the standard error stream {@linkplain System#err}. * If this value consists of multiple elements, each element is displayed in a new line. * * @throws IllegalStateException if {@code PrintStream.checkError()} is true after writing to stderr. */ @GwtIncompatible("java.io.PrintStream is not implemented") default void stderr() { out(System.err); }
/** * Entry point of the match API. * * @param value a value to be matched * @param <T> type of the value * @return a new {@code Match} instance */ @GwtIncompatible public static <T> Match<T> Match(T value) { return new Match<>(value); }