So I have to do as a homework in my class, to implement my own version of a Deque supported on an array, which can be accessed by both the tail or the head. My teacher provided us a JUnit test class to check if all our methods work. Two of those are clone() and equals(), I need this last one for the test class to check if two cloned ArrayDeque are the same. I just need help with this because it won't work with the next code:
@Override
public boolean equals(Object obj)
{
for (Object elem : items)
{
E x = (E) elem;
if (!x.equals((E)obj))
{
return false;
}
}
return true;
}
It would really help me if someone could give me a hand with this...
Thank you very much
EDIT: items
is an attribute with the array of elements of the deque
EDIT2:
Is this okay then?
public boolean equals(Object obj)
{
TSBDeQueue object = (TSBDeQueue) obj;
for (int i = 0; i < items.length; i++)
{
if (!object.items[i].equals(this.items[i]))
{
return false;
}
}
return true;
}