/** * Finds common instruments for all missions in compare list. * * @return the set of common instruments names */ public static Set<String> findCommonInstruments() { // calculate common instruments Set<String> commonInstruments = new HashSet<String>(); if (ITEMS.size() > 1) { // add first instruments of first item to list Iterator<CompareItem> i = ITEMS.iterator(); for (EntityInfo instrument : i.next().getInstruments()) { commonInstruments.add(instrument.getName()); } // check data with others while (i.hasNext()) { CompareItem next = i.next(); for (Iterator<String> j = commonInstruments.iterator(); j.hasNext(); ) { String commonInstrument = j.next(); // find instrument in next item boolean present = true; for (EntityInfo entityInfo : next.getInstruments()) { if (!entityInfo.getName().equalsIgnoreCase(commonInstrument)) { present = false; break; } } // remove instrument if it is not present in next if (!present) { j.remove(); } } } } return commonInstruments; }
/** * Check if mission with give id exists in compare list. * * @param id the id of mission to check * @return true if mission exists, false otherwise */ public static boolean exists(long id) { for (CompareItem item : ITEMS) { if (item.getMission().getId() == id) { return true; } } return false; }