public class DomainUtils extends Object
Modifier and Type | Field and Description |
---|---|
static String |
DATE_FORMAT
Deprecated.
see Date
Transformer |
static String |
DATE_FORMAT_DISPLAY
Deprecated.
see Date
Transformer |
static String |
DATE_TIME_FORMAT_DISPLAY
Deprecated.
see Date
Transformer |
static String |
DATE_TIME_FORMAT_INPUT
Deprecated.
see Date
Transformer |
static Comparator<File> |
FILE_BY_DATE_COMPARITOR |
static Comparator<File> |
FILE_BY_DATE_DESC_COMPARITOR |
static Comparator<File> |
FILE_BY_NAME_CASESENSITIVE_COMPARITOR |
static Comparator<File> |
FILE_BY_NAME_COMPARITOR |
static Comparator<File> |
FILE_BY_NAME_DESC_COMPARITOR |
static Pattern |
HIERARCHY_COUNT |
static int |
MAX_UNSIGNED |
static org.apache.commons.collections.Predicate |
NO_FILES
A
Predicate that filters out files; returns true if File is a File Type and false if its a Folder |
Constructor and Description |
---|
DomainUtils() |
Modifier and Type | Method and Description |
---|---|
static String |
castBigIntId(Object oid)
Cast an Id that is a BigInteger as a String
|
static String |
castToString(Object str)
Any DB raw value or any value that needs to be converted to a String
|
static String |
convertDecimalToHex(int i,
Integer minLength) |
static int |
convertHexToDecimal(String hexStr)
Hex string is pure dex chars only, No # or 0x or any other kind of prefix expected
|
protected static int |
convertHierarchyCode(char code)
code should be in range {'1'..'9', 'A'..'Z'} else out = 0
|
protected static String |
convertHierarchyCode(int code)
code should be in range {1..35} else out = 0
(9 numeric and 26 alphabets = 35) TODO: Instead of jut 35, consider upgrading to (35 + 35 x 10 + 35x100) per sequence. |
static int |
convertHierarchyCode(String code) |
static String |
convertHierarchyCode(String prefix,
Integer code)
Opposite of
convertHierarchyCode(String) . |
static int |
countHierarchyLevel(String hierarchy)
For a given hierarchy code x_y_z...
|
static String[] |
extractSQLColumnNames(String sql)
Get column names for Sql String
|
static String |
filterUrl(String url,
String keepParamsRegex)
Remove whatever params are not specified in the keepParams
Example: for a url like https://a.b.com/xyz/123/page.html?x=12345&name=4%20rt-uu+def&age=34&PG=4 we can pass keepParamsRegex as (?i:name|pg)=([^&])+ |
static void |
findFieldsDontMatch(Object existing,
Object recent,
String[] fieldNames)
Between 2 states of objects, for critical fields specified by fieldNames,
throw a ValidationException for the field that does not match.
|
static Calendar |
from(Date date) |
static String |
fullPath(String basePath,
String relativePath)
returns basePath + (/) + relativePath; ensures all path strings have "/" as separator.
Also if the basePath has a leading (/; which it should not ideally), this does not add additional "/" in the middle in that case. |
static Class |
getClosestParent(Collection<Class> classes,
Class child)
Given a collection of classes, determine which is the closest parent of the provided class.
|
static String |
getDateTimeFromCronExpr2(String cron)
Process CRON expr to a Date/Time with all digits PADDED (2 digit)
..
|
static String |
getFileExtension(String filePath)
Get file extension exclusive of '.'.
|
static void |
getFileFolders(File root,
List<File> files,
List<File> folders)
Wrapper method to derive Files and folders in the root (without recursion);
and apply the optional Comparator if necessary
|
static List |
getFiles(File root,
org.apache.commons.collections.Predicate filter)
Get a Tree in the form of List of Lists of folders from a specified root
Note: to get all files use FileUtils.listFiles(File, String[], boolean) |
static String |
getFolderPath(String filePath,
String defaultFolderPath)
Derive the path of the folder from the filePath.
|
static List |
getFolders(File root)
Get a Tree in the form of List of Lists of folders from a specified root
Note: to get all files use FileUtils.listFiles(File, String[], boolean) |
static List<String> |
getHierarchyCodes(String nodeHierarchyCode,
boolean includeThis)
Gets the Hierarchy codes as
List of the current hierarchical item, recognized by parameter node HierarchyCode. |
static String |
getParentHierarchyCode(String nodeHierarchyCode)
Gets the Hierarchy code of the parent of current hierarcihal item, recognized by parameter nodeHierarchyCode
|
static List<String> |
getParentHierarchyCodes(String nodeHierarchyCode,
boolean includeThis)
Gets the Hierarchy codes as
List of the parent of current hierarchical item, recognized by parameter node HierarchyCode. |
static org.springframework.core.io.Resource |
getResource(URI location)
Resolve the script source for URL or Files.
|
static String |
getSpacedName(String name)
Insert Spaces to make them more user friendly to read
|
static <SUB_T,T> Set<String> |
getSpecificEntityFields(Class<T> classT,
Class<SUB_T> claz)
Get fields that should be excluded for a
Query so that the resultant fields are common between
T & SUB_T. |
static Class |
getType(Collection c)
Utility to get type for collection that is assumed homogenous
|
static void |
merge(Object from,
Object to,
String[] fieldNames,
Set<String> optionalFieldNames)
Merge fields from one Object into the other, where the fieldNames is a white list
|
static Calendar |
normalizeTime(Calendar cal)
Set Hour, Min, sec, msec to 0
|
static Date |
normalizeTime(Date date)
Return a Date object with all time related fields normalized to 0.
|
static String |
padChar(String s,
int padPrefix,
String p)
Pad chars infront of a String; useful for textual indentation scenarios
|
static String |
padZero(long n,
int len)
For a given length fixed, put in the number and pad the rest with 0's
|
static String |
padZero(String s)
Represent numebers as 01, 02, ...etc instead of 1,2,...
|
static String |
parseDateTime(Calendar cal)
Convert Calendar to String.
|
static String |
parseDateTime(Calendar cal,
String format)
Convert Calendar to String.
|
static Calendar |
parseDateTime(String strDate)
Convert String representation of Date/Time to Calendar.
|
static Calendar |
parseDateTime(String strDate,
String format)
Convert String representation of Date/Time to Calendar.
|
static String |
parseDateTimeForDisplay(Calendar cal) |
static String |
processNum(Number n,
String defaultValue,
int decimalPlaces)
Simple Number processing utility to convert Numbers to Strings
|
static String |
relativePath(String basePath,
String fullPath,
boolean firstSeparator)
Derive relative path from fullPath by subtracting the base path and cleaning the string if necessary.
|
static Number |
round(Number n,
int decimalPlaces)
Calculate the round/truncated Number
DO NOT USE IF NUMBER ACCURACY IS REQURED BEYOND DECIMAL PLACES |
static int |
setMaskOff(int maskState,
int mask) |
static int |
setMaskOn(int maskState,
int mask) |
static void |
ValidateAlphanumeric(String s) |
static void |
validateDateTime(String strDateTime,
String format) |
@Deprecated public static String DATE_TIME_FORMAT_DISPLAY
Transformer
@Deprecated public static String DATE_FORMAT_DISPLAY
Transformer
@Deprecated public static final String DATE_TIME_FORMAT_INPUT
Transformer
@Deprecated public static final String DATE_FORMAT
Transformer
public static final int MAX_UNSIGNED
public static final Pattern HIERARCHY_COUNT
public static final org.apache.commons.collections.Predicate NO_FILES
Predicate
that filters out files; returns true if File is a File Type and false if its a Folderpublic static final Comparator<File> FILE_BY_DATE_COMPARITOR
public static final Comparator<File> FILE_BY_DATE_DESC_COMPARITOR
public static final Comparator<File> FILE_BY_NAME_COMPARITOR
public static final Comparator<File> FILE_BY_NAME_DESC_COMPARITOR
public static final Comparator<File> FILE_BY_NAME_CASESENSITIVE_COMPARITOR
public static final Calendar parseDateTime(String strDate, String format) throws ParseException
strDate
- as StringCalendar
ParseException
public static final void validateDateTime(String strDateTime, String format) throws Exception
Exception
public static String parseDateTime(Calendar cal, String format)
cal
- as Calendar
protected static int convertHierarchyCode(char code)
protected static String convertHierarchyCode(int code)
convertHierarchyCode
public static int convertHierarchyCode(String code)
code
- as String (like 1_3_5_2_8, 1_3_5_2_9, 1_3_5_2_A, ..., 1_3_5_2_Z, 1_3_5_2_Z1, ..1_3_5_2_ZZ, .. 1_3_5_2_ZZ1 etc.)
public static String convertHierarchyCode(String prefix, Integer code)
convertHierarchyCode(String)
. Converts a number to a Hierarchy code with parent as prefix.code
- as Integer ( > 0 or null)convertHierarchyCode(int)
public static String getParentHierarchyCode(String nodeHierarchyCode)
nodeHierarchyCode
- as String x_y_z..._m_npublic static List<String> getParentHierarchyCodes(String nodeHierarchyCode, boolean includeThis)
List
of the parent of current hierarchical item, recognized by parameter node HierarchyCode.
nodeHierarchyCode
- as String x_y_z..._m_nincludeThis
- as boolean, if true will include current as first in the list.public static List<String> getHierarchyCodes(String nodeHierarchyCode, boolean includeThis)
List
of the current hierarchical item, recognized by parameter node HierarchyCode.
nodeHierarchyCode
- as String x_y_z..._nincludeThis
- as boolean, if true will include current as first in the list.public static int countHierarchyLevel(String hierarchy)
hierarchy
- public static String fullPath(String basePath, String relativePath)
basePath
- as StringrelativePath
- as StringString
public static String relativePath(String basePath, String fullPath, boolean firstSeparator)
basePath
- as StringfullPath
- as StringfirstSeparator
- as boolean, if true will ensure a '/' exists at start of string, else it will ensure it does not.
Null will result in that aspect being ignored.String
, with '/' as separatorpublic static String getFileExtension(String filePath)
filePath
- as StringString
public static org.springframework.core.io.Resource getResource(URI location) throws IOException
location
- as URI
Resource
Exception
IOException
public static String getFolderPath(String filePath, String defaultFolderPath)
filePath
- as String (path) @nullable true, if null will simply return defaultFolderPath backdefaultFolderPath
- as StringString
public static List getFolders(File root)
FileUtils.listFiles(File, String[], boolean)
public static List getFiles(File root, org.apache.commons.collections.Predicate filter)
FileUtils.listFiles(File, String[], boolean)
public static void getFileFolders(File root, List<File> files, List<File> folders)
root
- as File; root or base folderfiles
- @nullable true; to which all files will be addedfolders
- @nullable true; to which all folders will be addedpublic static final Number round(Number n, int decimalPlaces)
n
- as NumberdecimalPlaces
- as int, if 0 (integer) else will round to # of decimal places.
Note: -1 implies true places. Example: 3.54 --> 3.54 and 3 --> 3, 3.0 --> 3public static final String processNum(Number n, String defaultValue, int decimalPlaces)
n
- as NumberdefaultValue
- , if nulldecimalPlaces
- , if 0 (integer) else will round to # of decimal places. See round(Number, int)
for more details, like -1 special caseString
TODO: Add unit test casepublic static final String convertDecimalToHex(int i, Integer minLength)
i
- as input intminLength
- as Integer. @nullable true. If not null then will ensure the length of the output is minimum fixed chars.String
public static void ValidateAlphanumeric(String s)
public static final int convertHexToDecimal(String hexStr)
hexStr
- as Hex Stringpublic static String getSpacedName(String name)
name
- as Stringpublic static final int setMaskOn(int maskState, int mask)
maskState
- as int (Domain object to maintain state)mask
- as int (The Mask representing the variable)public static final int setMaskOff(int maskState, int mask)
maskState
- as int (Domain object to maintain state)mask
- as int (The Mask representing the variable)public static final Calendar parseDateTime(String strDate) throws ParseException
strDate
- as StringCalendar
ParseException
public static String parseDateTime(Calendar cal)
cal
- as Calendar
public static String castBigIntId(Object oid)
oid
- String
public static String castToString(Object str)
str
- String
public static <SUB_T,T> Set<String> getSpecificEntityFields(Class<T> classT, Class<SUB_T> claz)
Query
so that the resultant fields are common between
T & SUB_T. Basically return Fields(T - SUB_T)public static String padZero(String s)
s
- public static String padZero(long n, int len)
n
- as longlen
- as the desired padded lengthString
public static String padChar(String s, int padPrefix, String p)
s
- padPrefix
- as the number of places to padp
- as String that represents the set of padded characters to applyString
public static String getDateTimeFromCronExpr2(String cron)
String
public static String[] extractSQLColumnNames(String sql)
String
[]public static String filterUrl(String url, String keepParamsRegex)
url
- as StringString
public static Calendar normalizeTime(Calendar cal)
cal
- Calendar
public static Date normalizeTime(Date date)
public static Class getClosestParent(Collection<Class> classes, Class child)
classes
- public static Class getType(Collection c)
public static void merge(Object from, Object to, String[] fieldNames, Set<String> optionalFieldNames) throws Exception
from
- as Objectto
- as ObjectfieldNames
- as String[]optionalFieldNames
- as Set of Strings; if null in hte "from" object they will not be merged.
These should be part of fieldNames also. This serves as an additional filter. @nullable true.NoSuchFieldException
SecurityException
Exception
more complex operations see ETL ExistingEntityMergeTransformer
public static void findFieldsDontMatch(Object existing, Object recent, String[] fieldNames) throws javax.validation.ValidationException
existing
- as Objectrecent
- as ObjectfieldNames
- as String[]javax.validation.ValidationException
Copyright © 2018. All rights reserved.