Deprecated DSet.toArray. Pretending like arrays are parameterized collections
is a bad idea and will lead to pain. Nixed the one place where toArray was used (which was a serous pig's breakfast itself). git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6402 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -25,8 +25,11 @@ import java.awt.BorderLayout;
|
|||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.util.ArrayList;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
@@ -35,6 +38,7 @@ import javax.swing.JTable;
|
|||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.collect.Iterators;
|
import com.google.common.collect.Iterators;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
import com.samskivert.util.ComparableArrayList;
|
import com.samskivert.util.ComparableArrayList;
|
||||||
|
|
||||||
@@ -219,7 +223,7 @@ public class DSetEditor<E extends DSet.Entry> extends JPanel
|
|||||||
_accessor.updateEntry(_setName, (DSet.Entry)ce.getArgument());
|
_accessor.updateEntry(_setName, (DSet.Entry)ce.getArgument());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setData (ComparableArrayList<Comparable<Object>> keys, Object[] data)
|
public void setData (ComparableArrayList<Comparable<Object>> keys, Collection<?> data)
|
||||||
{
|
{
|
||||||
_keys = keys;
|
_keys = keys;
|
||||||
_table.setData(data);
|
_table.setData(data);
|
||||||
@@ -296,28 +300,27 @@ public class DSetEditor<E extends DSet.Entry> extends JPanel
|
|||||||
|
|
||||||
protected void refreshData ()
|
protected void refreshData ()
|
||||||
{
|
{
|
||||||
|
// add our entries to a tree map so that we get them sorted by key (optionally applying
|
||||||
|
// our filter in the process)
|
||||||
|
TreeMap<Comparable<?>,F> data = Maps.newTreeMap();
|
||||||
|
Iterator<F> iter = (_entryFilter == null) ? iterator() :
|
||||||
|
Iterators.filter(iterator(), _entryFilter);
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
F entry = iter.next();
|
||||||
|
data.put(entry.getKey(), entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
// now extract that data into a sorted key list and sorted value list
|
||||||
ComparableArrayList<Comparable<Object>> keys =
|
ComparableArrayList<Comparable<Object>> keys =
|
||||||
new ComparableArrayList<Comparable<Object>>();
|
new ComparableArrayList<Comparable<Object>>();
|
||||||
E[] entries;
|
List<F> values = Lists.newArrayList();
|
||||||
|
for (Map.Entry<Comparable<?>,F> entry : data.entrySet()) {
|
||||||
if (_entryFilter == null) {
|
@SuppressWarnings("unchecked") Comparable<Object> key =
|
||||||
entries = createArray();
|
(Comparable<Object>)entry.getKey();
|
||||||
|
keys.add(key);
|
||||||
} else {
|
values.add(entry.getValue());
|
||||||
// Do some shuffling to get out a filtered array.
|
|
||||||
Iterator<F> itr = Iterators.filter(iterator(), _entryFilter);
|
|
||||||
ArrayList<F> list = Lists.newArrayList();
|
|
||||||
Iterators.addAll(list, itr);
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked") F[] tmp = (F[])new DSet.Entry[list.size()];
|
|
||||||
entries = tmp;
|
|
||||||
list.toArray(entries);
|
|
||||||
}
|
}
|
||||||
|
setData(keys, values);
|
||||||
for (E entry : entries) {
|
|
||||||
keys.insertSorted(getKey(entry));
|
|
||||||
}
|
|
||||||
setData(keys, entries); // this works because DSet itself is sorted
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited from interface SetListener
|
// documentation inherited from interface SetListener
|
||||||
@@ -351,14 +354,6 @@ public class DSetEditor<E extends DSet.Entry> extends JPanel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public E[] createArray ()
|
|
||||||
{
|
|
||||||
@SuppressWarnings("unchecked") F[] tmp = (F[])new DSet.Entry[_set.size()];
|
|
||||||
F[] entries = tmp;
|
|
||||||
_set.toArray(entries);
|
|
||||||
return entries;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Iterator<F> iterator ()
|
public Iterator<F> iterator ()
|
||||||
{
|
{
|
||||||
return _set.iterator();
|
return _set.iterator();
|
||||||
|
|||||||
@@ -243,22 +243,6 @@ public class DSet<E extends DSet.Entry>
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Copies the elements of this distributed set into the supplied array. If the array is not
|
|
||||||
* large enough to hold all of the elements, as many as fit into the array will be copied. If
|
|
||||||
* the <code>array</code> argument is null, an object array of sufficient size to contain all
|
|
||||||
* of the elements of this set will be created and returned.
|
|
||||||
*/
|
|
||||||
public E[] toArray (E[] array)
|
|
||||||
{
|
|
||||||
if (array == null) {
|
|
||||||
@SuppressWarnings("unchecked") E[] copy = (E[])new Entry[size()];
|
|
||||||
array = copy;
|
|
||||||
}
|
|
||||||
System.arraycopy(_entries, 0, array, 0, array.length);
|
|
||||||
return array;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an <b>immutable</b> view of this distributed set as a Java set.
|
* Creates an <b>immutable</b> view of this distributed set as a Java set.
|
||||||
*/
|
*/
|
||||||
@@ -288,7 +272,28 @@ public class DSet<E extends DSet.Entry>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated use {@link #toArray(Entry[])}.
|
* Copies the elements of this distributed set into the supplied array. If the array is not
|
||||||
|
* large enough to hold all of the elements, as many as fit into the array will be copied. If
|
||||||
|
* the <code>array</code> argument is null, an object array of sufficient size to contain all
|
||||||
|
* of the elements of this set will be created and returned.
|
||||||
|
*
|
||||||
|
* @deprecated use {@link #clone} or add this to an {@link ArrayList}. Arrays are an untypesafe
|
||||||
|
* quagmire.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public E[] toArray (E[] array)
|
||||||
|
{
|
||||||
|
if (array == null) {
|
||||||
|
@SuppressWarnings("unchecked") E[] copy = (E[])new Entry[size()];
|
||||||
|
array = copy;
|
||||||
|
}
|
||||||
|
System.arraycopy(_entries, 0, array, 0, array.length);
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated use {@link #clone} or add this to an {@link ArrayList}. Arrays are an untypesafe
|
||||||
|
* quagmire.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public Object[] toArray (Object[] array)
|
public Object[] toArray (Object[] array)
|
||||||
|
|||||||
Reference in New Issue
Block a user