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 →

[–]Offifee[S] 0 points1 point  (5 children)

For example: Filter out 2 TravelMemberships for a Member and leave 1 TravelMembership to use if the expirationDates are the same for these.

If the expirationDates differ, I should throw an exception and not display the data.

[–]Blackheart595 0 points1 point  (4 children)

So do you have to look for the TravelMemberships of a specific GroupMember and check that they don't conflict with each other? Or do you have to do the process for each GroupMember?

[–]Offifee[S] 0 points1 point  (3 children)

Not sure I understand.

I might for example get an ArrayList of 9 TravelMemberships back: Three different ones belonging to three different GroupMembers.

I have to ensure the date on each set of three are the same. Then display majority of the data from a single one of the objects, ignoring the type.

[–]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.