Package org.somda.sdc.biceps.common
Class MdibTypeValidator
- java.lang.Object
-
- org.somda.sdc.biceps.common.MdibTypeValidator
-
public class MdibTypeValidator extends Object
Utility class to validate MDIB instances.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends AbstractState>
booleanisContextState(T state)Checks if a state is a context state (true) or not (false).<T extends AbstractState>
booleanisMultiState(T state)Checks if a state is a multi-state (true) or not (false).<T extends AbstractDescriptor>
booleanisMultiStateDescriptor(T descriptor)Checks if a descriptor is a multi-state descriptor (true) or not (false).<T extends AbstractState>
booleanisSingleState(T state)Checks if a state is a single state (true) or not (false).<T extends AbstractDescriptor>
booleanisSingleStateDescriptor(T descriptor)Checks if a descriptor is a single state descriptor (true) or not (false).<D extends AbstractDescriptor,S extends AbstractState>
booleanmatch(D descriptor, List<S> states)Checks if the given descriptor states pairing is valid.<D extends AbstractDescriptor,S extends AbstractState>
booleanmatch(D descriptor, S state)Tries to match a descriptor with exactly one state.booleanmatch(Class<? extends AbstractDescriptor> descrClass, Class<? extends AbstractState> stateClass)Checks if descriptor and state classes match.StringresolveDescriptorBaseName(Class<? extends AbstractDescriptor> descrClass)Gets the base name of a descriptor class.<T extends AbstractState,V extends AbstractDescriptor>
Class<V>resolveDescriptorType(Class<T> stateClass)Resolves the descriptor type belonging to a state type.StringresolveStateBaseName(Class<? extends AbstractState> stateClass)Gets the base name of a state class.<T extends AbstractDescriptor,V extends AbstractState>
Class<V>resolveStateType(Class<T> descriptorClass)Resolves the state type belonging to a descriptor type.<T extends AbstractState>
Optional<AbstractContextState>toContextState(T state)Tries to cast to a context state.<T extends AbstractState>
Optional<AbstractMultiState>toMultiState(T state)Tries to cast to a multi-state.
-
-
-
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
- descriptor and states match in terms of
match(Class, Class), AbstractState.getDescriptorHandle()equalsAbstractDescriptor.getHandle(), and- single state descriptors do correspond to exactly one state.
- 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.
- descriptor and states match in terms of
-
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 AbstractState> Optional<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 AbstractState> Optional<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 AbstractDescriptor> Class<V> resolveDescriptorType(Class<T> stateClass) throws ClassNotFoundException
Resolves the descriptor type belonging to a state type.- Type Parameters:
T- a state typeV- 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 AbstractState> Class<V> resolveStateType(Class<T> descriptorClass) throws ClassNotFoundException
Resolves the state type belonging to a descriptor type.- Type Parameters:
T- a descriptor typeV- 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
-
-