This project is to extend (Java/Groovy) core classes to improve productivity.
How to use it in your project:
Maven:
<dependency>
<groupId>com.intellisrc</groupId>
<artifactId>groovy-extend</artifactId>
<version>VERSION</version>
</dependency>
Gradle:
dependecies {
implementation 'com.intellisrc:groovy-extend:VERSION'
// or extended annotation:
implementation group: 'com.intellisrc', name: 'groovy-extend', version: 'VERSION'
}
In which VERSION
is this package version, for example: 4.0.23.14
.
The first 3 numbers (4.0.23) are Groovy version used to compile this package.
You can use the groovy version that fits your needs.
NOTE: Don't forget to add your groovy dependency.
Date
class should no longer be used. Because of that, we extended Date
class to make it easier to change it to LocalDate
and LocalDateTime
:
toLocalDateTime
toLocalDate
toLocalTime
toZonedDateTime
toDate
: Only used for external codes which still rely on DatetoDateTime
: Convert to DateTimeformat
: use DateTimeFormatter in an easy wayisBetween
: Check if date or time is between two other dates or timesatStartOfDay
: Added to LocalDate as wellatEndOfDay
: get the last nanosecond of the day
YMDHms
: Return "yyyy-MM-dd HH:mm:ss"getYMDHms("","")
: Return "yyyyMMddHHmmss"YMDHmsS
: Return "yyyy-MM-dd HH:mm:ss.SSS"YMDHm
: Return "yyyy-MM-dd HH:mm"toMillis
: Return epoch milliseconds (long)fromMillis
: (static) Convert epoch milliseconds into LocalDateTimetoSeconds
: Return epoch seconds (long)fromSeconds
: (static) Convert epoch seconds into LocalDateTime
clearTime
: Return a LocalDateTime with 00:00:00.000 time
YMD
: Return "yyyy-MM-dd"
YY
: Return "yy"MM
: Return "MM"DD
: Return "dd"next()
andprevious()
: Allows to use it as range: (from..to)
HHmmss
: Return "HH:mm:ss"getHHmmss("")
: Return "HHmmss"HHmm
: Return "HH:mm"
These extensions provide faster ways to deal with files. Setting permissions and performing operations are made easier.
get
: Similar tonew File()
but more flexible.create
: Similar toget()
but will create an empty file including their directoriesuserDir
: get User directory (root directory for project)homeDir
: get Home directorytempDir
: get the temporal directory
lines
: Get total lines in a file (faster way)eachFileAsync
: Iterate through all files without having to read the whole directory firsteachFileMatchAsync
: Iterate files inside directory using glob search or FileFilterlistFiles
: Using glob search (Async) [@since 2.5.6.2
]deleteFiles
: Delete files using glob search or FileFilter (Async) [@since 2.5.6.2
]
permissions
: Will return PosixFilePermissionsownerPermissions
: set owner permissionsgroupPermissions
: set group permissionsothersPermissions
: set others permissionsclearPermissions
clearOwnerPermissions
clearGroupPermissions
clearOthersPermissions
setReadable
setWritable
setExecutable
setOwnerReadable
setOwnerWritable
setOwnerExecutable
setGroupReadable
setGroupWritable
setGroupExecutable
setOthersReadable
setOthersWritable
setOthersExecutable
copyTo
moveTo
linkTo
: Create a link from a file. Its argument is the link to create. An additional argument is to specify if link is hard or not.hardLinkOrCopyTo
: Will try to create a hardLink, but if its in another device (which is not allowed), it will copy it.
Extends String methods that are commonly used and easiest ways to convert them.
alphaNumeric
: returns only alphanumeric characterspadRight
: pad to the right with spacespadLeft
: pad to the left with spacesappendRandomNum
: Useful to create random strings, e.g: 'apple1234'insertAt
: Insert a substring into a string in a specific position
toInet4Address
toInet6Address
toInetAddress
getQueryMap
: Convert Query String to MaptoDateTime
: Convert String into LocalDateTime (auto detect format)toDate
: Convert String into LocalDate (auto detect format)toTime
: Convert String into LocalTime (auto detect format)toSnakeCase
: Returns a string as snake_case_formatted_stringtoCamelCase
: Returns a string as CamelCaseFormattedStringtoDotCase
: Returns a string as dot.case.formatted.stringtoKebabCase
: Returns a string as Kebab-Case-Formatted-String
ceil
floor
toQueryString
: Convert Map to Query String e.g : "a=1&b=2"
range
: Specify a range to get a random number
random
: Get one or more random element from a collection (two implementations).
LimitedLinkedList
: A list with a limited number of elements