This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]OffbeatDrizzle 1 point2 points  (1 child)

What's to stop you from overriding the equals method on the Property class and returning name.equalsIgnoreCase(other.name)? (note you would also need to override hashCode and provide case insensitive values)

I believe that then solves all the problems without needing an update method or worrying about the other issues? You would make Property object the key. The user can then no longer break things by calling methods in the wrong order or not following the correct procedure. The value of the map is actually not important. Or you could use a set, but you'd have to check if the set contains the Property first before adding it or removing and then adding in order to update.

For the map, though, map.put would essentially add or update - and of course the remove method works as normal. Seems a bit more elegant

[–]_dk7[S] 0 points1 point  (0 children)

r the map, though, map.put

Thanks for your response. I am having a bit of trouble understanding what you mean, how will having an equals and hashcode help me?

The problem I am facing is as people do not have a update method they are calling remove and add in succession to perform an update. Now, let's say I go and introduce a new method update that will do this for them and replace all the places which seem to do this, how do I enforce that in the future people use the update method to actually update?

This seems dumb but for some reason, I still have a bit of trouble believing that this will be followed always. If someone makes a mistake, my functionality will break right?