示例#1
0
  /**
   * returns actions by a class
   *
   * @note class must be an inheritance of the IAgent interface
   * @param p_class class list
   * @return action stream
   */
  @SuppressWarnings("unchecked")
  public static Stream<IAction> actionsFromAgentClass(final Class<?>... p_class) {
    return p_class == null || p_class.length == 0
        ? Stream.of()
        : Arrays.stream(p_class)
            .parallel()
            .filter(IAgent.class::isAssignableFrom)
            .flatMap(i -> CCommon.methods(i, i))
            .map(
                i -> {
                  try {
                    return (IAction) new CMethodAction(i);
                  } catch (final IllegalAccessException l_exception) {
                    LOGGER.warning(
                        CCommon.languagestring(CCommon.class, "actioninstantiate", i, l_exception));
                    return null;
                  }
                })

            // action can be instantiate
            .filter(Objects::nonNull)

            // check usable action name
            .filter(CCommon::actionusable);
  }