I have some data structures that stay unchanged if you try to add something that already exists in the data structure. The decision is maybe made through comparing a key or using a equals function. Only if the instance of the object is new to the structure it will be added to the structure.
I was wondering how do you name these kind of methods? updateX(), addX(), putX() are all misleading, but something like addIfXDoesntExist() is ugly.
Is there a convention or a quasi standard or anything that just sounds good and is short but at the same time comprehensive?
For logic like this, you can return a boolean, which returns true if it was a successful add, or false if it already existed. This means you can decide whether or not you care about the result or not and perform other additional logic on if statements etc
They do this within collection implementations a lot.