Per Mike T: we may want to create an array list of type B and then sort it
using a comparator on type A which is a superclass of B. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2230 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -39,7 +39,7 @@ public class SortableArrayList<T> extends BaseArrayList<T>
|
|||||||
* any object allocation). The elements must all be mutually
|
* any object allocation). The elements must all be mutually
|
||||||
* comparable.
|
* comparable.
|
||||||
*/
|
*/
|
||||||
public void sort (Comparator<T> comp)
|
public void sort (Comparator<? super T> comp)
|
||||||
{
|
{
|
||||||
if (_size > 1) {
|
if (_size > 1) {
|
||||||
QuickSort.sort(_elements, 0, _size-1, comp);
|
QuickSort.sort(_elements, 0, _size-1, comp);
|
||||||
@@ -56,7 +56,7 @@ public class SortableArrayList<T> extends BaseArrayList<T>
|
|||||||
* @return the index at which the element was inserted.
|
* @return the index at which the element was inserted.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public int insertSorted (T value, Comparator<T> comp)
|
public int insertSorted (T value, Comparator<? super T> comp)
|
||||||
{
|
{
|
||||||
int ipos = binarySearch(value, comp);
|
int ipos = binarySearch(value, comp);
|
||||||
if (ipos < 0) {
|
if (ipos < 0) {
|
||||||
@@ -76,7 +76,7 @@ public class SortableArrayList<T> extends BaseArrayList<T>
|
|||||||
* <code>(-(<i>insertion point</i>) - 1)</code> (always a negative
|
* <code>(-(<i>insertion point</i>) - 1)</code> (always a negative
|
||||||
* value) if the object was not found in the list.
|
* value) if the object was not found in the list.
|
||||||
*/
|
*/
|
||||||
public int binarySearch (T key, Comparator<T> comp)
|
public int binarySearch (T key, Comparator<? super T> comp)
|
||||||
{
|
{
|
||||||
return ArrayUtil.binarySearch(_elements, 0, _size, key, comp);
|
return ArrayUtil.binarySearch(_elements, 0, _size, key, comp);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user