diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md
index fbc88f3..234bd55 100644
--- a/CODE_OF_CONDUCT.md
+++ b/CODE_OF_CONDUCT.md
@@ -2,17 +2,14 @@
## Our Pledge
-In the interest of fostering an open and welcoming environment, we as
-contributors and maintainers pledge to making participation in our project and
-our community a harassment-free experience for everyone, regardless of age, body
-size, disability, ethnicity, sex characteristics, gender identity and expression,
-level of experience, education, socio-economic status, nationality, personal
-appearance, race, religion, or sexual identity and orientation.
+In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making
+participation in our project and our community a harassment-free experience for everyone, regardless of age, body size,
+disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education,
+socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
## Our Standards
-Examples of behavior that contributes to creating a positive environment
-include:
+Examples of behavior that contributes to creating a positive environment include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
@@ -22,53 +19,42 @@ include:
Examples of unacceptable behavior by participants include:
-* The use of sexualized language or imagery and unwelcome sexual attention or
- advances
+* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
-* Publishing others' private information, such as a physical or electronic
- address, without explicit permission
-* Other conduct which could reasonably be considered inappropriate in a
- professional setting
+* Publishing others' private information, such as a physical or electronic address, without explicit permission
+* Other conduct which could reasonably be considered inappropriate in a professional setting
## Our Responsibilities
-Project maintainers are responsible for clarifying the standards of acceptable
-behavior and are expected to take appropriate and fair corrective action in
-response to any instances of unacceptable behavior.
+Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take
+appropriate and fair corrective action in response to any instances of unacceptable behavior.
-Project maintainers have the right and responsibility to remove, edit, or
-reject comments, commits, code, wiki edits, issues, and other contributions
-that are not aligned to this Code of Conduct, or to ban temporarily or
-permanently any contributor for other behaviors that they deem inappropriate,
-threatening, offensive, or harmful.
+Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits,
+issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any
+contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
## Scope
-This Code of Conduct applies both within project spaces and in public spaces
-when an individual is representing the project or its community. Examples of
-representing a project or community include using an official project e-mail
-address, posting via an official social media account, or acting as an appointed
-representative at an online or offline event. Representation of a project may be
-further defined and clarified by project maintainers.
+This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the
+project or its community. Examples of representing a project or community include using an official project e-mail
+address, posting via an official social media account, or acting as an appointed representative at an online or offline
+event. Representation of a project may be further defined and clarified by project maintainers.
## Enforcement
-Instances of abusive, harassing, or otherwise unacceptable behavior may be
-reported by contacting the project team at vicky.thakor@javaquery.com. All
-complaints will be reviewed and investigated and will result in a response that
-is deemed necessary and appropriate to the circumstances. The project team is
-obligated to maintain confidentiality with regard to the reporter of an incident.
-Further details of specific enforcement policies may be posted separately.
+Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at
+vicky.thakor@javaquery.com. All complaints will be reviewed and investigated and will result in a response that is
+deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with
+regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
-Project maintainers who do not follow or enforce the Code of Conduct in good
-faith may face temporary or permanent repercussions as determined by other
-members of the project's leadership.
+Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent
+repercussions as determined by other members of the project's leadership.
## Attribution
-This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
-available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
+This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available
+at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
[homepage]: https://www.contributor-covenant.org
diff --git a/README.md b/README.md
index b6637ec..264da4a 100644
--- a/README.md
+++ b/README.md
@@ -1,35 +1,56 @@
# JavaQuery Util Library
+
Welcome to the JavaQuery util library
[](https://maven-badges.herokuapp.com/maven-central/com.javaquery/util)
# Overview
-Goal is to remove repeated boler plate utility code from your project. This library offers util classes of following framework and objects.
-
-- Collections: Provides wide range of operation you perform on collection (List, Set and Map) interfaces like nullOrEmpty(Collection), nonNullNonEmpty(Collection), batches(List source, int batchSize), etc...
-- Files: Provides wide range of operation you perform on java.io.File like createNewFile(T file), writeToFile(T file, String data), appendToFile(T file, String data, boolean appendNewLine), etc...
-- Console: Provides replacement of System.out.println() using .log() and System.err.println() using error().
-- JFile: Extends java.io.File and provide some extra function on file like getExtension, read, write.
-- JSONObject: Uses org.json.JSONObject and provides facility to optValue at any path in JSONObject, like items.item[0].batters.batter[2].available
-- Strings: Provides wide range of operation you perform on java.lang.String like nullOrEmpty(String str), joinStrings(String separator, String... strings), removeNotSupportedASCIICharacters(String str), etc...
-- DatePattern: Provides wide range of Date patterns commonly used worldwide like yyyyMMddHHmmss, yyyy-MM-dd HH:mm:ss'Z', yyyy-MM-dd'T'HH:mm:ss.SSSSSSS-HH:MM, etc...
+
+Goal is to remove repeated boler plate utility code from your project. This library offers util classes of following
+framework and objects.
+
+- Collections: Provides wide range of operation you perform on collection (List, Set and Map) interfaces
+ like nullOrEmpty(Collection), nonNullNonEmpty(Collection), batches(List source, int
+ batchSize), etc...
+- Files: Provides wide range of operation you perform on java.io.File like createNewFile(T
+ file), writeToFile(T file, String data), appendToFile(T file, String data, boolean
+ appendNewLine), etc...
+- Console: Provides replacement of System.out.println() using .log() and
+ System.err.println() using error().
+- JFile: Extends java.io.File and provide some extra function on file like getExtension
+ , read, write.
+- JSONObject: Uses org.json.JSONObject and provides facility to optValue at any path in JSONObject,
+ like items.item[0].batters.batter[2].available
+- Strings: Provides wide range of operation you perform on java.lang.String like nullOrEmpty(
+ String str), joinStrings(String separator, String... strings),
+ removeNotSupportedASCIICharacters(String str), etc...
+- DatePattern: Provides wide range of Date patterns commonly used worldwide like yyyyMMddHHmmss
+ , yyyy-MM-dd HH:mm:ss'Z', yyyy-MM-dd'T'HH:mm:ss.SSSSSSS-HH:MM, etc...
- DateRange: Class can be used to store start-date and end-date.
-- Dates: Provides wide range of operation you perform on java.util.Date like addInDate(Date date, int type, int amount), parse(String date, DatePattern datePattern, TimeZone timeZone), format(Date date, DatePattern datePattern, TimeZone timeZone), etc...
-- Assert: Provides wide range of operation for Assertions like nonNull(Object object, Supplier exceptionSupplier), isTrue(boolean expression, Supplier exceptionSupplier), nonNullNonEmpty(Collection> collection, Supplier exceptionSupplier), etc...
-- Objects: Provides wide range of operation on java.lang.Object like isNull(Object obj), nonNull(Object obj).
-- Regex: Provides wide range of operation using regular expression like isNumber(String value), isAlphaNumeric(String value), isValidEmail(String value).
+- Dates: Provides wide range of operation you perform on java.util.Date like addInDate(Date
+ date, int type, int amount), parse(String date, DatePattern datePattern, TimeZone timeZone)
+ , format(Date date, DatePattern datePattern, TimeZone timeZone), etc...
+- Assert: Provides wide range of operation for Assertions like nonNull(Object object, Supplier
+ exceptionSupplier), isTrue(boolean expression, Supplier exceptionSupplier),
+ nonNullNonEmpty(Collection> collection, Supplier exceptionSupplier), etc...
+- Objects: Provides wide range of operation on java.lang.Object like isNull(Object obj)
+ , nonNull(Object obj).
+- Regex: Provides wide range of operation using regular expression like isNumber(String value)
+ , isAlphaNumeric(String value), isValidEmail(String value).
- UniqueIdGenerator: Generate unique time based random alphanumeric string like Firebase keys.
# Maven
+
```
com.javaqueryutil
- 1.0.4
+ 1.0.5
```
# Gradle
+
```
-implementation 'com.javaquery:util:1.0.4'
+implementation 'com.javaquery:util:1.0.5'
```
diff --git a/build.gradle b/build.gradle
index b9f64a2..2e23282 100644
--- a/build.gradle
+++ b/build.gradle
@@ -5,7 +5,7 @@ plugins {
}
group 'com.javaquery'
-version '1.0.4'
+version '1.0.5'
repositories {
mavenCentral()
@@ -27,6 +27,17 @@ java {
withSourcesJar()
}
+jar {
+ manifest {
+ attributes(
+ 'Built-By': "Vicky Thakor",
+ 'Created-By': "Gradle ${gradle.gradleVersion}",
+ 'Build-Jdk': "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})",
+ 'Import-Package': "org.json,org.slf4j,*"
+ )
+ }
+}
+
publishing {
publications {
mavenJava(MavenPublication) {
diff --git a/settings.xml b/settings.xml
index 8242ca3..c9c093b 100644
--- a/settings.xml
+++ b/settings.xml
@@ -1,15 +1,15 @@
-
-
-
- ossrh
- ${env.MAVEN_USERNAME}
- ${env.MAVEN_CENTRAL_TOKEN}
-
-
- gpg.passphrase
- ${env.MAVEN_GPG_PASSPHRASE}
-
-
+
+
+
+ ossrh
+ ${env.MAVEN_USERNAME}
+ ${env.MAVEN_CENTRAL_TOKEN}
+
+
+ gpg.passphrase
+ ${env.MAVEN_GPG_PASSPHRASE}
+
+
diff --git a/src/main/java/com/javaquery/util/Assert.java b/src/main/java/com/javaquery/util/Assert.java
index 202ac54..78987e6 100644
--- a/src/main/java/com/javaquery/util/Assert.java
+++ b/src/main/java/com/javaquery/util/Assert.java
@@ -7,133 +7,149 @@
import java.util.function.Supplier;
/**
- * {@code Assert} is a collection of utility methods that helps asserting conditions and throw exception if condition fails
+ * {@code Assert} is a collection of utility methods that helps asserting conditions and throw
+ * exception if condition fails
*
* @author Harshit
* @since 1.0
*/
public final class Assert {
- private Assert() {
- }
+ private Assert() {}
- /**
- * Assert that {@code object} is {@code not null}.
- *
- * @param object object to check
- * @param Type of the exception to be thrown
- * @param exceptionSupplier supplier of a exception to be thrown
- * @throws T if {@code object} is {@code null}
- * @throws NullPointerException if {@code object} is {@code null} and {@code exceptionSupplier} is {@code null}
- */
- public static void nonNull(Object object, Supplier exceptionSupplier) throws T {
- if (Objects.isNull(object)) {
- throw exceptionSupplier.get();
- }
+ /**
+ * Assert that {@code object} is {@code not null}.
+ *
+ * @param object object to check
+ * @param Type of the exception to be thrown
+ * @param exceptionSupplier supplier of a exception to be thrown
+ * @throws T if {@code object} is {@code null}
+ * @throws NullPointerException if {@code object} is {@code null} and {@code exceptionSupplier} is
+ * {@code null}
+ */
+ public static void nonNull(Object object, Supplier exceptionSupplier)
+ throws T {
+ if (Objects.isNull(object)) {
+ throw exceptionSupplier.get();
}
+ }
- /**
- * Assert that {@code object} is {@code null}.
- *
- * @param object object to check
- * @param Type of the exception to be thrown
- * @param exceptionSupplier supplier of a exception to throw
- * @throws T if {@code object} is {@code not null}
- * @throws NullPointerException if {@code object} is {@code not null} and {@code exceptionSupplier} is {@code null}
- */
- public static void isNull(Object object, Supplier exceptionSupplier) throws T {
- if (Objects.nonNull(object)) {
- throw exceptionSupplier.get();
- }
+ /**
+ * Assert that {@code object} is {@code null}.
+ *
+ * @param object object to check
+ * @param Type of the exception to be thrown
+ * @param exceptionSupplier supplier of a exception to throw
+ * @throws T if {@code object} is {@code not null}
+ * @throws NullPointerException if {@code object} is {@code not null} and {@code
+ * exceptionSupplier} is {@code null}
+ */
+ public static void isNull(Object object, Supplier exceptionSupplier)
+ throws T {
+ if (Objects.nonNull(object)) {
+ throw exceptionSupplier.get();
}
+ }
- /**
- * Assert that {@code expression} is {@code true}.
- *
- * @param expression expression to check
- * @param Type of the exception to be thrown
- * @param exceptionSupplier supplier of a exception to throw
- * @throws T if {@code expression} is {@code false}
- * @throws NullPointerException if {@code expression} is {@code false} and {@code exceptionSupplier} is {@code null}
- */
- public static void isTrue(boolean expression, Supplier exceptionSupplier) throws T {
- if (!expression) {
- throw exceptionSupplier.get();
- }
+ /**
+ * Assert that {@code expression} is {@code true}.
+ *
+ * @param expression expression to check
+ * @param Type of the exception to be thrown
+ * @param exceptionSupplier supplier of a exception to throw
+ * @throws T if {@code expression} is {@code false}
+ * @throws NullPointerException if {@code expression} is {@code false} and {@code
+ * exceptionSupplier} is {@code null}
+ */
+ public static void isTrue(boolean expression, Supplier exceptionSupplier)
+ throws T {
+ if (!expression) {
+ throw exceptionSupplier.get();
}
+ }
- /**
- * Assert that {@code expression} is {@code false}.
- *
- * @param expression expression to check
- * @param Type of the exception to be thrown
- * @param exceptionSupplier supplier of a exception to throw
- * @throws T if {@code expression} is {@code true}
- * @throws NullPointerException if {@code expression} is {@code true} and {@code exceptionSupplier} is {@code null}
- */
- public static void isFalse(boolean expression, Supplier exceptionSupplier) throws T {
- if (expression) {
- throw exceptionSupplier.get();
- }
+ /**
+ * Assert that {@code expression} is {@code false}.
+ *
+ * @param expression expression to check
+ * @param Type of the exception to be thrown
+ * @param exceptionSupplier supplier of a exception to throw
+ * @throws T if {@code expression} is {@code true}
+ * @throws NullPointerException if {@code expression} is {@code true} and {@code
+ * exceptionSupplier} is {@code null}
+ */
+ public static void isFalse(
+ boolean expression, Supplier exceptionSupplier) throws T {
+ if (expression) {
+ throw exceptionSupplier.get();
}
+ }
- /**
- * Assert that {@code collection} is {@code not null} and {@code not empty}.
- *
- * @param collection collection to check
- * @param Type of the exception to be thrown
- * @param exceptionSupplier supplier of a exception to throw
- * @throws T if {@code collection} is {@code null} or {@code empty}
- * @throws NullPointerException if {@code collection} is {@code null} or {@code empty} and {@code exceptionSupplier} is {@code null}
- */
- public static void nonNullNonEmpty(Collection> collection, Supplier exceptionSupplier) throws T {
- if (Collections.nullOrEmpty(collection)) {
- throw exceptionSupplier.get();
- }
+ /**
+ * Assert that {@code collection} is {@code not null} and {@code not empty}.
+ *
+ * @param collection collection to check
+ * @param Type of the exception to be thrown
+ * @param exceptionSupplier supplier of a exception to throw
+ * @throws T if {@code collection} is {@code null} or {@code empty}
+ * @throws NullPointerException if {@code collection} is {@code null} or {@code empty} and {@code
+ * exceptionSupplier} is {@code null}
+ */
+ public static void nonNullNonEmpty(
+ Collection> collection, Supplier exceptionSupplier) throws T {
+ if (Collections.nullOrEmpty(collection)) {
+ throw exceptionSupplier.get();
}
+ }
- /**
- * Assert that {@code collection} is {@code null} or {@code empty}.
- *
- * @param collection collection to check
- * @param Type of the exception to be thrown
- * @param exceptionSupplier supplier of a exception to throw
- * @throws T if {@code collection} is {@code not null} and {@code not empty}
- * @throws NullPointerException if {@code collection} is {@code not null} and {@code not empty} and {@code exceptionSupplier} is {@code null}
- */
- public static void nullOrEmpty(Collection> collection, Supplier exceptionSupplier) throws T {
- if (Collections.nonNullNonEmpty(collection)) {
- throw exceptionSupplier.get();
- }
+ /**
+ * Assert that {@code collection} is {@code null} or {@code empty}.
+ *
+ * @param collection collection to check
+ * @param Type of the exception to be thrown
+ * @param exceptionSupplier supplier of a exception to throw
+ * @throws T if {@code collection} is {@code not null} and {@code not empty}
+ * @throws NullPointerException if {@code collection} is {@code not null} and {@code not empty}
+ * and {@code exceptionSupplier} is {@code null}
+ */
+ public static void nullOrEmpty(
+ Collection> collection, Supplier exceptionSupplier) throws T {
+ if (Collections.nonNullNonEmpty(collection)) {
+ throw exceptionSupplier.get();
}
+ }
- /**
- * Assert that {@code map} is {@code not null} and {@code not empty}.
- *
- * @param map map to check
- * @param Type of the exception to be thrown
- * @param exceptionSupplier supplier of a exception to throw
- * @throws T if {@code map} is {@code null} or {@code empty}
- * @throws NullPointerException if {@code map} is {@code null} or {@code empty} and {@code exceptionSupplier} is {@code null}
- */
- public static void nonNullNonEmptyMap(Map, ?> map, Supplier exceptionSupplier) throws T {
- if (Collections.nullOrEmpty(map)) {
- throw exceptionSupplier.get();
- }
+ /**
+ * Assert that {@code map} is {@code not null} and {@code not empty}.
+ *
+ * @param map map to check
+ * @param Type of the exception to be thrown
+ * @param exceptionSupplier supplier of a exception to throw
+ * @throws T if {@code map} is {@code null} or {@code empty}
+ * @throws NullPointerException if {@code map} is {@code null} or {@code empty} and {@code
+ * exceptionSupplier} is {@code null}
+ */
+ public static void nonNullNonEmptyMap(
+ Map, ?> map, Supplier exceptionSupplier) throws T {
+ if (Collections.nullOrEmpty(map)) {
+ throw exceptionSupplier.get();
}
+ }
- /**
- * Assert that {@code map} is {@code null} or {@code empty}.
- *
- * @param map map to check
- * @param Type of the exception to be thrown
- * @param exceptionSupplier supplier of a exception to throw
- * @throws T if {@code map} is {@code not null} and {@code not empty}
- * @throws NullPointerException if {@code map} is {@code not null} and {@code not empty} and {@code exceptionSupplier} is {@code null}
- */
- public static void nullOrEmptyMap(Map, ?> map, Supplier exceptionSupplier) throws T {
- if (Collections.nonNullNonEmpty(map)) {
- throw exceptionSupplier.get();
- }
+ /**
+ * Assert that {@code map} is {@code null} or {@code empty}.
+ *
+ * @param map map to check
+ * @param Type of the exception to be thrown
+ * @param exceptionSupplier supplier of a exception to throw
+ * @throws T if {@code map} is {@code not null} and {@code not empty}
+ * @throws NullPointerException if {@code map} is {@code not null} and {@code not empty} and
+ * {@code exceptionSupplier} is {@code null}
+ */
+ public static void nullOrEmptyMap(
+ Map, ?> map, Supplier exceptionSupplier) throws T {
+ if (Collections.nonNullNonEmpty(map)) {
+ throw exceptionSupplier.get();
}
+ }
}
diff --git a/src/main/java/com/javaquery/util/Objects.java b/src/main/java/com/javaquery/util/Objects.java
index d9d4345..973fdfe 100644
--- a/src/main/java/com/javaquery/util/Objects.java
+++ b/src/main/java/com/javaquery/util/Objects.java
@@ -6,30 +6,41 @@
*/
public final class Objects {
- private Objects() {
- }
+ private Objects() {}
- /**
- * Returns {@code true} if the provided reference is {@code null} otherwise
- * returns {@code false}.
- *
- * @param obj a reference to be checked against {@code null}
- * @return {@code true} if the provided reference is {@code null} otherwise
- * {@code false}
- */
- public static boolean isNull(Object obj) {
- return obj == null;
- }
+ /**
+ * Returns {@code true} if the provided reference is {@code null} otherwise returns {@code false}.
+ *
+ * @param obj a reference to be checked against {@code null}
+ * @return {@code true} if the provided reference is {@code null} otherwise {@code false}
+ */
+ public static boolean isNull(Object obj) {
+ return obj == null;
+ }
- /**
- * Returns {@code true} if the provided reference is non-{@code null}
- * otherwise returns {@code false}.
- *
- * @param obj a reference to be checked against {@code null}
- * @return {@code true} if the provided reference is non-{@code null}
- * otherwise {@code false}
- */
- public static boolean nonNull(Object obj) {
- return obj != null;
- }
+ /**
+ * Returns {@code true} if the provided reference is non-{@code null} otherwise returns {@code
+ * false}.
+ *
+ * @param obj a reference to be checked against {@code null}
+ * @return {@code true} if the provided reference is non-{@code null} otherwise {@code false}
+ */
+ public static boolean nonNull(Object obj) {
+ return obj != null;
+ }
+
+ /**
+ * Returns {@code true} if the arguments are equal to each other and {@code false} otherwise.
+ * Consequently, if both arguments are {@code null}, {@code true} is returned and if exactly one
+ * argument is {@code null}, {@code false} is returned. Otherwise, equality is determined by using
+ * the {@link Object#equals equals} method of the first argument.
+ *
+ * @param a an object
+ * @param b an object to be compared with {@code a} for equality
+ * @return {@code true} if the arguments are equal to each other and {@code false} otherwise
+ * @see Object#equals(Object)
+ */
+ public static boolean equals(Object a, Object b) {
+ return (a == b) || (a != null && a.equals(b));
+ }
}
diff --git a/src/main/java/com/javaquery/util/Regex.java b/src/main/java/com/javaquery/util/Regex.java
index a966c9e..1996e08 100644
--- a/src/main/java/com/javaquery/util/Regex.java
+++ b/src/main/java/com/javaquery/util/Regex.java
@@ -8,48 +8,45 @@
*/
public final class Regex {
- public static final String REGEX_NUMBER = "^-?[0-9]\\d*(\\.\\d+)?$";
- public static final String REGEX_ALPHA_NUMERIC = "^[a-zA-Z0-9]*$";
- public static final String REGEX_EMAIL =
- "^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))[^_@!*]*?$";
- public static final Pattern EMAIL_PATTERN = Pattern.compile(REGEX_EMAIL);
+ public static final String REGEX_NUMBER = "^-?[0-9]\\d*(\\.\\d+)?$";
+ public static final String REGEX_ALPHA_NUMERIC = "^[a-zA-Z0-9]*$";
+ public static final String REGEX_EMAIL =
+ "^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))[^_@!*]*?$";
+ public static final Pattern EMAIL_PATTERN = Pattern.compile(REGEX_EMAIL);
- private Regex() {
- }
+ private Regex() {}
- /**
- * Returns {@code true} if the provided String is valid number otherwise
- * returns {@code false}.
- *
- * @param value a String to be checked against number regular expression
- * @return Returns {@code true} if the provided String is valid number otherwise
- * returns {@code false}.
- */
- public static boolean isNumber(String value) {
- return Objects.nonNull(value) && value.matches(Regex.REGEX_NUMBER);
- }
+ /**
+ * Returns {@code true} if the provided String is valid number otherwise returns {@code false}.
+ *
+ * @param value a String to be checked against number regular expression
+ * @return Returns {@code true} if the provided String is valid number otherwise returns {@code
+ * false}.
+ */
+ public static boolean isNumber(String value) {
+ return Objects.nonNull(value) && value.matches(Regex.REGEX_NUMBER);
+ }
- /**
- * Returns {@code true} if the provided String is valid alpha numeric otherwise
- * returns {@code false}.
- *
- * @param value a String to be checked against alpha numeric regular expression
- * @return Returns {@code true} if the provided String is valid alpha numeric otherwise
- * returns {@code false}.
- */
- public static boolean isAlphaNumeric(String value) {
- return Objects.nonNull(value) && value.matches(Regex.REGEX_ALPHA_NUMERIC);
- }
+ /**
+ * Returns {@code true} if the provided String is valid alpha numeric otherwise returns {@code
+ * false}.
+ *
+ * @param value a String to be checked against alpha numeric regular expression
+ * @return Returns {@code true} if the provided String is valid alpha numeric otherwise returns
+ * {@code false}.
+ */
+ public static boolean isAlphaNumeric(String value) {
+ return Objects.nonNull(value) && value.matches(Regex.REGEX_ALPHA_NUMERIC);
+ }
- /**
- * Returns {@code true} if the provided String is valid email otherwise
- * returns {@code false}.
- *
- * @param value a String to be checked against email regular expression
- * @return Returns {@code true} if the provided String is valid email otherwise
- * returns {@code false}.
- */
- public static boolean isValidEmail(String value) {
- return Objects.nonNull(value) && Regex.EMAIL_PATTERN.matcher(value).matches();
- }
+ /**
+ * Returns {@code true} if the provided String is valid email otherwise returns {@code false}.
+ *
+ * @param value a String to be checked against email regular expression
+ * @return Returns {@code true} if the provided String is valid email otherwise returns {@code
+ * false}.
+ */
+ public static boolean isValidEmail(String value) {
+ return Objects.nonNull(value) && Regex.EMAIL_PATTERN.matcher(value).matches();
+ }
}
diff --git a/src/main/java/com/javaquery/util/UniqueIdGenerator.java b/src/main/java/com/javaquery/util/UniqueIdGenerator.java
index 43a13c6..4af23e3 100644
--- a/src/main/java/com/javaquery/util/UniqueIdGenerator.java
+++ b/src/main/java/com/javaquery/util/UniqueIdGenerator.java
@@ -6,61 +6,61 @@
*/
public class UniqueIdGenerator {
- // Modeled after base64 web-safe chars, but ordered by ASCII.
- private final static String PUSH_CHARS = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
- // We generate 72-bits of randomness which get turned into 12 characters and
- // appended to the timestamp to prevent collisions with other clients. We store the last
- // characters we generated because in the event of a collision, we'll use those same
- // characters except "incremented" by one.
- private static final int[] LAST_RAND_CHARS = new int[72];
- // Timestamp of last push, used to prevent local collisions if you push twice in one ms.
- private static long LAST_PUSH_TIME = 0L;
+ // Modeled after base64 web-safe chars, but ordered by ASCII.
+ private static final String PUSH_CHARS =
+ "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
+ // We generate 72-bits of randomness which get turned into 12 characters and
+ // appended to the timestamp to prevent collisions with other clients. We store the last
+ // characters we generated because in the event of a collision, we'll use those same
+ // characters except "incremented" by one.
+ private static final int[] LAST_RAND_CHARS = new int[72];
+ // Timestamp of last push, used to prevent local collisions if you push twice in one ms.
+ private static long LAST_PUSH_TIME = 0L;
- private UniqueIdGenerator() {
- }
-
- public static synchronized String generate() {
- long now = System.currentTimeMillis();
- boolean duplicateTime = now == LAST_PUSH_TIME;
- LAST_PUSH_TIME = now;
+ private UniqueIdGenerator() {}
- char[] timeStampChars = new char[8];
- for (int i = 7; i >= 0; i--) {
- timeStampChars[i] = PUSH_CHARS.charAt((int) (now % 64));
- now = (long) Math.floor((double) (now / 64));
- }
+ public static synchronized String generate() {
+ long now = System.currentTimeMillis();
+ boolean duplicateTime = now == LAST_PUSH_TIME;
+ LAST_PUSH_TIME = now;
- if (now != 0) {
- throw new AssertionError("We should have converted the entire timestamp.");
- }
+ char[] timeStampChars = new char[8];
+ for (int i = 7; i >= 0; i--) {
+ timeStampChars[i] = PUSH_CHARS.charAt((int) (now % 64));
+ now = (long) Math.floor((double) (now / 64));
+ }
- StringBuilder id = new StringBuilder(20);
- for (char c : timeStampChars) {
- id.append(c);
- }
+ if (now != 0) {
+ throw new AssertionError("We should have converted the entire timestamp.");
+ }
- if (!duplicateTime) {
- for (int i = 0; i < 12; i++) {
- LAST_RAND_CHARS[i] = (int) Math.floor(Double.valueOf(Math.random() * 64).intValue());
- }
- } else {
- // If the timestamp hasn't changed since last push, use the same random number,
- //except incremented by 1.
- int i;
- for (i = 11; i >= 0 && LAST_RAND_CHARS[i] == 63; i--) {
- LAST_RAND_CHARS[i] = 0;
- }
- LAST_RAND_CHARS[i]++;
- }
+ StringBuilder id = new StringBuilder(20);
+ for (char c : timeStampChars) {
+ id.append(c);
+ }
- for (int i = 0; i < 12; i++) {
- id.append(PUSH_CHARS.charAt(LAST_RAND_CHARS[i]));
- }
+ if (!duplicateTime) {
+ for (int i = 0; i < 12; i++) {
+ LAST_RAND_CHARS[i] = (int) Math.floor(Double.valueOf(Math.random() * 64).intValue());
+ }
+ } else {
+ // If the timestamp hasn't changed since last push, use the same random number,
+ // except incremented by 1.
+ int i;
+ for (i = 11; i >= 0 && LAST_RAND_CHARS[i] == 63; i--) {
+ LAST_RAND_CHARS[i] = 0;
+ }
+ LAST_RAND_CHARS[i]++;
+ }
- if (id.length() != 20) {
- throw new AssertionError("Length should be 20.");
- }
+ for (int i = 0; i < 12; i++) {
+ id.append(PUSH_CHARS.charAt(LAST_RAND_CHARS[i]));
+ }
- return id.substring(1);
+ if (id.length() != 20) {
+ throw new AssertionError("Length should be 20.");
}
+
+ return id.substring(1);
+ }
}
diff --git a/src/main/java/com/javaquery/util/collection/Collections.java b/src/main/java/com/javaquery/util/collection/Collections.java
index 34661c1..9f50cf0 100644
--- a/src/main/java/com/javaquery/util/collection/Collections.java
+++ b/src/main/java/com/javaquery/util/collection/Collections.java
@@ -16,223 +16,211 @@
*/
public final class Collections {
- private Collections() {
+ private Collections() {}
+
+ /**
+ * Returns {@code true} if the provided Collection [List, Set] is {@code null} or empty otherwise
+ * returns {@code false}.
+ *
+ * @param collection a Collection [List, Set] to be checked against {@code null} or empty
+ * @return {@code true} if the provided Collection [List, Set] is {@code null} or empty otherwise
+ * {@code false}
+ */
+ public static boolean nullOrEmpty(Collection> collection) {
+ return Objects.isNull(collection) || collection.isEmpty();
+ }
+
+ /**
+ * Returns {@code true} if the provided Collection [List, Set] is non-{@code null} and non-empty
+ * otherwise returns {@code false}.
+ *
+ * @param collection a Collection [List, Set] to be checked against non-{@code null} and non-empty
+ * @return {@code true} if the provided Collection [List, Set] is non-{@code null} and non-empty
+ * otherwise {@code false}
+ */
+ public static boolean nonNullNonEmpty(Collection> collection) {
+ return Objects.nonNull(collection) && !collection.isEmpty();
+ }
+
+ /**
+ * Returns {@code true} if the provided Map is {@code null} and empty otherwise returns {@code
+ * false}.
+ *
+ * @param map a Map to be checked against {@code null} or empty
+ * @return {@code true} if the provided Map is {@code null} and empty otherwise * returns {@code
+ * false}
+ */
+ public static boolean nullOrEmpty(Map, ?> map) {
+ return Objects.isNull(map) || map.isEmpty();
+ }
+
+ /**
+ * Returns {@code true} if the provided Map is non-{@code null} and non-empty otherwise returns
+ * {@code false}.
+ *
+ * @param map a Map to be checked against non-{@code null} and non-empty
+ * @return {@code true} if the provided Map is non-{@code null} and non-empty otherwise {@code
+ * false}
+ */
+ public static boolean nonNullNonEmpty(Map, ?> map) {
+ return Objects.nonNull(map) && !map.isEmpty();
+ }
+
+ /**
+ * Returns stream of batched List from original List by given batch size.
+ *
+ * @param source a List to be batched
+ * @param batchSize size of batch you want
+ * @param the type of List to be returned.
+ * @return Returns stream of batched List from original List by given batch size.
+ *
reference:
+ * http://stackoverflow.com/questions/12026885/common-util-to-break-a-list-into-batch
+ */
+ public static Stream> batches(List source, int batchSize) {
+ if (Objects.isNull(source)) throw new IllegalArgumentException("source can not be null");
+
+ int size = source.size();
+ if (batchSize < 0) {
+ throw new IllegalArgumentException("batchSize can not be negative");
+ } else if (batchSize == 0 && size != 0) {
+ return Stream.of(source);
}
-
- /**
- * Returns {@code true} if the provided Collection [List, Set] is {@code null} or empty otherwise
- * returns {@code false}.
- *
- * @param collection a Collection [List, Set] to be checked against {@code null} or empty
- * @return {@code true} if the provided Collection [List, Set] is {@code null} or empty
- * otherwise {@code false}
- */
- public static boolean nullOrEmpty(Collection> collection) {
- return Objects.isNull(collection) || collection.isEmpty();
+ if (size <= 0) return Stream.empty();
+ int fullChunks = (size - 1) / batchSize;
+ return IntStream.range(0, fullChunks + 1)
+ .mapToObj(n -> source.subList(n * batchSize, n == fullChunks ? size : (n + 1) * batchSize));
+ }
+
+ /**
+ * Note: Code imported from apache commons collection
+ *
+ *
Returns {@code true} iff the given {@link Collection}s contain exactly the same elements
+ * with exactly the same cardinalities.
+ *
+ *
That is, iff the cardinality of e in a is equal to the cardinality of e
+ * in b, for each element e in a or b
.
+ *
+ * @param collectionOne the first collection, must not be null
+ * @param collectionTwo the second collection, must not be null
+ * @return {@code true} iff the collections contain the same elements with the same cardinalities.
+ * @throws NullPointerException if either collection is null
+ * @since 1.0.3
+ */
+ public static boolean isCollectionEqual(
+ final Collection> collectionOne, final Collection> collectionTwo) {
+ Assert.nonNull(collectionOne, NullPointerException::new);
+ Assert.nonNull(collectionTwo, NullPointerException::new);
+
+ if (collectionOne.size() != collectionTwo.size()) {
+ return false;
}
- /**
- * Returns {@code true} if the provided Collection [List, Set] is non-{@code null} and non-empty otherwise
- * returns {@code false}.
- *
- * @param collection a Collection [List, Set] to be checked against non-{@code null} and non-empty
- * @return {@code true} if the provided Collection [List, Set] is non-{@code null} and non-empty
- * otherwise {@code false}
- */
- public static boolean nonNullNonEmpty(Collection> collection) {
- return Objects.nonNull(collection) && !collection.isEmpty();
+ final CardinalityHelper