From b92907c109a0824529d165abcc514d3c62a5633f Mon Sep 17 00:00:00 2001 From: Niall Pemberton Date: Fri, 7 Jan 2011 21:24:12 +0000 Subject: [PATCH] =?UTF-8?q?LANG-667=20Simplify=20compare()=20method=20-=20?= =?UTF-8?q?thanks=20to=20Julien=20Aym=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1056520 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/commons/lang3/ObjectUtils.java | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/ObjectUtils.java b/src/main/java/org/apache/commons/lang3/ObjectUtils.java index 2d53ab0dc..a0c132954 100644 --- a/src/main/java/org/apache/commons/lang3/ObjectUtils.java +++ b/src/main/java/org/apache/commons/lang3/ObjectUtils.java @@ -348,17 +348,14 @@ public class ObjectUtils { * @see java.util.Comparator#compare(Object, Object) */ public static > int compare(T c1, T c2, boolean nullGreater) { - int result = 0; - if ((c1 == null) || (c2 == null)) { - if (nullGreater) { - result = (c1 == null ? 1 : 0) - (c2 == null ? 1 : 0); - } else { - result = (c1 == null ? -1 : 0) - (c2 == null ? -1 : 0); - } - } else { - result = c1.compareTo(c2); + if (c1 == c2) { + return 0; + } else if (c1 == null) { + return (nullGreater ? 1 : -1); + } else if (c2 == null) { + return (nullGreater ? -1 : 1); } - return result; + return c1.compareTo(c2); } /**