Class DataMappingUtils

java.lang.Object
com.priint.pubserver.comet.bridge.datamapping.DataMappingUtils

public class DataMappingUtils extends Object
The type Data mapping utils.
  • Field Details

  • Method Details

    • emptyList

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

      public static List<String> stringList(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(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 List<Integer> processRange(List<?> values, String input)
      Process range list.
      Parameters:
      values - the values
      input - the input
      Returns:
      the list
    • getSubList

      public static <T> List<T> getSubList(List<T> values, List<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(List<?> values, List<Integer> range)
      Check range boolean.
      Parameters:
      values - the values
      range - the range
      Returns:
      the boolean
    • getRecordIndexList

      public static List<Integer> getRecordIndexList(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(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 String getDelimiter(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 List<String> parseQuotedList(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 List<String> parseQuotedList(String input)
      Parse quoted list list.
      Parameters:
      input - the input
      Returns:
      the list
    • parseNumberList

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

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

      public static String toString(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(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(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 List<KeyValue> filterByKey(List<KeyValue> values, String key)
      Filter by key list.
      Parameters:
      values - the values
      key - the key
      Returns:
      the list
    • split

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

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

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

      public static void failIfInputEmpty(Object caller, 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(Object caller, T target, Class<?> clazz, String entityModelIdentifier, String entityId, String parentBucketId, String recordGroupIdentifier, String resultEntityId, Context context, 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 String listSize(List<?> list)
      List size string.
      Parameters:
      list - the list
      Returns:
      the string
    • failIfSizeDiffer

      public static void failIfSizeDiffer(Object caller, List<?> input, List<?> output, String entityModelIdentifier, String entityId, String parentBucketId, String recordGroupIdentifier, String resultEntityId, Context context, 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 String range(int... range)
      Range string.
      Parameters:
      range - the range
      Returns:
      the string
    • all

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

      public static 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, String type, 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