Class CollectionUtil

java.lang.Object
org.drip.service.common.CollectionUtil

public class CollectionUtil
extends java.lang.Object
CollectionUtil implements generic utility functions used in DROP modules. Some of the functions it exposes are:

  • Map Merging Functionality
  • Map Key Functionality - key-value flatteners, key prefixers
  • Decompose/transform List/Set/Array Contents
  • Multi-Dimensional Map Manipulator Routines
  • Construct n-derivatives array from Slope
  • Collate Wengerts to a bigger Wengert




Author:
Lakshmi Krishnamurthy
  • Constructor Summary

    Constructors
    Constructor Description
    CollectionUtil()  
  • Method Summary

    Modifier and Type Method Description
    static WengertJacobian AppendWengert​(java.util.List<WengertJacobian> lsWJ)
    Append the Wengert Jacobians inside the list onto one single composite
    static boolean ContainsNearbyAlmostDuplicate​(int[] numberArray, int k, int t)
    Given an integer array numberArray and two integers k and t, return true if there are two distinct indices i and j in the array such that abs(numberArray[i] - numberArray[j]) .le.
    static double[] DerivArrayFromSlope​(int iNumDerivs, double dblSlope)
    Populate an array of derivatives using the input slope (and setting the other to zero)
    static CaseInsensitiveTreeMap<java.lang.Double> FlatStringTo2DSDMap​(java.lang.String str2DMap, java.lang.String strKVDelimiter, java.lang.String strRecordDelimiter, boolean bSkipNullValue, java.lang.String strNULLString)
    Turn a flattened 2D (string, double) string sequence into its corresponding map
    static CaseInsensitiveTreeMap<CaseInsensitiveTreeMap<java.lang.Double>> FlatStringTo3DSDMap​(java.lang.String str3DMap, java.lang.String strMultiLevelKeyDelimiter, java.lang.String strKVDelimiter, java.lang.String strRecordDelimiter, boolean bSkipNullValue, java.lang.String strNULLString)
    Turn a flattened 3D (string, string, double) string sequence into its corresponding map
    static CaseInsensitiveTreeMap<CaseInsensitiveTreeMap<CaseInsensitiveTreeMap<java.lang.Double>>> FlatStringTo4DSDMap​(java.lang.String str4DMap, java.lang.String strMultiLevelKeyDelimiter, java.lang.String strKVDelimiter, java.lang.String strRecordDelimiter, boolean bSkipNullValue, java.lang.String strNULLString)
    Turn a flattened 4D (string, string, string, double) string sequence into its corresponding map
    static java.lang.String FourDSDMapToFlatString​(CaseInsensitiveTreeMap<CaseInsensitiveTreeMap<CaseInsensitiveTreeMap<java.lang.Double>>> map4DSD, java.lang.String strMultiLevelKeyDelimiter, java.lang.String strKVDelimiter, java.lang.String strRecordDelimiter)
    Flatten a 4D SSSD map structure onto a string array
    static void main​(java.lang.String[] argumentArray)
    Entry Point
    static CaseInsensitiveTreeMap<java.lang.Double> MergeMaps​(CaseInsensitiveTreeMap<java.lang.Double> map1, CaseInsensitiveTreeMap<java.lang.Double> map2)
    Merge two maps
    static boolean MergeWithMain​(CaseInsensitiveTreeMap<java.lang.Double> mapMain, CaseInsensitiveTreeMap<java.lang.Double> mapToAdd)
    Merge the secondary map onto the main map
    static CaseInsensitiveTreeMap<java.lang.Double> PrefixKeys​(CaseInsensitiveTreeMap<java.lang.Double> mapIn, java.lang.String strPrefix)
    Prefix the keys in the input map, and return them in a new map
    static java.lang.String ThreeDSDMapToFlatString​(CaseInsensitiveTreeMap<CaseInsensitiveTreeMap<java.lang.Double>> map3DSD, java.lang.String strMultiLevelKeyDelimiter, java.lang.String strKVDelimiter, java.lang.String strRecordDelimiter)
    Flatten a 3D SSD map structure onto a string array
    static java.lang.String TwoDSDMapToFlatString​(CaseInsensitiveTreeMap<java.lang.Double> map2DSD, java.lang.String strKVDelimiter, java.lang.String strRecordDelimiter)
    Flatten an input 2D string/double map into a delimited string array

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CollectionUtil

      public CollectionUtil()
  • Method Details

    • PrefixKeys

      public static final CaseInsensitiveTreeMap<java.lang.Double> PrefixKeys​(CaseInsensitiveTreeMap<java.lang.Double> mapIn, java.lang.String strPrefix)
      Prefix the keys in the input map, and return them in a new map
      Parameters:
      mapIn - Input map
      strPrefix - The prefix
      Returns:
      Map containing the prefixed entries
    • MergeMaps

      public static final CaseInsensitiveTreeMap<java.lang.Double> MergeMaps​(CaseInsensitiveTreeMap<java.lang.Double> map1, CaseInsensitiveTreeMap<java.lang.Double> map2)
      Merge two maps
      Parameters:
      map1 - Map 1
      map2 - Map 2
      Returns:
      The merged map
    • MergeWithMain

      public static final boolean MergeWithMain​(CaseInsensitiveTreeMap<java.lang.Double> mapMain, CaseInsensitiveTreeMap<java.lang.Double> mapToAdd)
      Merge the secondary map onto the main map
      Parameters:
      mapMain - Main Map
      mapToAdd - Secondary Map to Add
      Returns:
      True - If successfully merged with main
    • TwoDSDMapToFlatString

      public static final java.lang.String TwoDSDMapToFlatString​(CaseInsensitiveTreeMap<java.lang.Double> map2DSD, java.lang.String strKVDelimiter, java.lang.String strRecordDelimiter)
      Flatten an input 2D string/double map into a delimited string array
      Parameters:
      map2DSD - 2D String/Double map
      strKVDelimiter - Element delimiter
      strRecordDelimiter - Record delimiter
      Returns:
      Flattened map string
    • ThreeDSDMapToFlatString

      public static final java.lang.String ThreeDSDMapToFlatString​(CaseInsensitiveTreeMap<CaseInsensitiveTreeMap<java.lang.Double>> map3DSD, java.lang.String strMultiLevelKeyDelimiter, java.lang.String strKVDelimiter, java.lang.String strRecordDelimiter)
      Flatten a 3D SSD map structure onto a string array
      Parameters:
      map3DSD - 3D SSD map
      strMultiLevelKeyDelimiter - Multi Level KeyDelimiter
      strKVDelimiter - Key-Value Delimiter
      strRecordDelimiter - Record Delimiter
      Returns:
      Flattened String
    • FourDSDMapToFlatString

      public static final java.lang.String FourDSDMapToFlatString​(CaseInsensitiveTreeMap<CaseInsensitiveTreeMap<CaseInsensitiveTreeMap<java.lang.Double>>> map4DSD, java.lang.String strMultiLevelKeyDelimiter, java.lang.String strKVDelimiter, java.lang.String strRecordDelimiter)
      Flatten a 4D SSSD map structure onto a string array
      Parameters:
      map4DSD - 4D SSSD map
      strMultiLevelKeyDelimiter - Multi Level KeyDelimiter
      strKVDelimiter - Key-Value Delimiter
      strRecordDelimiter - Record Delimiter
      Returns:
      Flattened String
    • FlatStringTo2DSDMap

      public static final CaseInsensitiveTreeMap<java.lang.Double> FlatStringTo2DSDMap​(java.lang.String str2DMap, java.lang.String strKVDelimiter, java.lang.String strRecordDelimiter, boolean bSkipNullValue, java.lang.String strNULLString)
      Turn a flattened 2D (string, double) string sequence into its corresponding map
      Parameters:
      str2DMap - Flattened 2D array input
      strKVDelimiter - Key-Value delimiter string
      strRecordDelimiter - Record delimiter string
      bSkipNullValue - Indicates whether NULL Values are to be skipped
      strNULLString - NULL string
      Returns:
      [String, double] map
    • FlatStringTo3DSDMap

      public static final CaseInsensitiveTreeMap<CaseInsensitiveTreeMap<java.lang.Double>> FlatStringTo3DSDMap​(java.lang.String str3DMap, java.lang.String strMultiLevelKeyDelimiter, java.lang.String strKVDelimiter, java.lang.String strRecordDelimiter, boolean bSkipNullValue, java.lang.String strNULLString)
      Turn a flattened 3D (string, string, double) string sequence into its corresponding map
      Parameters:
      str3DMap - Flattened 3D array input
      strMultiLevelKeyDelimiter - Multi-level key delimiter string
      strKVDelimiter - Key-Value delimiter string
      strRecordDelimiter - Record delimiter string
      bSkipNullValue - Indicates whether NULL Values are to be skipped
      strNULLString - NULL string
      Returns:
      [String, [String, double]] map
    • FlatStringTo4DSDMap

      public static final CaseInsensitiveTreeMap<CaseInsensitiveTreeMap<CaseInsensitiveTreeMap<java.lang.Double>>> FlatStringTo4DSDMap​(java.lang.String str4DMap, java.lang.String strMultiLevelKeyDelimiter, java.lang.String strKVDelimiter, java.lang.String strRecordDelimiter, boolean bSkipNullValue, java.lang.String strNULLString)
      Turn a flattened 4D (string, string, string, double) string sequence into its corresponding map
      Parameters:
      str4DMap - Flattened 4D array input
      strMultiLevelKeyDelimiter - Multi-level key delimiter string
      strKVDelimiter - Key-Value delimiter string
      strRecordDelimiter - Record delimiter string
      bSkipNullValue - Indicates whether NULL Values are to be skipped
      strNULLString - NULL string
      Returns:
      [String, [String, [String, double]]] map
    • DerivArrayFromSlope

      public static final double[] DerivArrayFromSlope​(int iNumDerivs, double dblSlope)
      Populate an array of derivatives using the input slope (and setting the other to zero)
      Parameters:
      iNumDerivs - Number of Derivatives to be populated
      dblSlope - Slope
      Returns:
      Array of derivatives
    • AppendWengert

      public static final WengertJacobian AppendWengert​(java.util.List<WengertJacobian> lsWJ)
      Append the Wengert Jacobians inside the list onto one single composite
      Parameters:
      lsWJ - List of Wengert Jacobians
      Returns:
      The Composite Wengert Jacobian
    • ContainsNearbyAlmostDuplicate

      public static final boolean ContainsNearbyAlmostDuplicate​(int[] numberArray, int k, int t)
      Given an integer array numberArray and two integers k and t, return true if there are two distinct indices i and j in the array such that abs(numberArray[i] - numberArray[j]) .le. t and abs(i - j) .le. k
      Parameters:
      numberArray - Number Array
      k - K
      t - T
      Returns:
      TRUE - Element matching the criteria above found
    • main

      public static final void main​(java.lang.String[] argumentArray) throws java.lang.Exception
      Entry Point
      Parameters:
      argumentArray - Argument Array
      Throws:
      java.lang.Exception - Thrown if an Exception is encountered