Class ContextDefinition<V>

    • Method Detail

      • createValue

        public final ContextValue<VcreateValue​(V value)
        Create a new context value based on this definition.
        Parameters:
        value - the value to associate with this definition
        Returns:
        a new context value holder
        Since:
        2.0.0
      • name

        public final String name()
        Gets the name for this context definition.
        Returns:
        the definition name
        Since:
        2.0.0
      • serialize

        public abstract String serialize​(V canonicalValue)
        Given a parsed value, write data out as a string.
        Parameters:
        canonicalValue - Parsed value
        Returns:
        serialized form of the value
        Since:
        2.0.0
      • deserialize

        public abstract @Nullable V deserialize​(String userValue)
        Given a string (which may be in user format), return a parsed object.
        Parameters:
        userValue - the value as a string, such as when provided by user input
        Returns:
        V a deserialized value, or null if unsuccessful
        Since:
        2.0.0
      • matches

        public final boolean matches​(ContextValue<V> ctx,
                                     V activeValue)
        Given a defined context and the active value (provided by accumulateCurrentValues(CalculatedSubject, Consumer)), return whether the active value matches the defined value.
        Parameters:
        ctx - a defined context
        activeValue - a value to test for membership in ctx
        Returns:
        whether a match was found
        Since:
        2.0.0
      • matches

        public boolean matches​(V ownVal,
                               V testVal)
        Get whether two values match.
        Parameters:
        ownVal - the defined value
        testVal - the value being tested against
        Returns:
        whether testVal is an element of ownVal
      • accumulateCurrentValues

        public abstract void accumulateCurrentValues​(CalculatedSubject subject,
                                                     Consumer<V> consumer)
        Given a player, calculate active context types
        Parameters:
        subject - The subject active contexts are being calculated for
        consumer - A function that will take the returned value and add it to the active context set
        Since:
        2.0.0
      • suggestValues

        public Set<VsuggestValues​(CalculatedSubject subject)
        Given a subject, suggest a set of values that may be valid for this context. This need not be an exhaustive list, or could even be an empty list, but allows providing users possible suggestions to what sensible values for a context may be.
        Parameters:
        subject - a subject to query for environment information
        Returns:
        a set of possible values
        Since:
        2.0.0