Hello everyone,
Let me describe my program a bit.
There are 5 classes which describe Person, Tool, Building, Room and Organisation. They all have a String field so they are all similar. So I made an Abstract class which includes the getName method (which returns the name of the class)
The problem starts in this section. I have a class which creates an ArrayList for each and every class like this:
public class Lists implements Comparable<AllObjects> { private ArrayList<Person> personList; private ArrayList<Device> deviceList; private ArrayList<Building> buildingList; private ArrayList<Room> roomList; private ArrayList<Organisation> orgList; public Lists () { this.personList = new ArrayList<Person>(); this.deviceList = new ArrayList<Device>(); this.buildingList = new ArrayList<Building>(); this.roomList = new ArrayList<Room>(); this.orgList = new ArrayList<Organisation>(); }
I needed to implement comparable, because I have to sort these ArrayLists according to their Objects' names.
But it seems that I can't write this comparison in Lists class. So I tried writing this comparable method in the ABSTRACT class of all my objects.
But I just can't get it working. Can someone please give me a hint ?
Here is the Person class:
public class Person extends AllObjects { private String name; public Person (String s) { this.name = s; } public String getName() { return this.name; } }
And the abstract class of all 5 Classes;
public abstract class AllObjects implements Comparable<AllObjects>{ private String name; public String getName() { return this.name; } public int CompareTo(Object tmp1) { tmp1 = (AllObjects) tmp1; int result = this.getName().compareTo(((AllObjects) tmp1).getName()); return result; } }