Skip to content

Commit

Permalink
fixed files form Lang #64
Browse files Browse the repository at this point in the history
  • Loading branch information
tdurieux committed Mar 7, 2017
1 parent a7e8a02 commit 163957b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions projects/Lang/64/org/apache/commons/lang/enums/ValuedEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ public final int getValue() {
* @throws NullPointerException if other is <code>null</code>
*/
public int compareTo(Object other) {
if (other == this) {
return 0;
}
if (other.getClass() != this.getClass()) {
if (other.getClass().getName().equals(this.getClass().getName())) {
return iValue - getValueInOtherClassLoader(other);
}
throw new ClassCastException(
"Different enum class '" + ClassUtils.getShortClassName(other.getClass()) + "'");
}
return iValue - ((ValuedEnum) other).iValue;
}

Expand All @@ -189,9 +199,20 @@ public int compareTo(Object other) {
* @param other the object to determine the value for
* @return the value
*/
private int getValueInOtherClassLoader(Object other) {
try {
Method mth = other.getClass().getMethod("getValue", null);
Integer value = (Integer) mth.invoke(other, null);
return value.intValue();
} catch (NoSuchMethodException e) {
// ignore - should never happen
} catch (IllegalAccessException e) {
// ignore - should never happen
} catch (InvocationTargetException e) {
// ignore - should never happen
}
throw new IllegalStateException("This should not happen");
}

/**
* <p>Human readable description of this <code>Enum</code> item.</p>
Expand Down

0 comments on commit 163957b

Please sign in to comment.