Package org.openmuc.jeebus.spine.utils
Class Selectors
- java.lang.Object
-
- org.openmuc.jeebus.spine.utils.Selectors
-
public class Selectors extends java.lang.ObjectUtility class for working with selector types.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <DATA,SELECTOR>
booleandataMatchesAnySelector(DATA data, java.util.List<SELECTOR> selectorList, ListFeatureFunctionTypeInfo<DATA,?,SELECTOR,?> typeInfo)This method checks if the given data object matches any of the given selectors.static SpineExceptionerrorForIllegalSelectors(java.util.List<java.lang.Class<?>> illegalSelectors, java.lang.String expected)Generate a SpineException for illegal filter selectors.static <SELECTOR,ELEMENTS>
ReadListCmdOptiongetReadListCmdOption(java.util.List<SELECTOR> selectorList, ELEMENTS elements)static <DATA,SELECTOR>
java.util.Map<java.lang.Integer,DATA>getSelectedData(java.util.List<DATA> dataList, java.util.List<SELECTOR> selectorList, ListFeatureFunctionTypeInfo<DATA,?,SELECTOR,?> typeInfo)Takes a list of selectors and a list of fitting data class objects (e.g.static <V> booleanselectorFits(V selector, V actual)This method simplifies checking if values fit for a given selector.static <T> Pair<java.util.List<java.lang.Class<?>>,java.util.List<T>>splitByType(java.util.List<? super T> elements, java.lang.Class<? extends T> selectorClass)Splits given list into two new lists: elements of given type, and classes of elements that didn't match.
-
-
-
Method Detail
-
selectorFits
public static <V> boolean selectorFits(V selector, V actual)This method simplifies checking if values fit for a given selector. If a selectorValue is null it is seen as not set and thus returns true.- Type Parameters:
V- must be the same type- Parameters:
selector- the value of the selectoractual- the value of the element to compare to- Returns:
- true if selector fits or if selector value is null
-
splitByType
public static <T> Pair<java.util.List<java.lang.Class<?>>,java.util.List<T>> splitByType(java.util.List<? super T> elements, java.lang.Class<? extends T> selectorClass)
Splits given list into two new lists: elements of given type, and classes of elements that didn't match.- Type Parameters:
T- Type of elements to search for.- Parameters:
elements- List to search throughselectorClass- class to search for- Returns:
- Classes of elements that didn't match, and elements that were found. Either or both might be empty.
-
errorForIllegalSelectors
public static SpineException errorForIllegalSelectors(java.util.List<java.lang.Class<?>> illegalSelectors, java.lang.String expected)
Generate a SpineException for illegal filter selectors.- Parameters:
illegalSelectors- the list of illegal filter selectorsexpected- the type of selector we were expecting- Returns:
- a SpineException complaining about illegal filter selectors, or null if there were none.
-
dataMatchesAnySelector
public static <DATA,SELECTOR> boolean dataMatchesAnySelector(DATA data, java.util.List<SELECTOR> selectorList, ListFeatureFunctionTypeInfo<DATA,?,SELECTOR,?> typeInfo)This method checks if the given data object matches any of the given selectors. A match is defined by following conditions:- The given
AdditionalSelectorConditionreturns true. - For all attributes of the selector the
propertyMatchesSelector(java.beans.PropertyDescriptor, SELECTOR, DATA, java.lang.Class<DATA>)method returns true.
- Type Parameters:
DATA- type of data to checkSELECTOR- type of selector to check with- Parameters:
data- the data object to checkselectorList- list of selectors to usetypeInfo- RTTI object- Returns:
- true if the given data object matches any of the given selectors
- The given
-
getSelectedData
public static <DATA,SELECTOR> java.util.Map<java.lang.Integer,DATA> getSelectedData(java.util.List<DATA> dataList, java.util.List<SELECTOR> selectorList, ListFeatureFunctionTypeInfo<DATA,?,SELECTOR,?> typeInfo)Takes a list of selectors and a list of fitting data class objects (e.g. List ofMeasurementDescriptionListDataSelectorsType) andMeasurementDescriptionDataType). Returns a map of data with its indices for the given data objects with all the data objects that fit for at least one of the selectors.- Type Parameters:
DATA- type of data to select fromSELECTOR- type of selector to use- Parameters:
dataList- list of data to select fromselectorList- list of selectorstypeInfo- RTTI object- Returns:
- map of the given data types with its indices that fit at least one selector
-
getReadListCmdOption
public static <SELECTOR,ELEMENTS> ReadListCmdOption getReadListCmdOption(java.util.List<SELECTOR> selectorList, ELEMENTS elements)
-
-