Class Inplaces


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

    An inplace has functional method mutate with a number of arguments corresponding to the arity. Any of the arguments annotated with @Mutable may be mutated during execution. Some interfaces narrow this behavior to only a specific argument; most ops in practice will implement one of these narrowed interfaces. For example, Inplaces.Arity2_1 is a binary inplace op that mutates the first of two arguments—e.g., an a /= b division operation would be an Inplaces.Arity2_1, whereas b = a / b would be an Inplaces.Arity2_2.

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

    Note that there is no nullary (arity 0) inplace interface, because there would be no arguments to mutate; see also Consumers.Arity0, Computers.Arity0 and Producer.

    Author:
    Curtis Rueden, Gabriel Selzer
    • Field Detail

      • ALL_INPLACES

        public static final Map<Inplaces.InplaceInfo,​Class<?>> ALL_INPLACES
        All known inplace types and their arities and mutable positions. The entries are sorted by arity and mutable position.
    • Method Detail

      • isInplace

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

        public static Class<?> inplaceOfArity​(int arity,
                                              int mutableIndex)
        Parameters:
        arity - an int corresponding to a Inplace of that arity.
        mutableIndex - an int corresponding to a the mutable index of d arity.
        Returns:
        the Inplace of arity arity.
        Throws:
        IllegalArgumentException - iff there is no known Inplace of arity arity.
      • arityOf

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