Class Selectors


  • public class Selectors
    extends java.lang.Object
    Utility class for working with selector types.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      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.
      static SpineException errorForIllegalSelectors​(java.util.List<java.lang.Class<?>> illegalSelectors, java.lang.String expected)
      Generate a SpineException for illegal filter selectors.
      static <SELECTOR,​ELEMENTS>
      ReadListCmdOption
      getReadListCmdOption​(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> boolean selectorFits​(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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 selector
        actual - 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 through
        selectorClass - 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 selectors
        expected - 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:
        1. The given AdditionalSelectorCondition returns true.
        2. 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 check
        SELECTOR - type of selector to check with
        Parameters:
        data - the data object to check
        selectorList - list of selectors to use
        typeInfo - RTTI object
        Returns:
        true if the given data object matches any of the given selectors
      • 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 of MeasurementDescriptionListDataSelectorsType) and MeasurementDescriptionDataType). 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 from
        SELECTOR - type of selector to use
        Parameters:
        dataList - list of data to select from
        selectorList - list of selectors
        typeInfo - 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)