Class MdibTypeValidator


  • public class MdibTypeValidator
    extends Object
    Utility class to validate MDIB instances.
    • Method Detail

      • resolveDescriptorBaseName

        public String resolveDescriptorBaseName​(Class<? extends AbstractDescriptor> descrClass)
        Gets the base name of a descriptor class. The base name is the name of the class without Descriptor suffix.
        Parameters:
        descrClass - the class where to resolve the base name from.
        Returns:
        the base name.
      • resolveStateBaseName

        public String resolveStateBaseName​(Class<? extends AbstractState> stateClass)
        Gets the base name of a state class. The base name is the name of the class without State suffix.
        Parameters:
        stateClass - the class where to resolve the base name from.
        Returns:
        the base name.
      • match

        public boolean match​(Class<? extends AbstractDescriptor> descrClass,
                             Class<? extends AbstractState> stateClass)
        Checks if descriptor and state classes match.

        A match is given if both classes do not implement the abstract flavor and share the same name prefix excluding the Descriptor and State suffix.

        Parameters:
        descrClass - the descriptor class to match.
        stateClass - the state class to match.
        Returns:
        true if classes match, otherwise false.
      • match

        public <D extends AbstractDescriptor,​S extends AbstractState> boolean match​(D descriptor,
                                                                                          List<S> states)
        Checks if the given descriptor states pairing is valid.

        A match is given if

        Type Parameters:
        D - any descriptor class.
        S - any state class.
        Parameters:
        descriptor - the descriptor to test.
        states - the list of states to test.
        Returns:
        true if instances match, otherwise false.
      • match

        public <D extends AbstractDescriptor,​S extends AbstractState> boolean match​(D descriptor,
                                                                                          S state)
        Tries to match a descriptor with exactly one state.

        Hint: does also work for multi-state lists of size 1.

        Type Parameters:
        D - any descriptor class.
        S - any state class.
        Parameters:
        descriptor - the descriptor to test.
        state - the state to test.
        Returns:
        true if descriptor and state match, otherwise false.
        See Also:
        match(AbstractDescriptor, List)
      • isSingleStateDescriptor

        public <T extends AbstractDescriptor> boolean isSingleStateDescriptor​(T descriptor)
        Checks if a descriptor is a single state descriptor (true) or not (false).
        Type Parameters:
        T - any descriptor class.
        Parameters:
        descriptor - the descriptor to test.
        Returns:
        true if the descriptor is a single state descriptor, false otherwise.
      • isSingleState

        public <T extends AbstractState> boolean isSingleState​(T state)
        Checks if a state is a single state (true) or not (false).
        Type Parameters:
        T - any state class.
        Parameters:
        state - the state to test.
        Returns:
        true if the state is a single state, false otherwise.
      • isMultiStateDescriptor

        public <T extends AbstractDescriptor> boolean isMultiStateDescriptor​(T descriptor)
        Checks if a descriptor is a multi-state descriptor (true) or not (false).
        Type Parameters:
        T - any descriptor class.
        Parameters:
        descriptor - the descriptor to test.
        Returns:
        true if the descriptor is a multi-state descriptor, false otherwise.
      • isMultiState

        public <T extends AbstractState> boolean isMultiState​(T state)
        Checks if a state is a multi-state (true) or not (false).
        Type Parameters:
        T - any state class.
        Parameters:
        state - the state to test.
        Returns:
        true if the state is a multi-state, false otherwise.
      • isContextState

        public <T extends AbstractState> boolean isContextState​(T state)
        Checks if a state is a context state (true) or not (false).
        Type Parameters:
        T - any state class.
        Parameters:
        state - the state to test.
        Returns:
        true if the state is a context state, false otherwise.
      • toMultiState

        public <T extends AbstractStateOptional<AbstractMultiState> toMultiState​(T state)
        Tries to cast to a multi-state.
        Type Parameters:
        T - any state class.
        Parameters:
        state - the state to cast.
        Returns:
        The cast multi-state or Optional.empty() if the state was not a multi-state.
      • toContextState

        public <T extends AbstractStateOptional<AbstractContextState> toContextState​(T state)
        Tries to cast to a context state.
        Type Parameters:
        T - any state class.
        Parameters:
        state - the state to cast.
        Returns:
        The cast multi-state or Optional.empty() if the state was not a multi-state.
      • resolveDescriptorType

        public <T extends AbstractState,​V extends AbstractDescriptorClass<V> resolveDescriptorType​(Class<T> stateClass)
                                                                                                    throws ClassNotFoundException
        Resolves the descriptor type belonging to a state type.
        Type Parameters:
        T - a state type
        V - a descriptor type
        Parameters:
        stateClass - to resolve the descriptor type for
        Returns:
        the descriptor type matching the passed state
        Throws:
        ClassNotFoundException - if no matching descriptor class has been found
      • resolveStateType

        public <T extends AbstractDescriptor,​V extends AbstractStateClass<V> resolveStateType​(Class<T> descriptorClass)
                                                                                               throws ClassNotFoundException
        Resolves the state type belonging to a descriptor type.
        Type Parameters:
        T - a descriptor type
        V - a state type
        Parameters:
        descriptorClass - to resolve the state type for
        Returns:
        the state type matching the passed descriptor
        Throws:
        ClassNotFoundException - if no matching state class has been found