Fix generics

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@882949 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastian Bazley 2009-11-21 18:07:15 +00:00
parent d45e05d584
commit 55559050cf
1 changed files with 13 additions and 12 deletions

View File

@ -31,7 +31,7 @@ public class Range<T> implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private final Comparator comparator; private final Comparator<T> comparator;
private final T minimum; private final T minimum;
private final T maximum; private final T maximum;
@ -45,8 +45,8 @@ public class Range<T> implements Serializable {
* @throws IllegalArgumentException if the value is <code>null</code> * @throws IllegalArgumentException if the value is <code>null</code>
* @throws ClassCastException if the value is not Comparable * @throws ClassCastException if the value is not Comparable
*/ */
public static <T extends Comparable> Range is(T element) { public static <T extends Comparable<T>> Range<T> is(T element) {
return new Range(element, element, ComparableComparator.INSTANCE); return new Range<T>(element, element, ComparableComparator.<T>getInstance());
} }
/** /**
@ -63,8 +63,8 @@ public class Range<T> implements Serializable {
* @throws IllegalArgumentException if either value is <code>null</code> * @throws IllegalArgumentException if either value is <code>null</code>
* @throws ClassCastException if either value is not Comparable * @throws ClassCastException if either value is not Comparable
*/ */
public static <T extends Comparable> Range between(T element1, T element2) { public static <T extends Comparable<T>> Range<T> between(T element1, T element2) {
return new Range( element1, element2, ComparableComparator.INSTANCE); return new Range<T>( element1, element2, ComparableComparator.<T>getInstance());
} }
/** /**
@ -77,8 +77,8 @@ public class Range<T> implements Serializable {
* @param c comparator to be used * @param c comparator to be used
* @throws IllegalArgumentException if the value is <code>null</code> * @throws IllegalArgumentException if the value is <code>null</code>
*/ */
public static <T> Range is(T element, Comparator c) { public static <T> Range<T> is(T element, Comparator<T> c) {
return new Range(element, element, c); return new Range<T>(element, element, c);
} }
/** /**
@ -95,11 +95,11 @@ public class Range<T> implements Serializable {
* @param c comparator to be used * @param c comparator to be used
* @throws IllegalArgumentException if either value is <code>null</code> * @throws IllegalArgumentException if either value is <code>null</code>
*/ */
public static <T> Range between(T element1, T element2, Comparator c) { public static <T> Range<T> between(T element1, T element2, Comparator<T> c) {
return new Range(element1, element2, c); return new Range<T>(element1, element2, c);
} }
private Range(T element1, T element2, Comparator c) { private Range(T element1, T element2, Comparator<T> c) {
if(element1 == null || element2 == null) { if(element1 == null || element2 == null) {
throw new IllegalArgumentException("Elements in a range must not be null: element1=" + throw new IllegalArgumentException("Elements in a range must not be null: element1=" +
element1 + ", element2=" + element2); element1 + ", element2=" + element2);
@ -145,7 +145,7 @@ public class Range<T> implements Serializable {
* *
* @return the comparator being used * @return the comparator being used
*/ */
public Comparator getComparator() { public Comparator<T> getComparator() {
return this.comparator; return this.comparator;
} }
@ -287,7 +287,8 @@ public class Range<T> implements Serializable {
} else if (obj == null || obj.getClass() != getClass()) { } else if (obj == null || obj.getClass() != getClass()) {
return false; return false;
} else { } else {
Range range = (Range) obj; @SuppressWarnings("unchecked") // OK because we checked the class above
Range<T> range = (Range<T>) obj;
return getMinimum().equals(range.getMinimum()) && return getMinimum().equals(range.getMinimum()) &&
getMaximum().equals(range.getMaximum()); getMaximum().equals(range.getMaximum());
} }