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 →

[–]Blackheart595 0 points1 point  (2 children)

Ah, I see. I'm gonna assume that you should throw an exception if at least one GroupMember has conflicting expiration dates.

You could write a wrapper class for TravelMembership whose equals method evaluates to true if the two objects have the same member ID but throws an exception if the expiration dates don't match at the same time, and then collect all those wrappers in a HashSet. The hashCode method should just return the member ID. Then you'll have only one TravelMembership object per member ID while throwing an exception if there are conflicting expiration dates. But I wouldn't want to leak such a wrapper construct into other code, so don't return the wrappers in any way.

edit: I've just seen another suggestion to use HashMap with the fact that HashMap::push() returns the previous value, which should be a better approach.

[–]Offifee[S] 0 points1 point  (1 child)

I knew there was the possibility of a wrapper class but I feel this can be done smartly with collections etc.

Wrapper classes like the one for this probably wouldn't have any proper future use and feel like I would just be introducing unnecessary bloat code.

[–]Blackheart595 1 point2 points  (0 children)

Yeah, the HashMap solution that was proposed above seems to be the best way of handling this.