I need to find a object in java based in the property of its many subojects.
What I currently have is ugly as hell and I'm sure there's a more efficient way to do so.
Probably with a library like hamcrest, or maybe directly with Java (my knowledge in Java is not the best).
This is what I have so far:
private HotelResult findHotelResult(List<HotelResult> hotelResultsList, HotelSelection hotelSelection) {
for (HotelResult hotelResult : hotelResultsList)
for (RoomOption roomOption : hotelResult.getRoomOptions())
for (RoomTypeIds roomTypeIds : roomOption.getRoomTypeIds())
for (RoomRateIds roomRateIds : roomTypeIds.getRoomRateIds())
if ( roomRateIds.getId().equals(hotelSelection.getResultId()) )
return hotelResult;
(...)
}
Thank you in advance.