I have one ArrayList and one TreeSet that hold the same object type.
TreeSet<StatusChangeDB> listToChange;
List<StatusChangeDB> originalList;
StatusChangeDB looks like...
public class StatusChangeDB implements Comparable<StatusChangeDB> {
private String sector;
private String superlayer;
private String loclayer;
private String locwire;
private String problem_type;
public StatusChangeDB() {
}
...
...
getters and setters
hashCode()
equals(Object)
compareTo(...)
}
When original list is generated, the Object, StatusChangeDB, has 4 of 5 of its primitives set, i.e. sector, superlayer, loclayer, locwire. The originalList is displayed in a JTable which implements AbstractTableModel.
At some point in the process, the user selects the rows from the displayed table and assigns the "problemType", which creates TreeSet listToChange.
Now I would like to remove the values selected from the JTable once the "problemType" is "set". To do this, I cannot use a straight
originaList.removeAll(listToChange)
Because the objects differ by "problemType".
I have tried this method in my TableModel
public void removeRow(TreeSet<StatusChangeDB> listToChange) {
//this.wireList.removeAll(statusChangeDBs); Does not work
//because objects are different
for (StatusChangeDB row : listToChange) {
for (StatusChangeDB statusChangeDB : originalList) {
if (statusChangeDB.getSector().equals(row.getSector())
&& statusChangeDB.getSuperlayer().equals(row.getSuperlayer())
&& statusChangeDB.getLoclayer().equals(row.getLoclayer())
&& statusChangeDB.getLocwire().equals(row.getLocwire())) {
System.out.println("####### EQUAL #######");
System.out.println(ro.getSector() + " " + ro.getSuperlayer() + " " + ro.getLoclayer() + " "
+ ro.getLocwire());
this.originalList.remove(statusChangeDB);
}
}
}
This method does the job of finding the values that equal to one another, however the line
this.originalList.remove(statusChangeDB);
produces the error
Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedOperationException at java.util.AbstractList.remove(AbstractList.java:161) at java.util.AbstractList$Itr.remove(AbstractList.java:374) at java.util.AbstractCollection.remove(AbstractCollection.java:293) at database.ui.TableModel.removeRow(TableModel.java:95)
I have read the SO forums on this, but I am not able to construct the ArrayList using Arrays.asList because the ArrayList is dymnamically added to. How can I accomplish this task of removing the Object from the ArrayList? Please no comments on using DefaultTableModel instead of AbstractTable Model. The "all knowing" leaders of the project have requested the AbstractTableModel.
The code that sets the originalList is as follows:
public void setWireSet(Dataset<StatusChangeDB> wireDF) {
setWireList(wireDF.collectAsList());
updateTable();
}
public void setWireList(List<StatusChangeDB> wireList) {
this.originalList = wireList;
}
Both lists are filled and when dumped to screen have the appropriate values assigned.
The assignment of originalList is if TableModel as
private List<StatusChangeDB> originalList;
private String[] colNames = { "Sector", "SuperLayer", "Layer", "Wire" };
public TableModel() {
this.originalList = new ArrayList<StatusChangeDB>();
}
this.originalList?java.util.ArrayList.Listdoes not support removing elements. So, you cannot use theremove.