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. It provides the following Functions:
  • >Prefix the keys in the input map, and return them in a new map
  • >Merge two maps
  • >Merge the secondary map onto the main map
  • >Flatten an input 2D string/double map into a delimited string array
  • >Flatten a 3D SSD map structure onto a string array
  • >Flatten a 4D SSSD Multi-map structure onto a string array
  • >Turn a flattened 2D (string, double) string sequence into its corresponding map
  • >Turn a flattened 3D (string, string, double) string sequence into its corresponding map
  • >Turn a flattened 4D (string, string, string, double) string sequence into its corresponding map
  • >Populate an array of derivatives using the input slope (and setting the other to zero)
  • >Append the Wengert Jacobians inside the list onto one single composite
  • >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

Module Computational Core Module
Library Computation Support
Project Environment, Product/Definition Containers, and Scenario/State Manipulation APIs
Package Assorted Data Structures Support Utilities

Author:
Lakshmi Krishnamurthy
  • Constructor Summary

    Constructors
    Constructor Description
    CollectionUtil()  
  • Method Summary

    Modifier and Type Method Description
    static org.drip.numerical.differentiation.WengertJacobian AppendWengert​(java.util.List<org.drip.numerical.differentiation.WengertJacobian> wengertJacobianList)
    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 derivativeCount, double slope)
    Populate an array of derivatives using the input slope (and setting the other to zero)
    static org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> FlatStringTo2DSDMap​(java.lang.String twoDMap, java.lang.String keyValueDelimiter, java.lang.String recordDelimiter, boolean skipNULLValue, java.lang.String nullString)
    Turn a flattened 2D (string, double) string sequence into its corresponding map
    static org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>> FlatStringTo3DSDMap​(java.lang.String threeDMap, java.lang.String multiLevelKeyDelimiter, java.lang.String keyValueDelimiter, java.lang.String recordDelimiter, boolean skipNULLValue, java.lang.String nullString)
    Turn a flattened 3D (string, string, double) string sequence into its corresponding map
    static org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>> FlatStringTo4DSDMap​(java.lang.String fourDMap, java.lang.String multiLevelKeyDelimiter, java.lang.String keyValueDelimiter, java.lang.String recordDelimiter, boolean skipNullValue, java.lang.String nullString)
    Turn a flattened 4D (string, string, string, double) string sequence into its corresponding map
    static java.lang.String FourDSDMapToFlatString​(org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>> multiMap, java.lang.String multiLevelKeyDelimiter, java.lang.String keyValueDelimiter, java.lang.String recordDelimiter)
    Flatten a 4D SSSD Multi-map structure onto a string array
    static org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> MergeMaps​(org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> map1, org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> map2)
    Merge two maps
    static boolean MergeWithMain​(org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapMain, org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapToAdd)
    Merge the secondary map onto the main map
    static org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> PrefixKeys​(org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> inputMap, java.lang.String prefix)
    Prefix the keys in the input map, and return them in a new map
    static java.lang.String ThreeDSDMapToFlatString​(org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>> doubleValuedDoubleMap, java.lang.String multiLevelKeyDelimiter, java.lang.String keyValueDelimiter, java.lang.String recordDelimiter)
    Flatten a 3D SSD map structure onto a string array
    static java.lang.String TwoDSDMapToFlatString​(org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> doubleValueMap, java.lang.String keyValueDelimiter, java.lang.String recordDelimiter)
    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 org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> PrefixKeys​(org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> inputMap, java.lang.String prefix)
      Prefix the keys in the input map, and return them in a new map
      Parameters:
      inputMap - Input map
      prefix - The prefix
      Returns:
      Map containing the prefixed entries
    • MergeMaps

      public static final org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> MergeMaps​(org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> map1, org.drip.analytics.support.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​(org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapMain, org.drip.analytics.support.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​(org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> doubleValueMap, java.lang.String keyValueDelimiter, java.lang.String recordDelimiter)
      Flatten an input 2D string/double map into a delimited string array
      Parameters:
      doubleValueMap - 2D String/Double map
      keyValueDelimiter - Element delimiter
      recordDelimiter - Record delimiter
      Returns:
      Flattened map string
    • ThreeDSDMapToFlatString

      public static final java.lang.String ThreeDSDMapToFlatString​(org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>> doubleValuedDoubleMap, java.lang.String multiLevelKeyDelimiter, java.lang.String keyValueDelimiter, java.lang.String recordDelimiter)
      Flatten a 3D SSD map structure onto a string array
      Parameters:
      doubleValuedDoubleMap - 3D SSD map
      multiLevelKeyDelimiter - Multi Level KeyDelimiter
      keyValueDelimiter - Key-Value Delimiter
      recordDelimiter - Record Delimiter
      Returns:
      Flattened String
    • FourDSDMapToFlatString

      public static final java.lang.String FourDSDMapToFlatString​(org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>> multiMap, java.lang.String multiLevelKeyDelimiter, java.lang.String keyValueDelimiter, java.lang.String recordDelimiter)
      Flatten a 4D SSSD Multi-map structure onto a string array
      Parameters:
      multiMap - 4D SSSD map
      multiLevelKeyDelimiter - Multi-Level Key Delimiter
      keyValueDelimiter - Key-Value Delimiter
      recordDelimiter - Record Delimiter
      Returns:
      Flattened String
    • FlatStringTo2DSDMap

      public static final org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> FlatStringTo2DSDMap​(java.lang.String twoDMap, java.lang.String keyValueDelimiter, java.lang.String recordDelimiter, boolean skipNULLValue, java.lang.String nullString)
      Turn a flattened 2D (string, double) string sequence into its corresponding map
      Parameters:
      twoDMap - Flattened 2D array input
      keyValueDelimiter - Key-Value delimiter string
      recordDelimiter - Record delimiter string
      skipNULLValue - Indicates whether NULL Values are to be skipped
      nullString - NULL string
      Returns:
      [String, double] map
    • FlatStringTo3DSDMap

      public static final org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>> FlatStringTo3DSDMap​(java.lang.String threeDMap, java.lang.String multiLevelKeyDelimiter, java.lang.String keyValueDelimiter, java.lang.String recordDelimiter, boolean skipNULLValue, java.lang.String nullString)
      Turn a flattened 3D (string, string, double) string sequence into its corresponding map
      Parameters:
      threeDMap - Flattened 3D array input
      multiLevelKeyDelimiter - Multi-level key delimiter string
      keyValueDelimiter - Key-Value delimiter string
      recordDelimiter - Record delimiter string
      skipNULLValue - Indicates whether NULL Values are to be skipped
      nullString - NULL string
      Returns:
      [String, [String, double]] map
    • FlatStringTo4DSDMap

      public static final org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>> FlatStringTo4DSDMap​(java.lang.String fourDMap, java.lang.String multiLevelKeyDelimiter, java.lang.String keyValueDelimiter, java.lang.String recordDelimiter, boolean skipNullValue, java.lang.String nullString)
      Turn a flattened 4D (string, string, string, double) string sequence into its corresponding map
      Parameters:
      fourDMap - Flattened 4D array input
      multiLevelKeyDelimiter - Multi-level key delimiter string
      keyValueDelimiter - Key-Value delimiter string
      recordDelimiter - Record delimiter string
      skipNullValue - Indicates whether NULL Values are to be skipped
      nullString - NULL string
      Returns:
      [String, [String, [String, double]]] map
    • DerivArrayFromSlope

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

      public static final org.drip.numerical.differentiation.WengertJacobian AppendWengert​(java.util.List<org.drip.numerical.differentiation.WengertJacobian> wengertJacobianList)
      Append the Wengert Jacobians inside the list onto one single composite
      Parameters:
      wengertJacobianList - 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