List of usage examples for com.google.common.collect MapDifference entriesOnlyOnLeft
Map<K, V> entriesOnlyOnLeft();
From source file:org.oscarehr.admin.traceability.TraceabilityReportProcessor.java
@Override public String call() throws Exception { ClinicDAO dao = SpringUtils.getBean(ClinicDAO.class); Clinic clinic = dao.getClinic();/* w ww.j av a 2s. com*/ String clinicName = clinic.getClinicName(); String originDate = null; String gitSHA = null; clinicName = (clinicName == null) ? "" : clinicName; FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); PrintWriter pw = new PrintWriter(outputStream); List<FileItem> items = upload.parseRequest(request); for (FileItem diskFileItem : items) { GZIPInputStream gzip = new GZIPInputStream(diskFileItem.getInputStream()); ObjectInputStream ios = new ObjectInputStream(gzip); @SuppressWarnings("unchecked") Map<String, String> sourceMap = (Map<String, String>) ios.readObject(); originDate = sourceMap.get("origin_date"); originDate = (originDate == null) ? "n/a" : originDate; sourceMap.remove("origin_date"); gitSHA = sourceMap.get("git_sha"); gitSHA = (gitSHA == null) ? "n/a" : gitSHA; sourceMap.remove("origin_date"); sourceMap.remove("git_sha"); // build local 'trace' Map<String, String> targetMap = GenerateTraceabilityUtil.buildTraceMap(request); // find the difference between incoming and local 'trace' MapDifference<String, String> diff = Maps.difference(sourceMap, targetMap); // modified, for the same keys Map<String, MapDifference.ValueDifference<String>> differing = diff.entriesDiffering(); pw.write("---------------------------------------------------------------------------------------"); pw.write(newLine); pw.write("----------------------------TRACEABILITY REPORT----------------------------------------"); pw.write(newLine); pw.write("---------------------------------------------------------------------------------------"); pw.write(newLine); pw.write(newLine); pw.write("Started: " + new java.util.Date()); pw.write(newLine); pw.write(newLine); pw.write("Trace Generated On Date: " + originDate); pw.write(newLine); pw.write("Clinic Name: " + clinicName); pw.write(newLine); pw.write("Git SHA: " + gitSHA); pw.write(newLine); pw.write(newLine); pw.write("Changed:"); pw.write(newLine); pw.write("-----------------------------------------"); pw.write(newLine); pw.write(newLine); for (Map.Entry<String, MapDifference.ValueDifference<String>> entry : differing.entrySet()) { String key = entry.getKey(); pw.write(key); pw.write(newLine); pw.write(newLine); } //to check equality //boolean mapsEqual = diff.areEqual(); pw.write(newLine); pw.write("Removed:"); pw.write(newLine); pw.write("-----------------------------------------"); pw.write(newLine); pw.write(newLine); Map<String, String> left_ = diff.entriesOnlyOnLeft(); for (Map.Entry<String, String> entry : left_.entrySet()) { String key = entry.getKey(); pw.write(key); pw.write(newLine); } pw.write(newLine); pw.write("Added:"); pw.write(newLine); pw.write("-----------------------------------------"); pw.write(newLine); pw.write(newLine); Map<String, String> right_ = diff.entriesOnlyOnRight(); for (Map.Entry<String, String> entry : right_.entrySet()) { String key = entry.getKey(); pw.write(key); pw.write(newLine); } pw.write(newLine); pw.write("Unchanged:"); pw.write(newLine); pw.write("-----------------------------------------"); pw.write(newLine); pw.write(newLine); Map<String, String> common = diff.entriesInCommon(); for (Map.Entry<String, String> entry : common.entrySet()) { String key = entry.getKey(); pw.write(key); pw.write(newLine); } pw.write("Finished: " + new java.util.Date()); pw.write(newLine); pw.write("---------------------------------------------------------------------------------------"); pw.write(newLine); pw.write("--------------------------------END OF REPORT------------------------------------------"); pw.write(newLine); pw.write("---------------------------------------------------------------------------------------"); pw.write(newLine); pw.flush(); pw.close(); break; } return getClass().getName(); }
From source file:com.blackducksoftware.bdio.io.Specification.java
/** * Returns a modified version of this specification whose term definitions can be used to map an older version of * the specification into a newer version. *//*from ww w . j av a 2 s . c o m*/ public Map<String, TermDefinition> importDefinitions() { MapDifference<String, TermDefinition> diff = Maps.difference(asTermDefinitions(), latest().asTermDefinitions()); if (diff.areEqual()) { return asTermDefinitions(); } else { // Use the resolver from the latest version of the specification to generate term definitions ImportResolver resolver = latest().importResolver(); Map<String, TermDefinition> termDefinitions = new LinkedHashMap<>(); // Entries on the right did not exist when the current version of the specification was // released, therefore we can ignore them in our reconstructed definitions // All common entries are unchanged between both versions of the specification termDefinitions.putAll(diff.entriesInCommon()); // Entries which have the same alias but different IRIs have been "re-mapped"; typically // (but not always) we want the alias to point to the latest IRI for (Entry<String, ValueDifference<TermDefinition>> e : diff.entriesDiffering().entrySet()) { String alias = e.getKey(); termDefinitions.put(alias, resolver.changed(alias, e.getValue().leftValue(), e.getValue().rightValue())); } // Entries on the left have been removed or renamed (their alias changed). We must delegate // to the import resolver to decide what do here. for (Entry<String, TermDefinition> e : diff.entriesOnlyOnLeft().entrySet()) { String alias = e.getKey(); termDefinitions.put(alias, resolver.removed(alias, e.getValue())); } return termDefinitions; } }