I need circular list of objects. And each one should know which is previous or next. I did this:
class Bus {
private Bus previous;
private Bus next;
public Bus() {
//anything
}
public void setPrevious(Bus bus) {
this.previous = bus;
}
public void setNext(Bus bus) {
this.next = bus;
}
private void someMethod() {
// if (previous.xxx() && next.xxx()) {
// do something
// }
}
}
And I created an array of Bus. After I add all buses into it, I set next and previous of each element. And I feel it's ugly:D. May you suggest me better way?