Package org.drip.service.common
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
andt
, return true if there are two distinct indicesi
andj
in the array such thatabs(numberArray[i] - numberArray[j]) .le. t
andabs(i - j) .le. k
- 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 compositestatic 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 mapstatic 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 mapstatic 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 mapstatic 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 arraystatic 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 mapsstatic 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 mapstatic 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 mapstatic 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 arraystatic 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 arrayMethods 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 mapprefix
- 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 1map2
- 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 MapmapToAdd
- 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 mapkeyValueDelimiter
- Element delimiterrecordDelimiter
- 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 mapmultiLevelKeyDelimiter
- Multi Level KeyDelimiterkeyValueDelimiter
- Key-Value DelimiterrecordDelimiter
- 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 mapmultiLevelKeyDelimiter
- Multi-Level Key DelimiterkeyValueDelimiter
- Key-Value DelimiterrecordDelimiter
- 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 inputkeyValueDelimiter
- Key-Value delimiter stringrecordDelimiter
- Record delimiter stringskipNULLValue
- Indicates whether NULL Values are to be skippednullString
- 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 inputmultiLevelKeyDelimiter
- Multi-level key delimiter stringkeyValueDelimiter
- Key-Value delimiter stringrecordDelimiter
- Record delimiter stringskipNULLValue
- Indicates whether NULL Values are to be skippednullString
- 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 inputmultiLevelKeyDelimiter
- Multi-level key delimiter stringkeyValueDelimiter
- Key-Value delimiter stringrecordDelimiter
- Record delimiter stringskipNullValue
- Indicates whether NULL Values are to be skippednullString
- 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 populatedslope
- 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 Arrayk
- Kt
- T- Returns:
- TRUE - Element matching the criteria above found
-