Applying a set of updates for new Java features from Hendrik Maryns in LANG-336
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@770105 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f89a50b528
commit
8b7956d27f
|
@ -33,7 +33,7 @@ import java.math.BigInteger;
|
|||
* @since 2.0
|
||||
* @version $Id$
|
||||
*/
|
||||
public final class Fraction extends Number implements Comparable {
|
||||
public final class Fraction extends Number implements Comparable<Fraction> {
|
||||
|
||||
/**
|
||||
* Required for serialization support. Lang version 2.0.
|
||||
|
@ -867,13 +867,12 @@ public final class Fraction extends Number implements Comparable {
|
|||
* with equals, because, for example, equals treats 1/2 and 2/4 as
|
||||
* different, whereas compareTo treats them as equal.
|
||||
*
|
||||
* @param object the object to compare to
|
||||
* @param other the object to compare to
|
||||
* @return -1 if this is less, 0 if equal, +1 if greater
|
||||
* @throws ClassCastException if the object is not a <code>Fraction</code>
|
||||
* @throws NullPointerException if the object is <code>null</code>
|
||||
*/
|
||||
public int compareTo(Object object) {
|
||||
Fraction other = (Fraction) object;
|
||||
public int compareTo(Fraction other) {
|
||||
if (this==other) {
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -119,7 +119,7 @@ public final class NumberRange extends Range implements Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
int compare = ((Comparable) num1).compareTo(num2);
|
||||
int compare = ((Comparable<Number>) num1).compareTo(num2);
|
||||
if (compare == 0) {
|
||||
this.min = num1;
|
||||
this.max = num1;
|
||||
|
@ -176,8 +176,8 @@ public final class NumberRange extends Range implements Serializable {
|
|||
if (number.getClass() != min.getClass()) {
|
||||
throw new IllegalArgumentException("The number must be of the same type as the range numbers");
|
||||
}
|
||||
int compareMin = ((Comparable) min).compareTo(number);
|
||||
int compareMax = ((Comparable) max).compareTo(number);
|
||||
int compareMin = ((Comparable<Number>) min).compareTo(number);
|
||||
int compareMax = ((Comparable<Number>) max).compareTo(number);
|
||||
return compareMin <= 0 && compareMax >= 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -458,8 +458,8 @@ public class StrTokenizer implements ListIterator<String>, Cloneable {
|
|||
public List<String> getTokenList() {
|
||||
checkTokenized();
|
||||
List<String> list = new ArrayList<String>(tokens.length);
|
||||
for (int i = 0; i < tokens.length; i++) {
|
||||
list.add(tokens[i]);
|
||||
for (String element : tokens) {
|
||||
list.add(element);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
|
|
@ -1264,11 +1264,6 @@ public class FractionTest extends TestCase {
|
|||
fail("expecting NullPointerException");
|
||||
} catch (NullPointerException ex) {}
|
||||
|
||||
try {
|
||||
f1.compareTo(new Object());
|
||||
fail("expecting ClassCastException");
|
||||
} catch (ClassCastException ex) {}
|
||||
|
||||
f2 = Fraction.getFraction(2, 5);
|
||||
assertTrue(f1.compareTo(f2) > 0);
|
||||
assertTrue(f2.compareTo(f2) == 0);
|
||||
|
|
Loading…
Reference in New Issue