Errai 3.0.1-SNAPSHOT

org.jboss.errai.jpa.client.local.backend
Class Comparisons

java.lang.Object
  extended by org.jboss.errai.jpa.client.local.backend.Comparisons

public class Comparisons
extends Object

Non-instantiable utility methods for comparing two or more values.

Author:
Jonathan Fuerth

Constructor Summary
Comparisons()
           
 
Method Summary
static String escapeRegexChar(char ch)
           
static boolean in(Object thingToCompare, Object[] collection)
          Tests if the first argument is equal to any of the remaining arguments.
static Boolean like(String value, String pattern, String escapeChar)
          Checks of the given value matches the given JPQL wildcard pattern.
static int nullSafeCompare(Comparable c1, Comparable c2)
          Compares one potentially null Comparable to another.
static boolean nullSafeEquals(Object o1, Object o2)
          Tests two potentially null object references for equality using approximate JPQL/SQL null semantics.
static boolean nullSafeGreaterThan(Object o1, Object o2)
          Tests if one potentially null object reference is greater than another.
static boolean nullSafeGreaterThanOrEqualTo(Object o1, Object o2)
          Tests if one potentially null object reference is greater than another.
static boolean nullSafeLessThan(Object o1, Object o2)
          Tests if one potentially null object reference is greater than another.
static boolean nullSafeLessThanOrEqualTo(Object o1, Object o2)
          Tests if one potentially null object reference is greater than another.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Comparisons

public Comparisons()
Method Detail

nullSafeEquals

public static boolean nullSafeEquals(Object o1,
                                     Object o2)
Tests two potentially null object references for equality using approximate JPQL/SQL null semantics.

Specifically, this method returns true if and only if both arguments are non-null and either of the following conditions are met:

  1. o1 == o2
  2. o1.equals(o2)

Parameters:
o1 - One object to compare. Null is permitted.
o2 - The other object to compare. Null is permitted.
Returns:
true if o1 and o2 are equal (either by reference equality or by Object.equals()); false otherwise

nullSafeGreaterThan

public static boolean nullSafeGreaterThan(Object o1,
                                          Object o2)
Tests if one potentially null object reference is greater than another.

Parameters:
o1 - One object to compare. Null is permitted.
o2 - The other object to compare. Null is permitted.
Returns:
true if o1 > o2 (either by primitive comparison or by Comparable.compareTo()); false otherwise

nullSafeGreaterThanOrEqualTo

public static boolean nullSafeGreaterThanOrEqualTo(Object o1,
                                                   Object o2)
Tests if one potentially null object reference is greater than another.

Parameters:
o1 - One object to compare. Null is permitted.
o2 - The other object to compare. Null is permitted.
Returns:
true if o1 > o2 (either by primitive comparison or by Comparable.compareTo()); false otherwise

nullSafeLessThan

public static boolean nullSafeLessThan(Object o1,
                                       Object o2)
Tests if one potentially null object reference is greater than another.

Parameters:
o1 - One object to compare. Null is permitted.
o2 - The other object to compare. Null is permitted.
Returns:
true if o1 > o2 (either by primitive comparison or by Comparable.compareTo()); false otherwise

nullSafeLessThanOrEqualTo

public static boolean nullSafeLessThanOrEqualTo(Object o1,
                                                Object o2)
Tests if one potentially null object reference is greater than another.

Parameters:
o1 - One object to compare. Null is permitted.
o2 - The other object to compare. Null is permitted.
Returns:
true if o1 > o2 (either by primitive comparison or by Comparable.compareTo()); false otherwise

nullSafeCompare

public static int nullSafeCompare(Comparable c1,
                                  Comparable c2)
Compares one potentially null Comparable to another.

Parameters:
c1 - One object to compare. Null is permitted.
c2 - The other object to compare. Null is permitted.
Returns:
0 if c1 and c2 are both null; -1 if c1 is null and c2 is not; 1 if c1 is not null and c2 is. Otherwise returns c1.compareTo(c2).

in

public static boolean in(Object thingToCompare,
                         Object[] collection)
Tests if the first argument is equal to any of the remaining arguments. Equality is tested using nullSafeEquals(Object, Object).

Special Case
If the collection has only one item in it, and that item is assignable to Collection, then that collection will be searched rather than being treated as a single scalar value. This allows correct behaviour for a JPQL query SELECT x FROM MyClass x WHERE x.prop IN :param and param resolves to a collection value at runtime.

Parameters:
thingToCompare - The item to compare against the remaining arguments.
collection - One or more items to test for equality with thingToCompare .
Returns:
True if there is an item in collection that compares equal with thingToCompare. False otherwise.

like

public static Boolean like(String value,
                           String pattern,
                           String escapeChar)
Checks of the given value matches the given JPQL wildcard pattern.

Parameters:
value - The string value to test. May be null.
pattern - The JPQL pattern to test against. Special characters are "_ ", which matches any single character, and "%", which matches 0 or more characters.

escapeRegexChar

public static String escapeRegexChar(char ch)

Errai 3.0.1-SNAPSHOT

Copyright © 2013-2014 JBoss, a division of Red Hat. All Rights Reserved.