本文整理汇总了Java中java.util.Objects.compare方法的典型用法代码示例。如果您正苦于以下问题:Java Objects.compare方法的具体用法?Java Objects.compare怎么用?Java Objects.compare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Objects
的用法示例。
在下文中一共展示了Objects.compare方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: pathOrderingOf
import java.util.Objects; //导入方法依赖的package包/类
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;
};
}
示例2: testNewUnsafeString
import java.util.Objects; //导入方法依赖的package包/类
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");
}
}