BeanItemContainer equality

I am populating my BeanItemContainer with some initial Items, when created. During user operation I am adding or removing Items into/from my BeanItemContainer. At the end of user operation I have to check if my BeanItemContainer has changed from its initial Items.

Is there any support from the API I can use here!

Thanks in advance.

Not directly, but it should be easy enough.

The easiest way might be to listen to changes if it is ok to react to changes even if they are later reverted - see the interface
ItemSetChangeNotifier
which is implemented by most container.

Otherwise, if it is enough to check whether the set of instances has changed (rather than their contents), you could try something like

Collection oldItemIds = container.getItemIds();
// perform modifications
if (!(new ArrayList(oldItemIds).equals(new ArrayList(container.getItemIds()))) { ... }

If you don’t care about order, convert the collections into HashSets instead of ArrayLists. For some containers, this might even work without wrapping the item id collections, but you should not rely on that unless the container or the javadoc specifies the return type.

If you do care about the contents of the items and you are modifying the bean instances, it can get tricky as the container does not copy the items. Then you might need to implement deep cloning and equality check methods yourself or find some other approach for keeping track of changes if some modifications might be made bypassing the BeanItem interface.

EDIT: added javadoc link.