本文整理了Java中java.util.Objects.compare()
方法的一些代码示例,展示了Objects.compare()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Objects.compare()
方法的具体详情如下:
包路径:java.util.Objects
类名称:Objects
方法名:compare
[英]Returns 0 if a == b, or c.compare(a, b) otherwise. That is, this makes c null-safe.
[中]如果a==b,则返回0,否则返回c.compare(a,b)。也就是说,这使得c null安全。
代码示例来源:origin: apache/hive
@Override
public int compare(Operator<?> o1, Operator<?> o2) {
Long id1 = Long.valueOf(o1.getIdentifier());
Long id2 = Long.valueOf(o2.getIdentifier());
int c0 = Objects.compare(o1.getOperatorName(), o2.getOperatorName(), Comparator.naturalOrder());
if (c0 != 0) {
return c0;
}
return Long.compare(id1, id2);
}
};
代码示例来源:origin: OpenNMS/opennms
@Override
public int compareTo(final CompAttrib o) {
return Objects.compare(this, o, COMPARATOR);
}
}
代码示例来源:origin: OpenNMS/opennms
@Override
public int compareTo(final Attrib o) {
return Objects.compare(this, o, COMPARATOR);
}
}
代码示例来源:origin: org.omnifaces/omniutils
@Override
protected int compare(N left, N right) {
return Objects.compare(left, right, comparator);
}
}
代码示例来源:origin: org.omnifaces/omniutils
@Override
protected int compare(N left, N right) {
return Objects.compare(left, right, comparator);
}
代码示例来源:origin: OpenNMS/opennms
@Override
public int compareTo(final CompMember o) {
return Objects.compare(this, o, COMPARATOR);
}
代码示例来源:origin: mcekovic/tennis-crystal-ball
public static <T extends Comparable<T>> int nullsLastCompare(T t1, T t2) {
return Objects.compare(t1, t2, NULLS_LAST_COMPARATOR);
}
代码示例来源:origin: mcekovic/tennis-crystal-ball
public static <T extends Comparable<T>> int nullsFirstCompare(T t1, T t2) {
return Objects.compare(t1, t2, NULLS_FIRST_COMPARATOR);
}
代码示例来源:origin: org.omnifaces/omniutils
@Override
public void accept(T t) {
if (count == 0) {
min = t;
max = t;
} else {
if (Objects.compare(min, t, comparator) > 0) {
min = t;
}
if (Objects.compare(t, max, comparator) > 0) {
max = t;
}
}
count++;
}
代码示例来源:origin: tec.units/indriya
@SuppressWarnings("unchecked")
@Override
public int compareTo(UnitConverter obj) {
if (this == obj) {
return 0;
}
if (obj instanceof Pair) {
Pair that = (Pair) obj;
@SuppressWarnings("rawtypes")
Comparator c = new UnitComparator<>();
return Objects.compare(left, that.left, c) + Objects.compare(right, that.right, c);
}
return -1;
}
}
代码示例来源:origin: dita-ot/dita-ot
public int compare(final Value a0, final Value a1) {
if (a0 == null || a1 == null) {
return -1;
}
return Objects.compare(a0.value, a1.value, String::compareTo);
}
});
代码示例来源:origin: org.apache.sshd/sshd-common
@Override
public boolean isSecurityEntitySupported(Class<?> entityType, String name) {
if (!isSupported()) {
return false;
}
if (KeyPairGenerator.class.isAssignableFrom(entityType)
|| KeyFactory.class.isAssignableFrom(entityType)) {
return Objects.compare(name, getName(), String.CASE_INSENSITIVE_ORDER) == 0;
} else if (Signature.class.isAssignableFrom(entityType)) {
return Objects.compare(SecurityUtils.CURVE_ED25519_SHA512, name, String.CASE_INSENSITIVE_ORDER) == 0;
} else {
return false;
}
}
代码示例来源:origin: org.apache.isis.core/isis-core-commons
/**
* Natural order compare, with nulls ordered first.
* @param x
* @param y
* @return
*/
public static <T extends Comparable<T>> int compareNullsFirst(final T x, final T y) {
return Objects.compare(x, y, Comparator.nullsFirst(Comparator.naturalOrder()));
}
代码示例来源:origin: org.apache.isis.core/isis-core-commons
/**
* Natural order compare, with nulls ordered last.
* @param x
* @param y
* @return
*/
public static <T extends Comparable<T>> int compareNullsLast(final T x, final T y) {
return Objects.compare(x, y, Comparator.nullsLast(Comparator.naturalOrder()));
}
代码示例来源:origin: org.apache.sshd/sshd-osgi
@Override
public boolean isSecurityEntitySupported(Class<?> entityType, String name) {
if (!isSupported()) {
return false;
}
if (KeyPairGenerator.class.isAssignableFrom(entityType)
|| KeyFactory.class.isAssignableFrom(entityType)) {
return Objects.compare(name, getName(), String.CASE_INSENSITIVE_ORDER) == 0;
} else if (Signature.class.isAssignableFrom(entityType)) {
return Objects.compare(SecurityUtils.CURVE_ED25519_SHA512, name, String.CASE_INSENSITIVE_ORDER) == 0;
} else {
return false;
}
}
代码示例来源:origin: org.xbib/sshd-common
@Override
public boolean isSecurityEntitySupported(Class<?> entityType, String name) {
if (!isSupported()) {
return false;
}
if (KeyPairGenerator.class.isAssignableFrom(entityType)
|| KeyFactory.class.isAssignableFrom(entityType)) {
return Objects.compare(name, getName(), String.CASE_INSENSITIVE_ORDER) == 0;
} else if (Signature.class.isAssignableFrom(entityType)) {
return Objects.compare(SecurityUtils.CURVE_ED25519_SHA512, name, String.CASE_INSENSITIVE_ORDER) == 0;
} else {
return false;
}
}
代码示例来源:origin: org.nuxeo.runtime/nuxeo-runtime-stream
public <U> List<U> sort(Collection<U> children) {
if (children == null || children.isEmpty()) {
return Collections.emptyList();
}
AvroSchemaFactory<U> factory = getFactory(children.iterator().next());
if (factory == null) {
return Collections.emptyList();
}
List<U> sortedChildren = new ArrayList<>(children);
sortedChildren.sort((o1, o2) -> Objects.compare(factory.getQualifiedName(o1), factory.getQualifiedName(o2),
String::compareTo));
return sortedChildren;
}
代码示例来源:origin: OpenNMS/opennms
@Override
public int compare(ResourceType r0, ResourceType r1) {
// Sort by resource label, allowing the resource label to be null
final Comparator<? super String> comparator = (a, b) -> a.compareTo(b);
return Objects.compare(r0.getLabel(), r1.getLabel(), Comparator.nullsLast(comparator));
}
});
代码示例来源:origin: com.powsybl/powsybl-gse-network-explorer
private Comparator<IdAndName> getIdAndNameComparator() {
boolean selected = showName.isSelected();
return (o1, o2) -> {
if (selected) {
return Objects.compare(o1.getName(), o2.getName(), String::compareTo);
} else {
return o1.getId().compareTo(o2.getId());
}
};
}
代码示例来源:origin: com.github.seancfoley/ipaddress
public int compare(Address one, Address two) {
if(one == two) {
return 0;
}
int result = compare(one.getSection(), two.getSection());
if(result == 0 && one instanceof IPv6Address) {
IPv6Address oneIPv6 = (IPv6Address) one;
IPv6Address twoIPv6 = (IPv6Address) two;
result = Objects.compare(oneIPv6.getZone(), twoIPv6.getZone(), Comparator.nullsFirst(String::compareTo));
}
return result;
}
内容来源于网络,如有侵权,请联系作者删除!