Class DataMappingUtils


  • public class DataMappingUtils
    extends java.lang.Object
    The type Data mapping utils.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int FIRST
      The constant FIRST.
      static int LAST
      The constant LAST.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean all​(java.lang.String[] records)
      All boolean.
      static boolean checkRange​(java.util.List<?> values, java.util.List<java.lang.Integer> range)
      Check range boolean.
      static java.util.List<java.lang.String> emptyList()
      Empty list list.
      static void failIfInputEmpty​(java.lang.Object caller, java.util.List<?> in)
      Fail if input empty.
      static void failIfSizeDiffer​(java.lang.Object caller, java.util.List<?> input, java.util.List<?> output, java.lang.String entityModelIdentifier, java.lang.String entityId, java.lang.String parentBucketId, java.lang.String recordGroupIdentifier, java.lang.String resultEntityId, Context context, java.lang.String searchStr)
      Fail if size differ.
      static <T> void failIfTargetEmpty​(java.lang.Object caller, T target, java.lang.Class<?> clazz, java.lang.String entityModelIdentifier, java.lang.String entityId, java.lang.String parentBucketId, java.lang.String recordGroupIdentifier, java.lang.String resultEntityId, Context context, java.lang.String searchStr, int... range)
      Fail if target empty.
      static java.util.List<KeyValue> filterByKey​(java.util.List<KeyValue> values, java.lang.String key)
      Filter by key list.
      static java.lang.String getDelimiter​(java.lang.String delimiter, int pos, int size)
      Adds delimiter after each but not the last element of the returned string
      static <T> T getListElement​(java.util.List<T> input, int index)
      Gets list element.
      static MediaObject getMediaObjectByTypeAndMedia​(MediaAsset asset, java.lang.String type, java.lang.String media)
      Gets media object by type and media.
      static <T> T getNthOf​(java.util.List<T> in, int nth)
      Gets nth of.
      static <T> T getNthOf​(T[] in, int nth)
      Gets nth of.
      static java.util.List<java.lang.Integer> getRecordIndexList​(java.lang.String[] record, int listSize)
      Returns list of indexes
      static <T> java.util.List<T> getSubList​(java.util.List<T> values, java.util.List<java.lang.Integer> range)
      Gets sub list.
      static java.lang.Integer getZBasedIndex​(int pos, int listSize)
      Returns index of the requested record
      static java.lang.String listSize​(java.util.List<?> list)
      List size string.
      static java.util.List<java.lang.Integer> parseNumberList​(java.lang.String input)
      Parse number list list.
      static java.util.List<java.lang.Integer> parseNumberList​(java.lang.String input, char fieldSeparator)
      Parse number list list.
      static java.util.List<java.lang.String> parseQuotedList​(java.lang.String input)
      Parse quoted list list.
      static java.util.List<java.lang.String> parseQuotedList​(java.lang.String input, char fieldSeparator, char fieldDelimiter)
      Parse quoted list list.
      static java.lang.String popFront​(java.lang.String from, java.lang.String prefix)
      Pop front string.
      static java.lang.String popTail​(java.lang.String from, java.lang.String suffix)
      Pop tail string.
      static java.util.List<java.lang.Integer> processRange​(java.util.List<?> values, java.lang.String input)
      Process range list.
      static java.lang.String range​(int... range)
      Range string.
      static <T> T requireNthOf​(java.util.List<T> in, int nth)
      Require nth of t.
      static <T> T requireNthOf​(T[] in, int nth)
      Require nth of t.
      static java.lang.String[] split​(java.lang.String value, java.lang.String separator)
      Split string [ ].
      static java.util.List<java.lang.String> stringList​(java.lang.String... strings)
      Converts a string array or several strings to a string list
      static java.lang.String toString​(java.lang.String input)
      Returns the string given or empty string if null was given.
      static boolean validList​(java.lang.String[] records)
      Validates correctness of the requested records list, list can contain positive and negative Integers, or the String 'all'
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • emptyList

        public static java.util.List<java.lang.String> emptyList()
        Empty list list.
        Returns:
        a String List containing one (empty) string
      • stringList

        public static java.util.List<java.lang.String> stringList​(java.lang.String... strings)

        Converts a string array or several strings to a string list

        Parameters:
        strings - zero, one or more strings
        Returns:
        a string list containing all strings provided as argument
      • getListElement

        public static <T> T getListElement​(java.util.List<T> input,
                                           int index)
        Gets list element.
        Type Parameters:
        T - the type parameter
        Parameters:
        input - the input
        index - the index
        Returns:
        the list element
      • processRange

        public static java.util.List<java.lang.Integer> processRange​(java.util.List<?> values,
                                                                     java.lang.String input)
        Process range list.
        Parameters:
        values - the values
        input - the input
        Returns:
        the list
      • getSubList

        public static <T> java.util.List<T> getSubList​(java.util.List<T> values,
                                                       java.util.List<java.lang.Integer> range)
        Gets sub list.
        Type Parameters:
        T - the type parameter
        Parameters:
        values - the values
        range - the range
        Returns:
        the sub list
      • checkRange

        public static boolean checkRange​(java.util.List<?> values,
                                         java.util.List<java.lang.Integer> range)
        Check range boolean.
        Parameters:
        values - the values
        range - the range
        Returns:
        the boolean
      • getRecordIndexList

        public static java.util.List<java.lang.Integer> getRecordIndexList​(java.lang.String[] record,
                                                                           int listSize)
        Returns list of indexes
        Parameters:
        record - list of requested records, delimited by ',' (comma), can contain
        • string 'all' whole list will be returned
        • positive numbers - returns, value decremented by one e.g 1 will return index of 0
        • negative numbers - returns element count from the end of the list, e.g -1 will return index of the last element
        • 0 (zero) - returns index of the first element, the same result as 1
        listSize - length of list from which records are requested
        Returns:
        list of indexes from the parameter list, requested by record
      • validList

        public static boolean validList​(java.lang.String[] records)
        Validates correctness of the requested records list, list can contain positive and negative Integers, or the String 'all'
        Parameters:
        records - array of values to be checked
        Returns:
        true if text is not null and is not empty and all values are correct
      • getDelimiter

        public static java.lang.String getDelimiter​(java.lang.String delimiter,
                                                    int pos,
                                                    int size)
        Adds delimiter after each but not the last element of the returned string
        Parameters:
        delimiter - delimiter to be added
        pos - position of the element, when 0 (zero) returns empty string
        size - number of all elements in the list
        Returns:
        delimiter or empty stringreturn (pos == 0 ? "" : (pos + 1 < size ? delimiter : ""));
      • parseQuotedList

        public static java.util.List<java.lang.String> parseQuotedList​(java.lang.String input,
                                                                       char fieldSeparator,
                                                                       char fieldDelimiter)
        Parse quoted list list.
        Parameters:
        input - the input
        fieldSeparator - the field separator
        fieldDelimiter - the field delimiter
        Returns:
        the list
      • parseQuotedList

        public static java.util.List<java.lang.String> parseQuotedList​(java.lang.String input)
        Parse quoted list list.
        Parameters:
        input - the input
        Returns:
        the list
      • parseNumberList

        public static java.util.List<java.lang.Integer> parseNumberList​(java.lang.String input,
                                                                        char fieldSeparator)
        Parse number list list.
        Parameters:
        input - the input
        fieldSeparator - the field separator
        Returns:
        the list
      • parseNumberList

        public static java.util.List<java.lang.Integer> parseNumberList​(java.lang.String input)
        Parse number list list.
        Parameters:
        input - the input
        Returns:
        the list
      • toString

        public static java.lang.String toString​(java.lang.String input)
        Returns the string given or empty string if null was given.

        Use this to prevent Null Pointer Exceptions.

        Parameters:
        input - the input
        Returns:
        string
      • getNthOf

        public static <T> T getNthOf​(java.util.List<T> in,
                                     int nth)
        Gets nth of.
        Type Parameters:
        T - the type parameter
        Parameters:
        in - the in
        nth - the nth
        Returns:
        the nth of
      • getNthOf

        public static <T> T getNthOf​(T[] in,
                                     int nth)
        Gets nth of.
        Type Parameters:
        T - the type parameter
        Parameters:
        in - the in
        nth - the nth
        Returns:
        the nth of
      • requireNthOf

        public static <T> T requireNthOf​(T[] in,
                                         int nth)
                                  throws PubServerException
        Require nth of t.
        Type Parameters:
        T - the type parameter
        Parameters:
        in - the in
        nth - the nth
        Returns:
        the t
        Throws:
        PubServerException - the pub server exception
      • requireNthOf

        public static <T> T requireNthOf​(java.util.List<T> in,
                                         int nth)
                                  throws PubServerException
        Require nth of t.
        Type Parameters:
        T - the type parameter
        Parameters:
        in - the in
        nth - the nth
        Returns:
        the t
        Throws:
        PubServerException - the pub server exception
      • filterByKey

        public static java.util.List<KeyValue> filterByKey​(java.util.List<KeyValue> values,
                                                           java.lang.String key)
        Filter by key list.
        Parameters:
        values - the values
        key - the key
        Returns:
        the list
      • split

        public static java.lang.String[] split​(java.lang.String value,
                                               java.lang.String separator)
        Split string [ ].
        Parameters:
        value - the value
        separator - the separator
        Returns:
        the string [ ]
      • popFront

        public static java.lang.String popFront​(java.lang.String from,
                                                java.lang.String prefix)
        Pop front string.
        Parameters:
        from - the from
        prefix - the prefix
        Returns:
        the string
      • popTail

        public static java.lang.String popTail​(java.lang.String from,
                                               java.lang.String suffix)
        Pop tail string.
        Parameters:
        from - the from
        suffix - the suffix
        Returns:
        the string
      • failIfInputEmpty

        public static void failIfInputEmpty​(java.lang.Object caller,
                                            java.util.List<?> in)
                                     throws PubServerException
        Fail if input empty.
        Parameters:
        caller - the caller
        in - the in
        Throws:
        PubServerException - the pub server exception
      • failIfTargetEmpty

        public static <T> void failIfTargetEmpty​(java.lang.Object caller,
                                                 T target,
                                                 java.lang.Class<?> clazz,
                                                 java.lang.String entityModelIdentifier,
                                                 java.lang.String entityId,
                                                 java.lang.String parentBucketId,
                                                 java.lang.String recordGroupIdentifier,
                                                 java.lang.String resultEntityId,
                                                 Context context,
                                                 java.lang.String searchStr,
                                                 int... range)
                                          throws PubServerException
        Fail if target empty.
        Type Parameters:
        T - the type parameter
        Parameters:
        caller - the caller
        target - the target
        clazz - the clazz
        entityModelIdentifier - the entity model identifier
        entityId - the entity id
        parentBucketId - the parent bucket id
        recordGroupIdentifier - the record group identifier
        resultEntityId - the result entity id
        context - the context
        searchStr - the search str
        range - the range
        Throws:
        PubServerException - the pub server exception
      • listSize

        public static java.lang.String listSize​(java.util.List<?> list)
        List size string.
        Parameters:
        list - the list
        Returns:
        the string
      • failIfSizeDiffer

        public static void failIfSizeDiffer​(java.lang.Object caller,
                                            java.util.List<?> input,
                                            java.util.List<?> output,
                                            java.lang.String entityModelIdentifier,
                                            java.lang.String entityId,
                                            java.lang.String parentBucketId,
                                            java.lang.String recordGroupIdentifier,
                                            java.lang.String resultEntityId,
                                            Context context,
                                            java.lang.String searchStr)
                                     throws PubServerException
        Fail if size differ.
        Parameters:
        caller - the caller
        input - the input
        output - the output
        entityModelIdentifier - the entity model identifier
        entityId - the entity id
        parentBucketId - the parent bucket id
        recordGroupIdentifier - the record group identifier
        resultEntityId - the result entity id
        context - the context
        searchStr - the search str
        Throws:
        PubServerException - the pub server exception
      • range

        public static java.lang.String range​(int... range)
        Range string.
        Parameters:
        range - the range
        Returns:
        the string
      • all

        public static boolean all​(java.lang.String[] records)
        All boolean.
        Parameters:
        records - the records
        Returns:
        the boolean
      • getZBasedIndex

        public static java.lang.Integer getZBasedIndex​(int pos,
                                                       int listSize)
        Returns index of the requested record
        Parameters:
        pos - requested position of the record
        • positive number - returns, value decremented by one e.g 1 will return index of 0
        • negative number - returns element count from the end of the list, e.g -1 will return index of the last element
        • 0 (zero) - returns index of the first element, the same result as 1
        listSize - number of all elements in the array
        Returns:
        index of the requested record
      • getMediaObjectByTypeAndMedia

        public static MediaObject getMediaObjectByTypeAndMedia​(MediaAsset asset,
                                                               java.lang.String type,
                                                               java.lang.String media)
        Gets media object by type and media.
        Parameters:
        asset - the asset
        type - the type
        media - the media
        Returns:
        the media object by type and media