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
|
* @since 2.0
|
||||||
* @version $Id$
|
* @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.
|
* 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
|
* with equals, because, for example, equals treats 1/2 and 2/4 as
|
||||||
* different, whereas compareTo treats them as equal.
|
* 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
|
* @return -1 if this is less, 0 if equal, +1 if greater
|
||||||
* @throws ClassCastException if the object is not a <code>Fraction</code>
|
* @throws ClassCastException if the object is not a <code>Fraction</code>
|
||||||
* @throws NullPointerException if the object is <code>null</code>
|
* @throws NullPointerException if the object is <code>null</code>
|
||||||
*/
|
*/
|
||||||
public int compareTo(Object object) {
|
public int compareTo(Fraction other) {
|
||||||
Fraction other = (Fraction) object;
|
|
||||||
if (this==other) {
|
if (this==other) {
|
||||||
return 0;
|
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) {
|
if (compare == 0) {
|
||||||
this.min = num1;
|
this.min = num1;
|
||||||
this.max = num1;
|
this.max = num1;
|
||||||
|
@ -176,8 +176,8 @@ public final class NumberRange extends Range implements Serializable {
|
||||||
if (number.getClass() != min.getClass()) {
|
if (number.getClass() != min.getClass()) {
|
||||||
throw new IllegalArgumentException("The number must be of the same type as the range numbers");
|
throw new IllegalArgumentException("The number must be of the same type as the range numbers");
|
||||||
}
|
}
|
||||||
int compareMin = ((Comparable) min).compareTo(number);
|
int compareMin = ((Comparable<Number>) min).compareTo(number);
|
||||||
int compareMax = ((Comparable) max).compareTo(number);
|
int compareMax = ((Comparable<Number>) max).compareTo(number);
|
||||||
return compareMin <= 0 && compareMax >= 0;
|
return compareMin <= 0 && compareMax >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -458,8 +458,8 @@ public class StrTokenizer implements ListIterator<String>, Cloneable {
|
||||||
public List<String> getTokenList() {
|
public List<String> getTokenList() {
|
||||||
checkTokenized();
|
checkTokenized();
|
||||||
List<String> list = new ArrayList<String>(tokens.length);
|
List<String> list = new ArrayList<String>(tokens.length);
|
||||||
for (int i = 0; i < tokens.length; i++) {
|
for (String element : tokens) {
|
||||||
list.add(tokens[i]);
|
list.add(element);
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1264,11 +1264,6 @@ public class FractionTest extends TestCase {
|
||||||
fail("expecting NullPointerException");
|
fail("expecting NullPointerException");
|
||||||
} catch (NullPointerException ex) {}
|
} catch (NullPointerException ex) {}
|
||||||
|
|
||||||
try {
|
|
||||||
f1.compareTo(new Object());
|
|
||||||
fail("expecting ClassCastException");
|
|
||||||
} catch (ClassCastException ex) {}
|
|
||||||
|
|
||||||
f2 = Fraction.getFraction(2, 5);
|
f2 = Fraction.getFraction(2, 5);
|
||||||
assertTrue(f1.compareTo(f2) > 0);
|
assertTrue(f1.compareTo(f2) > 0);
|
||||||
assertTrue(f2.compareTo(f2) == 0);
|
assertTrue(f2.compareTo(f2) == 0);
|
||||||
|
|
Loading…
Reference in New Issue