Tab and trailing space removal

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1023897 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastian Bazley 2010-10-18 16:45:29 +00:00
parent 218ba8fd3b
commit a68c67c121
3 changed files with 114 additions and 114 deletions

View File

@ -75,8 +75,8 @@ public class ListUtils {
List<? extends E> smaller = list1;
List<? extends E> larger = list2;
if (list1.size() > list2.size()) {
smaller = list2;
larger = list1;
smaller = list2;
larger = list1;
}
HashSet<E> hashSet = new HashSet<E>(smaller);

View File

@ -34,8 +34,8 @@ import org.apache.commons.collections.Predicate;
* Comparator comparator = new Comparator() {
*
* public int compare(Object first, Object second) {
* return ((Integer) second) - ((Integer) first);
* }
* return ((Integer) second) - ((Integer) first);
* }
*
* };
* </pre>
@ -86,103 +86,103 @@ public class ComparatorPredicate<T> implements Predicate<T>, Serializable {
EQUAL, GREATER, LESS, GREATER_OR_EQUAL, LESS_OR_EQUAL,
}
// Instance variables:
// Instance variables:
/** The internal object to compare with */
private final T object;
/** The internal object to compare with */
private final T object;
/** The comparator to use for comparison */
private final Comparator<T> comparator;
/** The comparator to use for comparison */
private final Comparator<T> comparator;
/** The comparison evaluation criterion to use */
private final Criterion criterion;
/** The comparison evaluation criterion to use */
private final Criterion criterion;
/**
* Factory to create the comparator predicate
*
* @param object the object to compare to
* @param comparator the comparator to use for comparison
* @return the predicate
* @throws IllegalArgumentException if comparator is null
*/
public static <T> Predicate<T> getInstance(T object, Comparator<T> comparator) {
return getInstance(object, comparator, Criterion.EQUAL);
}
/**
* Factory to create the comparator predicate
*
* @param object the object to compare to
* @param comparator the comparator to use for comparison
* @return the predicate
* @throws IllegalArgumentException if comparator is null
*/
public static <T> Predicate<T> getInstance(T object, Comparator<T> comparator) {
return getInstance(object, comparator, Criterion.EQUAL);
}
/**
* Factory to create the comparator predicate
*
* @param object the object to compare to
* @param comparator the comparator to use for comparison
* @param criterion the criterion to use to evaluate comparison
* @return the predicate
* @throws IllegalArgumentException if comparator is null of criterion is invalid
*/
public static <T> Predicate<T> getInstance(T object, Comparator<T> comparator, Criterion criterion) {
/**
* Factory to create the comparator predicate
*
* @param object the object to compare to
* @param comparator the comparator to use for comparison
* @param criterion the criterion to use to evaluate comparison
* @return the predicate
* @throws IllegalArgumentException if comparator is null of criterion is invalid
*/
public static <T> Predicate<T> getInstance(T object, Comparator<T> comparator, Criterion criterion) {
if (comparator == null) {
throw new IllegalArgumentException("Comparator must not be null.");
}
if (criterion == null) {
throw new IllegalArgumentException("Criterion must not be null.");
}
return new ComparatorPredicate<T>(object, comparator, criterion);
}
return new ComparatorPredicate<T>(object, comparator, criterion);
}
/**
* Constructor that performs no validation.
* Use <code>getInstance</code> if you want.
*
* @param object the object to compare to
* @param comparator the comparator to use for comparison
* @param criterion the criterion to use to evaluate comparison
*/
public ComparatorPredicate(T object, Comparator<T> comparator, Criterion criterion) {
super();
this.object = object;
this.comparator = comparator;
this.criterion = criterion;
}
/**
* Constructor that performs no validation.
* Use <code>getInstance</code> if you want.
*
* @param object the object to compare to
* @param comparator the comparator to use for comparison
* @param criterion the criterion to use to evaluate comparison
*/
public ComparatorPredicate(T object, Comparator<T> comparator, Criterion criterion) {
super();
this.object = object;
this.comparator = comparator;
this.criterion = criterion;
}
/**
* Evaluates the predicate. The predicate evaluates to <code>true</code> in the following cases:
*
* <ul>
* <li><code>comparator.compare(object, input) == 0 && criterion == EQUAL</code></li>
* <li><code>comparator.compare(object, input) < 0 && criterion == LESS</code></li>
* <li><code>comparator.compare(object, input) > 0 && criterion == GREATER</code></li>
* <li><code>comparator.compare(object, input) >= 0 && criterion == GREATER_OR_EQUAL</code></li>
* <li><code>comparator.compare(object, input) <= 0 && criterion == LESS_OR_EQUAL</code></li>
* </ul>
*
* @see org.apache.commons.collections.Predicate#evaluate(java.lang.Object)
* @see java.util.Comparator#compare(java.lang.Object first, java.lang.Object second)
*
* @throws IllegalStateException if the criterion is invalid (really not possible)
*/
public boolean evaluate(T target) {
/**
* Evaluates the predicate. The predicate evaluates to <code>true</code> in the following cases:
*
* <ul>
* <li><code>comparator.compare(object, input) == 0 && criterion == EQUAL</code></li>
* <li><code>comparator.compare(object, input) < 0 && criterion == LESS</code></li>
* <li><code>comparator.compare(object, input) > 0 && criterion == GREATER</code></li>
* <li><code>comparator.compare(object, input) >= 0 && criterion == GREATER_OR_EQUAL</code></li>
* <li><code>comparator.compare(object, input) <= 0 && criterion == LESS_OR_EQUAL</code></li>
* </ul>
*
* @see org.apache.commons.collections.Predicate#evaluate(java.lang.Object)
* @see java.util.Comparator#compare(java.lang.Object first, java.lang.Object second)
*
* @throws IllegalStateException if the criterion is invalid (really not possible)
*/
public boolean evaluate(T target) {
boolean result = false;
int comparison = comparator.compare(object, target);
boolean result = false;
int comparison = comparator.compare(object, target);
switch (criterion) {
case EQUAL:
result = (comparison == 0);
break;
case GREATER:
result = (comparison > 0);
break;
case LESS:
result = (comparison < 0);
break;
case GREATER_OR_EQUAL:
result = (comparison >= 0);
break;
case LESS_OR_EQUAL:
result = (comparison <= 0);
break;
default:
throw new IllegalStateException("The current criterion '" + criterion + "' is invalid.");
}
case EQUAL:
result = (comparison == 0);
break;
case GREATER:
result = (comparison > 0);
break;
case LESS:
result = (comparison < 0);
break;
case GREATER_OR_EQUAL:
result = (comparison >= 0);
break;
case LESS_OR_EQUAL:
result = (comparison <= 0);
break;
default:
throw new IllegalStateException("The current criterion '" + criterion + "' is invalid.");
}
return result;
}
return result;
}
}

View File

@ -117,15 +117,15 @@ public class TestListUtils extends BulkTest {
* Tests intersecting two lists in different orders.
*/
public void testIntersectionOrderInsensitivity() {
List<String> one = new ArrayList<String>();
List<String> two = new ArrayList<String>();
one.add("a");
one.add("b");
two.add("a");
two.add("a");
two.add("b");
two.add("b");
assertEquals(ListUtils.intersection(one,two),ListUtils.intersection(two, one));
List<String> one = new ArrayList<String>();
List<String> two = new ArrayList<String>();
one.add("a");
one.add("b");
two.add("a");
two.add("a");
two.add("b");
two.add("b");
assertEquals(ListUtils.intersection(one,two),ListUtils.intersection(two, one));
}
public void testPredicatedList() {