io.hawt.log.support.Objects Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hawtio-insight-log Show documentation
Show all versions of hawtio-insight-log Show documentation
hawtio :: hawtio-insight-log
package io.hawt.log.support;
public final class Objects {
public static boolean isBlank(String text) {
return text == null || text.trim().length() == 0;
}
/**
* A helper method for comparing objects for equality while handling nulls
*/
public static boolean equal(Object a, Object b) {
if (a == b) {
return true;
}
return a != null && b != null && a.equals(b);
}
/**
* A helper method for performing an ordered comparison on the objects
* handling nulls and objects which do not handle sorting gracefully
*
* @param a the first object
* @param b the second object
*/
@SuppressWarnings("unchecked")
public static int compare(Object a, Object b) {
if (a == b) {
return 0;
}
if (a == null) {
return -1;
}
if (b == null) {
return 1;
}
if (a instanceof Comparable) {
Comparable comparable = (Comparable)a;
return comparable.compareTo(b);
}
int answer = a.getClass().getName().compareTo(b.getClass().getName());
if (answer == 0) {
answer = a.hashCode() - b.hashCode();
}
return answer;
}
public static boolean contains(String matchesText, String... values) {
for (String v : values) {
if (v != null && v.contains(matchesText)) {
return true;
}
}
return false;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy