@Override public ExhibitionSection getExhibitionSection(ExhibitionSection search) { if (searchExhibitionSectionsByID.containsKey(search.getId())) { return searchExhibitionSectionsByID.get(search.getId()); } if (searchExhibitionSectionsByName.containsKey(nameKey(search))) { return searchExhibitionSectionsByName.get(nameKey(search)); } return search; }
private String nameKey(ExhibitionSection exhibitionSection) { try { return exhibitionSection .getExhibitionID() .getName() .concat(":->") .concat(exhibitionSection.getSectionNumber()); } catch (Exception e) { return e.getMessage(); } }
private void buildIndexes() { // Clear All Indexes searchExhibitionSectionsByName.clear(); searchExhibitionSectionsByID.clear(); // Rebuild them... for (Iterator it = collection.iterator(); it.hasNext(); ) { ExhibitionSection exhibitionSection = (ExhibitionSection) it.next(); searchExhibitionSectionsByID.put(exhibitionSection.getId(), exhibitionSection); searchExhibitionSectionsByName.put(nameKey(exhibitionSection), exhibitionSection); } }
@Override public boolean isAddable(ExhibitionSection exhibitionSection) { if (!searchExhibitionSectionsByName.containsKey(nameKey(exhibitionSection))) return true; return (Objects.equals( searchExhibitionSectionsByName.get(nameKey(exhibitionSection)).getId(), exhibitionSection.getId())); }