Esempio n. 1
0
/**
 * 模拟委托的接口,对应C#中的委托Action(void -> void)
 *
 * @author Zhang Yifan
 */
@ParametersAreNonnullByDefault
public interface Action0 extends IDelegate {
  /** */
  void DoAction();

  /** */
  public static final TypeToken<Action0> ACTION0_TYPETOKEN = TypeToken.of(Action0.class);

  /** A Method object that represents the only method in Action0 interface. */
  public static final Invokable<Action0, Void> ACTION0_METHOD =
      Methods.TryGetFirstMethod(TypeToken.of(Action0.class), "DoAction")
          .get()
          .returning(void.class);

  // public static final Method ACTION0_METHOD = Methods.TryGetFirstMethod(Action0.class,
  // "DoAction").get();

  // public static final Invokable<Action0, Void> ACTION0_INVOKABLE =
  // ACTION0_TYPETOKEN.method(ACTION0_METHOD).returning(Void.class);
}
Esempio n. 2
0
/**
 * Represents the method that defines a set of criteria and determines whether the specified object
 * meets those criteria.
 *
 * @param <TIn> The type of the object to compare. This type parameter is contravariant. That is,
 *     you can use either the type you specified or any type that is less derived.
 * @author Zhang Yifan
 */
@FunctionalInterface
public interface Predicate<TIn>
    extends java.util.function.Predicate<TIn>, com.google.common.base.Predicate<TIn>, IDelegate {
  /**
   * Determines whether the specified object meets the criteria of this delegate.
   *
   * @param input The object to compare against the criteria defined within the method represented
   *     by this delegate.
   * @return true if obj meets the criteria defined within the method represented by this delegate;
   *     otherwise, false.
   */
  @CheckReturnValue
  boolean DoPredicate(TIn input);

  /**
   * Determines whether the specified object meets the criteria of this delegate.
   *
   * @param input The object to compare against the criteria defined within the method represented
   *     by this delegate.
   * @return true if obj meets the criteria defined within the method represented by this delegate;
   *     otherwise, false.
   */
  @Override
  @CheckReturnValue
  default boolean test(final TIn input) {
    return this.DoPredicate(input);
  }

  /**
   * Determines whether the specified object meets the criteria of this delegate.
   *
   * @param input The object to compare against the criteria defined within the method represented
   *     by this delegate.
   * @return true if obj meets the criteria defined within the method represented by this delegate;
   *     otherwise, false.
   */
  @Override
  @CheckReturnValue
  default boolean apply(final TIn input) {
    return this.DoPredicate(input);
  }

  // region Default methods that convert this function object(Predicate) to a function object of
  // other type.

  /**
   * Returns a {@link java.util.function.Function} that has the same functionality as this {@link
   * Predicate} instance (the returned instance wraps this {@link Predicate} instance).
   *
   * @see java.util.function.Function
   */
  @Pure
  @NoExcept
  @Nonnull
  @CheckReturnValue
  @Inline
  default <TInExt extends TIn> java.util.function.Function<TInExt, Boolean> ToFunction() {
    return input -> Boolean.valueOf(this.DoPredicate(input));
  }

  /**
   * Returns a {@link com.google.common.base.Function} that has the same functionality as this
   * {@link Predicate} instance (the returned instance wraps this {@link Predicate} instance).
   *
   * @see com.google.common.base.Function
   */
  @Pure
  @NoExcept
  @Nonnull
  @CheckReturnValue
  @Inline
  default <TInExt extends TIn> Function<TInExt, Boolean> ToGuavaFunction() {
    return input -> Boolean.valueOf(this.DoPredicate(input));
  }

  /**
   * Returns a {@link com.google.common.base.Function} that has the same functionality as this
   * {@link Predicate} instance (the returned instance wraps this {@link Predicate} instance).
   *
   * @see com.google.common.base.Function
   */
  @Pure
  @NoExcept
  @Nonnull
  @CheckReturnValue
  @Inline
  default <TInExt extends TIn> rx.functions.Func1<TInExt, Boolean> ToRXFuncion() {
    return input -> Boolean.valueOf(this.DoPredicate(input));
  }

  // endregion

  /** A Invokable object that represents the only method in Predicate interface. */
  @Nonnull
  @SuppressWarnings({"rawtypes", "unchecked"})
  Invokable<Predicate, Boolean> PREDICATE_METHOD =
      Methods.GetFirstMethod(TypeToken.of(Predicate.class), "DoPredicate").returning(boolean.class);

  // public static final Method PREDICATE_METHOD = Methods.TryGetFirstMethod(Predicate.class,
  // "DoPredicate").get();
}