Class Computers


  • public final class Computers
    extends Object
    Container class for computer-style functional interfaces at various arities.

    A computer has functional method compute with a number of arguments corresponding to the arity, plus an additional argument for the preallocated output to be populated by the computation.

    Each computer interface implements a corresponding Consumer-style interface (see Consumers) with arity+1; the consumer's accept method simply delegates to compute. This pattern allows computer ops to be used directly as consumers as needed.

    Author:
    Curtis Rueden, Gabriel Selzer
    • Field Detail

      • ALL_COMPUTERS

        public static final Class<?>[][] ALL_COMPUTERS
        All known computer types and their arities. The types are indexed, first by the number of pure inputs in their functional method, then by the (1-indexed) index of the preallocated output.

        Note that this data structure is populated at the bottom of the file, so it does not impede quick browsing of the functional interfaces

    • Method Detail

      • isComputer

        public static boolean isComputer​(Class<?> c)
        Returns:
        true if the given type is a known computer type, false otherwise.
        Note that only the type itself and not its type hierarchy is considered.
        Throws:
        NullPointerException - If c is null.
      • computerOfArity

        public static Class<?> computerOfArity​(int arity)
        Parameters:
        arity - an int corresponding to a Computer of that arity.
        Returns:
        the Computer of arity arity.
        Throws:
        IllegalArgumentException - iff there is no known Computer of arity arity.
      • computerOfArity

        public static Class<?> computerOfArity​(int arity,
                                               int pos)
        Parameters:
        arity - an int corresponding to a Computer of that arity.
        pos - an int corresponding to the position of the Computer's output
        Returns:
        the Computer of arity arity.
        Throws:
        IllegalArgumentException - iff there is no known Computer of arity arity.
      • arityOf

        public static int arityOf​(Class<?> c)
        Parameters:
        c - the Class of unknown arity
        Returns:
        the arity of c, or -1 if c is not a Computer.