Java Code Examples for java.util.Objects.compare()

The following are Jave code examples for showing how to use compare() of the java.util.Objects class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: de.flapdoodle.solid   File: Blobs.java   View Source Code Vote up 5 votes
private static Comparator<? super Entry<ImmutableMap<String, Object>, Collection<Blob>>> pathOrderingOf(ImmutableList<String> pathOrdering) {
	return (Entry<ImmutableMap<String, Object>, Collection<Blob>> l,Entry<ImmutableMap<String, Object>, Collection<Blob>> r) -> {
		for (String key : pathOrdering) {
			int ret=Objects.compare(asString(l.getKey().get(key)), asString(r.getKey().get(key)), Ordering.natural());
			if (ret!=0) {
				return ret;
			}
		}
		return 0;
	};
}
 
Example 2
Project: jdk8u-jdk   File: NewUnsafeString.java   View Source Code Vote up 4 votes
public static void testNewUnsafeString() {
    String benchmark = "exemplar";
    String constructorCopy = new String(benchmark);
    char[] jlaChars = benchmark.toCharArray();
    String jlaCopy = jla.newStringUnsafe(jlaChars);

    if (benchmark == constructorCopy) {
        throw new Error("should be different instances");
    }
    if (!benchmark.equals(constructorCopy)) {
        throw new Error("Copy not equal");
    }
    if (0 != Objects.compare(benchmark, constructorCopy, Comparator.naturalOrder())) {
        throw new Error("Copy not equal");
    }

    if (benchmark == jlaCopy) {
        throw new Error("should be different instances");
    }
    if (!benchmark.equals(jlaCopy)) {
        throw new Error("Copy not equal");
    }
    if (0 != Objects.compare(benchmark, jlaCopy, Comparator.naturalOrder())) {
        throw new Error("Copy not equal");
    }

    if (constructorCopy == jlaCopy) {
        throw new Error("should be different instances");
    }
    if (!constructorCopy.equals(jlaCopy)) {
        throw new Error("Copy not equal");
    }
    if (0 != Objects.compare(constructorCopy, jlaCopy, Comparator.naturalOrder())) {
        throw new Error("Copy not equal");
    }

    // The following is extremely "evil". Never ever do this in non-test code.
    jlaChars[0] = 'X';
    if (!"Xxemplar".equals(jlaCopy)) {
        throw new Error("jla.newStringUnsafe did not use provided string");
    }

}
 
Example 3
Project: openjdk-jdk10   File: NewUnsafeString.java   View Source Code Vote up 4 votes
public static void testNewUnsafeString() {
    String benchmark = "exemplar";
    String constructorCopy = new String(benchmark);
    char[] jlaChars = benchmark.toCharArray();
    String jlaCopy = jla.newStringUnsafe(jlaChars);

    if (benchmark == constructorCopy) {
        throw new Error("should be different instances");
    }
    if (!benchmark.equals(constructorCopy)) {
        throw new Error("Copy not equal");
    }
    if (0 != Objects.compare(benchmark, constructorCopy, Comparator.naturalOrder())) {
        throw new Error("Copy not equal");
    }

    if (benchmark == jlaCopy) {
        throw new Error("should be different instances");
    }
    if (!benchmark.equals(jlaCopy)) {
        throw new Error("Copy not equal");
    }
    if (0 != Objects.compare(benchmark, jlaCopy, Comparator.naturalOrder())) {
        throw new Error("Copy not equal");
    }

    if (constructorCopy == jlaCopy) {
        throw new Error("should be different instances");
    }
    if (!constructorCopy.equals(jlaCopy)) {
        throw new Error("Copy not equal");
    }
    if (0 != Objects.compare(constructorCopy, jlaCopy, Comparator.naturalOrder())) {
        throw new Error("Copy not equal");
    }

    // The following is extremely "evil". Never ever do this in non-test code.
    jlaChars[0] = 'X';
    if (!"Xxemplar".equals(jlaCopy)) {
        throw new Error("jla.newStringUnsafe did not use provided string");
    }

}