<editor-fold desc="null safe comparable">
180065
public static <T extends Comparable> int compare(@Nullable T first, @Nullable T second) {
        return compare(first, second, Comparable::compareTo);
    }
297057
public static <T> void writeNullable(
      @Nullable T value, @NonNull Parcel dest, int flags, @NonNull TypeAdapter<T> adapter) {
    if (value == null) {
      dest.writeInt(0);
    } else {
      dest.writeInt(1);
      adapter.writeToParcel(value, dest, flags);
    }
  }
1201551
@SuppressWarnings("deprecation")
    @Override
    public int compareTo(Evidence o) {
        if (o == null) {
            throw new IllegalArgumentException("Unable to compare null evidence");
        }
        if (StringUtils.equalsIgnoreCase(source, o.source)) {
            if (StringUtils.equalsIgnoreCase(name, o.name)) {
                if (StringUtils.equalsIgnoreCase(value, o.value)) {
                    //TODO the call to ObjectUtils.equals needs to be replaced when we
                    //stop supporting Jenkins 1.6 requirement.
                    if (ObjectUtils.equals(confidence, o.confidence)) {
                        return 0; //they are equal
                    } else {
                        return ObjectUtils.compare(confidence, o.confidence);
                    }
                } else {
                    return compareToIgnoreCaseWithNullCheck(value, o.value);
                }
            } else {
                return compareToIgnoreCaseWithNullCheck(name, o.name);
            }
        } else {
            return compareToIgnoreCaseWithNullCheck(source, o.source);
        }
    }
756532
@Override
  public int compareTo(TaskDetails otherTask) {
    if (otherTask == null) {
      return -1;
    }

    return new CompareToBuilder().append(this.taskKey, otherTask.getTaskKey())
        .toComparison();
  }
963334
public static <T> T nullable(Class<T> clazz) {
        AdditionalMatchers.or(isNull(), isA(clazz));
        return  (T) Primitives.defaultValue(clazz);
    }
61946
@SuppressWarnings({ "rawtypes", "unchecked" })
    public static int compareTo(final Comparable thisValue, final Comparable otherValue, final OrderDirection orderDirection, final OrderDirection nullOrderDirection) {
        if (null == thisValue && null == otherValue) {
            return 0;
        }
        if (null == thisValue) {
            return orderDirection == nullOrderDirection ? -1 : 1;
        }
        if (null == otherValue) {
            return orderDirection == nullOrderDirection ? 1 : -1;
        }
        return OrderDirection.ASC == orderDirection ? thisValue.compareTo(otherValue) : -thisValue.compareTo(otherValue);
    }
65241
@SuppressWarnings("unchecked")
	private <T> T nullFor(DataType dataType)
	{
		switch(dataType)
		{
			case Long: return (T)Long.valueOf(-1);
			default: return null;
		}
	}
1211948
@Override
    protected void compareData(ITable expectedTable, ITable actualTable, ComparisonColumn[] comparisonCols, FailureHandler failureHandler) throws DataSetException {
        logger.debug("compareData(expectedTable={}, actualTable={}, "
                        + "comparisonCols={}, failureHandler={}) - start",
                new Object[]{expectedTable, actualTable, comparisonCols,
                        failureHandler});

        if (expectedTable == null) {
            throw new NullPointerException(
                    "The parameter 'expectedTable' must not be null");
        }
        if (actualTable == null) {
            throw new NullPointerException(
                    "The parameter 'actualTable' must not be null");
        }
        if (comparisonCols == null) {
            throw new NullPointerException(
                    "The parameter 'comparisonCols' must not be null");
        }
        if (failureHandler == null) {
            throw new NullPointerException(
                    "The parameter 'failureHandler' must not be null");
        }

        // iterate over all rows
        for (int i = 0; i < expectedTable.getRowCount(); i++) {
            // iterate over all columns of the current row
            for (int j = 0; j < comparisonCols.length; j++) {
                ComparisonColumn compareColumn = comparisonCols[j];

                String columnName = compareColumn.getColumnName();
                DataType dataType = compareColumn.getDataType();

                Object expectedValue = expectedTable.getValue(i, columnName);
                Object actualValue = actualTable.getValue(i, columnName);

                // Compare the values
                if (skipCompare(columnName, expectedValue, actualValue)) {
                    if (logger.isTraceEnabled()) {
                        logger.trace("ignoring comparison " + expectedValue + "=" +
                                actualValue + " on column " + columnName);
                    }
                    continue;
                }

                if(expectedValue != null && expectedValue.toString().startsWith("regex:")){
                    if(!regexMatches(expectedValue.toString(),actualValue.toString())){
                        Difference diff = new Difference(
                                expectedTable, actualTable,
                                i, columnName,
                                expectedValue, actualValue);

                        // Handle the difference (throw error immediately or something else)
                        failureHandler.handle(diff);
                    }
                }
                else if (dataType.compare(expectedValue, actualValue) != 0) {

                    Difference diff = new Difference(
                            expectedTable, actualTable,
                            i, columnName,
                            expectedValue, actualValue);

                    // Handle the difference (throw error immediately or something else)
                    failureHandler.handle(diff);
                }
            }
        }
    }
802794
public static ComparatorItem fromSortOrder(Sort.Order sortOrder) {
    if (sortOrder == null || sortOrder.getProperty() == null
        || sortOrder.getProperty().trim().length() == 0) {
      return null;
    }
    boolean nullIsFirst = Sort.NullHandling.NULLS_FIRST.equals(sortOrder.getNullHandling());
    return new ComparatorItem(sortOrder.getProperty(), sortOrder.isAscending(),
        sortOrder.isIgnoreCase(),
        nullIsFirst);
  }
1258631
@Override
  public void endVisit(MethodDeclaration node) {
    ExecutableElement element = node.getExecutableElement();
    if (!ElementUtil.getName(element).equals("compareTo") || node.getBody() == null) {
      return;
    }
    DeclaredType comparableType = typeUtil.findSupertype(
        ElementUtil.getDeclaringClass(element).asType(), "java.lang.Comparable");
    if (comparableType == null) {
      return;
    }
    List<? extends TypeMirror> typeArguments = comparableType.getTypeArguments();
    List<? extends VariableElement> parameters = element.getParameters();
    if (typeArguments.size() != 1 || parameters.size() != 1
        || !typeArguments.get(0).equals(parameters.get(0).asType())) {
      return;
    }

    VariableElement param = node.getParameter(0).getVariableElement();

    FunctionInvocation castCheck = createCastCheck(typeArguments.get(0), new SimpleName(param));
    if (castCheck != null) {
      node.getBody().addStatement(0, new ExpressionStatement(castCheck));
    }
  }
218702
public void validate(Object o)
    {
        if (o != null && o instanceof Comparable)
        {
            compareMinExclusive((Comparable<?>)o);
            compareMinInclusive((Comparable<?>)o);
            compareMaxExclusive((Comparable<?>)o);
            compareMaxInclusive((Comparable<?>)o);
        }
    }
983297
static Class<?> comparableClassFor(Object x) {
        if (x instanceof Comparable) {
            Class<?> c; Type[] ts, as; Type t; ParameterizedType p;
            if ((c = x.getClass()) == String.class) // bypass checks
                return c;
            if ((ts = c.getGenericInterfaces()) != null) {
                for (int i = 0; i < ts.length; ++i) {
                    if (((t = ts[i]) instanceof ParameterizedType) &&
                        ((p = (ParameterizedType)t).getRawType() ==
                         Comparable.class) &&
                        (as = p.getActualTypeArguments()) != null &&
                        as.length == 1 && as[0] == c) // type arg is c
                        return c;
                }
            }
        }
        return null;
    }
1246176
public static <Value extends Comparable<Value>> int nullSafeCompare(final Value first, final Value second) {
        if (first == null) {
            return second == null ? EQUAL_COMPARE_RESULT : LOWER_THAN_COMPARE_RESULT;
        }
        return second == null ? GREATER_THAN_COMPARE_RESULT : first.compareTo(second);
    }
1078397
public static <T extends Comparable<T>> int compare(T o1, T o2) {
		if(o1 == null) {
			return o2 == null ? 0 : 1;
		} else if(o2 == null) {
			return -1;
		} else {
			return o1.compareTo(o2);
		}
	}
311599
@Override
    public int compareTo(final AbstractAttr<T> otherObj) {
        if (otherObj == null) {
            return 1;
        } else {
            return value.compareTo(otherObj.value);
        }
    }
969631
@Override
    public VariableNullability appendNewVariables(ImmutableMap<Variable, Variable> nullabilityBindings) {
        ImmutableList<ImmutableSet<Variable>> groupList = ImmutableList.copyOf(nullableGroups);
        ImmutableMap<Variable, Integer> originalVariableMap = extractVariableMap(groupList);

        AtomicInteger groupCount = new AtomicInteger(groupList.size());

        ImmutableMultimap<Integer, Variable> newVariableMultimap = nullabilityBindings.entrySet().stream()
                .collect(ImmutableCollectors.toMultimap(
                        e -> e.getKey().equals(e.getValue())
                                ? groupCount.getAndIncrement()
                                : originalVariableMap.get(e.getValue()),
                        Map.Entry::getKey));

        ImmutableSet<ImmutableSet<Variable>> newNullableGroups = IntStream.range(0, groupCount.get())
                .boxed()
                .map(i -> i < groupList.size()
                        ? Sets.union(groupList.get(i), ImmutableSet.copyOf(newVariableMultimap.get(i)))
                            .immutableCopy()
                        : ImmutableSet.copyOf(newVariableMultimap.get(i)))
                .collect(ImmutableCollectors.toSet());

        return new VariableNullabilityImpl(newNullableGroups);
    }
1160619
@Deprecated
  public static <T extends Comparable> Comparator<T> comparable()
  {
    return new Comparator<T>()
    {
      @Override
      public int compare(T t, T t1)
      {
        return t.compareTo(t1);
      }
    };
  }