Hi, I am trying to compare two objects, but it is not working correctly. Please help.

/**
 * Compares theObject with <CODE>this</CODE> object for 
 * equivalence. Do not concern yourself with runtime
 * efficiency.
 * @param theObject to be compared with this object
 * @return true if theObject is equivalent to this
 * object.
 */
@Override public  
boolean equals( Object theObject ){
	if (theObject == null) return false;
	if(!(theObject instanceof BoundedBag)) return false;
	if (this == theObject) return true;
	
	BoundedBag obj = (BoundedBag) theObject;

	if( this.size() != obj.size() ) return false;
	
	// Fill in the remainder of the code.
	
	BoundedBag extra = (BoundedBag)thisObject;
	if(thisObject.equals (theObject))
		return true;
	else
		return false;		
}

Help us out a little. What do you expect to see, and what are you seeing instead?

Stating your problem clearly won't just help me and others to solve it, it might actually lead you to a solution.

I need to implement "equals" then throughly test it using JUnit. Two BoundedBags are equivalent if their elements are the same regardless of order. For example, true is returned from each of the following

{1,2,3}.equals ({3,1,2} )
{1,1,1,3}.equals( {1,3,1,1} )
but {1,1,1,3}.equals( {1,1,3} ) returns false.

I am getting an error from lines 2 and below. It is saying that thisObject can not be resolved to a variable.

This article has been dead for over six months. Start a new discussion instead.