List of usage examples for com.google.common.collect MapDifference entriesOnlyOnRight
Map<K, V> entriesOnlyOnRight();
From source file:components.cells.Cells.java
private static <T> Map<IPosition, T> merge(final T initialSymbol, final Map<IPosition, T> left, final Map<IPosition, T> right) { final Builder<IPosition, T> builder = new ImmutableSortedMap.Builder<IPosition, T>(Ordering.natural()); final MapDifference<IPosition, T> difference = Maps.difference(left, right); for (final Entry<IPosition, T> mutation : difference.entriesInCommon().entrySet()) if (!mutation.getValue().equals(initialSymbol)) builder.put(mutation);/*w w w .j a v a 2 s . c om*/ for (final Entry<IPosition, T> mutation : difference.entriesOnlyOnLeft().entrySet()) if (!mutation.getValue().equals(initialSymbol)) builder.put(mutation); for (final Entry<IPosition, T> mutation : difference.entriesOnlyOnRight().entrySet()) if (!mutation.getValue().equals(initialSymbol)) builder.put(mutation); for (final Entry<IPosition, ValueDifference<T>> mutation : difference.entriesDiffering().entrySet()) { final T rightValue = mutation.getValue().rightValue(); if (!rightValue.equals(initialSymbol)) builder.put(mutation.getKey(), rightValue); } return builder.build(); }
From source file:cpw.mods.fml.client.modloader.ModLoaderClientHelper.java
public static void handleFinishLoadingFor(ModLoaderModContainer mc, Minecraft game) { FMLLog.log(mc.getModId(), Level.FINE, "Handling post startup activities for ModLoader mod %s", mc.getModId());/* ww w . ja va2 s .c o m*/ BaseMod mod = (BaseMod) mc.getMod(); Map<Class<? extends Entity>, Render> renderers = Maps.newHashMap(RenderManager.field_78727_a.field_78729_o); try { FMLLog.log(mc.getModId(), Level.FINEST, "Requesting renderers from basemod %s", mc.getModId()); mod.addRenderer(renderers); FMLLog.log(mc.getModId(), Level.FINEST, "Received %d renderers from basemod %s", renderers.size(), mc.getModId()); } catch (Exception e) { FMLLog.log(mc.getModId(), Level.SEVERE, e, "A severe problem was detected with the mod %s during the addRenderer call. Continuing, but expect odd results", mc.getModId()); } MapDifference<Class<? extends Entity>, Render> difference = Maps .difference(RenderManager.field_78727_a.field_78729_o, renderers, Equivalence.identity()); for (Entry<Class<? extends Entity>, Render> e : difference.entriesOnlyOnLeft().entrySet()) { FMLLog.log(mc.getModId(), Level.WARNING, "The mod %s attempted to remove an entity renderer %s from the entity map. This will be ignored.", mc.getModId(), e.getKey().getName()); } for (Entry<Class<? extends Entity>, Render> e : difference.entriesOnlyOnRight().entrySet()) { FMLLog.log(mc.getModId(), Level.FINEST, "Registering ModLoader entity renderer %s as instance of %s", e.getKey().getName(), e.getValue().getClass().getName()); RenderingRegistry.registerEntityRenderingHandler(e.getKey(), e.getValue()); } for (Entry<Class<? extends Entity>, ValueDifference<Render>> e : difference.entriesDiffering().entrySet()) { FMLLog.log(mc.getModId(), Level.FINEST, "Registering ModLoader entity rendering override for %s as instance of %s", e.getKey().getName(), e.getValue().rightValue().getClass().getName()); RenderingRegistry.registerEntityRenderingHandler(e.getKey(), e.getValue().rightValue()); } try { mod.registerAnimation(game); } catch (Exception e) { FMLLog.log(mc.getModId(), Level.SEVERE, e, "A severe problem was detected with the mod %s during the registerAnimation call. Continuing, but expect odd results", mc.getModId()); } }
From source file:org.apache.cassandra.db.DefsTable.java
private static void mergeColumnFamilies(Map<DecoratedKey, ColumnFamily> old, Map<DecoratedKey, ColumnFamily> updated) throws ConfigurationException, IOException { // calculate the difference between old and new states (note that entriesOnlyLeft() will be always empty) MapDifference<DecoratedKey, ColumnFamily> diff = Maps.difference(old, updated); // check if any new Keyspaces with ColumnFamilies were added. for (Map.Entry<DecoratedKey, ColumnFamily> entry : diff.entriesOnlyOnRight().entrySet()) { ColumnFamily cfAttrs = entry.getValue(); if (!cfAttrs.isEmpty()) { Map<String, CFMetaData> cfDefs = KSMetaData .deserializeColumnFamilies(new Row(entry.getKey(), cfAttrs)); for (CFMetaData cfDef : cfDefs.values()) addColumnFamily(cfDef);/* w w w . j a v a 2s .co m*/ } } // deal with modified ColumnFamilies (remember that all of the keyspace nested ColumnFamilies are put to the single row) Map<DecoratedKey, MapDifference.ValueDifference<ColumnFamily>> modifiedEntries = diff.entriesDiffering(); for (DecoratedKey keyspace : modifiedEntries.keySet()) { MapDifference.ValueDifference<ColumnFamily> valueDiff = modifiedEntries.get(keyspace); ColumnFamily prevValue = valueDiff.leftValue(); // state before external modification ColumnFamily newValue = valueDiff.rightValue(); // updated state Row newRow = new Row(keyspace, newValue); if (prevValue.isEmpty()) // whole keyspace was deleted and now it's re-created { for (CFMetaData cfm : KSMetaData.deserializeColumnFamilies(newRow).values()) addColumnFamily(cfm); } else if (newValue.isEmpty()) // whole keyspace is deleted { for (CFMetaData cfm : KSMetaData.deserializeColumnFamilies(new Row(keyspace, prevValue)).values()) dropColumnFamily(cfm.ksName, cfm.cfName); } else // has modifications in the nested ColumnFamilies, need to perform nested diff to determine what was really changed { String ksName = AsciiType.instance.getString(keyspace.key); Map<String, CFMetaData> oldCfDefs = new HashMap<String, CFMetaData>(); for (CFMetaData cfm : Schema.instance.getKSMetaData(ksName).cfMetaData().values()) oldCfDefs.put(cfm.cfName, cfm); Map<String, CFMetaData> newCfDefs = KSMetaData.deserializeColumnFamilies(newRow); MapDifference<String, CFMetaData> cfDefDiff = Maps.difference(oldCfDefs, newCfDefs); for (CFMetaData cfDef : cfDefDiff.entriesOnlyOnRight().values()) addColumnFamily(cfDef); for (CFMetaData cfDef : cfDefDiff.entriesOnlyOnLeft().values()) dropColumnFamily(cfDef.ksName, cfDef.cfName); for (MapDifference.ValueDifference<CFMetaData> cfDef : cfDefDiff.entriesDiffering().values()) updateColumnFamily(cfDef.rightValue()); } } }
From source file:org.apache.cassandra.db.DefsTable.java
private static Set<String> mergeKeyspaces(Map<DecoratedKey, ColumnFamily> old, Map<DecoratedKey, ColumnFamily> updated) throws ConfigurationException, IOException { // calculate the difference between old and new states (note that entriesOnlyLeft() will be always empty) MapDifference<DecoratedKey, ColumnFamily> diff = Maps.difference(old, updated); /**/*from ww w.jav a2 s . c om*/ * At first step we check if any new keyspaces were added. */ for (Map.Entry<DecoratedKey, ColumnFamily> entry : diff.entriesOnlyOnRight().entrySet()) { ColumnFamily ksAttrs = entry.getValue(); // we don't care about nested ColumnFamilies here because those are going to be processed separately if (!ksAttrs.isEmpty()) addKeyspace(KSMetaData.fromSchema(new Row(entry.getKey(), entry.getValue()), Collections.<CFMetaData>emptyList())); } /** * At second step we check if there were any keyspaces re-created, in this context * re-created means that they were previously deleted but still exist in the low-level schema as empty keys */ Map<DecoratedKey, MapDifference.ValueDifference<ColumnFamily>> modifiedEntries = diff.entriesDiffering(); // instead of looping over all modified entries and skipping processed keys all the time // we would rather store "left to process" items and iterate over them removing already met keys List<DecoratedKey> leftToProcess = new ArrayList<DecoratedKey>(modifiedEntries.size()); for (Map.Entry<DecoratedKey, MapDifference.ValueDifference<ColumnFamily>> entry : modifiedEntries .entrySet()) { ColumnFamily prevValue = entry.getValue().leftValue(); ColumnFamily newValue = entry.getValue().rightValue(); if (prevValue.isEmpty()) { addKeyspace(KSMetaData.fromSchema(new Row(entry.getKey(), newValue), Collections.<CFMetaData>emptyList())); continue; } leftToProcess.add(entry.getKey()); } if (leftToProcess.size() == 0) return Collections.emptySet(); /** * At final step we updating modified keyspaces and saving keyspaces drop them later */ Set<String> keyspacesToDrop = new HashSet<String>(); for (DecoratedKey key : leftToProcess) { MapDifference.ValueDifference<ColumnFamily> valueDiff = modifiedEntries.get(key); ColumnFamily newState = valueDiff.rightValue(); if (newState.isEmpty()) keyspacesToDrop.add(AsciiType.instance.getString(key.key)); else updateKeyspace(KSMetaData.fromSchema(new Row(key, newState), Collections.<CFMetaData>emptyList())); } return keyspacesToDrop; }
From source file:org.eclipse.mdht.uml.common.util.ModelCompare.java
static public void compare(NamedElement element1, NamedElement element2, CompareResultVisitor compareResults) { compareResults.startElement(element1); HashMap<String, Element> umlPackage1HashMap = createElementHashMap(element1); HashMap<String, Element> umlPackage2HashMap = createElementHashMap(element2); MapDifference<String, Element> diff = Maps.difference(umlPackage1HashMap, umlPackage2HashMap, ValueEquivalence.ElementEquivalence); ArrayList<Element> leftElements = getSortedElements(diff.entriesOnlyOnLeft().values()); for (Element eee : leftElements) { compareResults.addedElement(element1, eee); if (eee instanceof Package || eee instanceof org.eclipse.uml2.uml.Class) { compare((NamedElement) eee, null, compareResults); }/*from w ww.j ava2s . com*/ } ArrayList<Element> rightElements = getSortedElements(diff.entriesOnlyOnRight().values()); for (Element eee : rightElements) { compareResults.deletedElement(element1, eee); } ArrayList<ValueDifference<Element>> differences = getSortedValueDifference( diff.entriesDiffering().values()); for (ValueDifference<Element> valueDifference : differences) { compareResults.changedElement(element1, valueDifference.leftValue(), valueDifference.rightValue()); if ((valueDifference.leftValue() instanceof Class) || (valueDifference.leftValue() instanceof Package)) { compare((NamedElement) valueDifference.leftValue(), (NamedElement) valueDifference.rightValue(), compareResults); } } compareResults.endElement(element1); }
From source file:org.apache.abdera2.activities.extra.Difference.java
private Iterable<Pair<String, Object>> _fieldsAdded(MapDifference<String, Object> difference) { return Pair.from(difference.entriesOnlyOnRight()); }
From source file:uk.ac.open.kmi.iserve.discovery.disco.Util.java
/** * Given two sets of matches find out the differences * TODO: Probably useful for others. Place somewhere else. The discovery-api module is an option but it forces to have guava as a dependency, do we want to? * * @param inputMatches//www. j a va2 s .com * @param inputMatchesAlt */ public static void compareResults(Map<URL, MatchResult> inputMatches, Map<URL, MatchResult> inputMatchesAlt) { MapDifference<URL, MatchResult> diff = Maps.difference(inputMatches, inputMatchesAlt); System.out.println("Comparing Match Results Maps"); Map<URL, MatchResult> common = diff.entriesInCommon(); System.out.println("Entries in common"); showMapDetails(common); Map<URL, MatchResult> onlyLeft = diff.entriesOnlyOnLeft(); System.out.println("Entries only in the left map"); showMapDetails(common); Map<URL, MatchResult> onlyRight = diff.entriesOnlyOnRight(); System.out.println("Entries only in the right map"); showMapDetails(common); Map<URL, ValueDifference<MatchResult>> diffValues = diff.entriesDiffering(); System.out.println("Differing values"); for (Entry<URL, ValueDifference<MatchResult>> entry : diffValues.entrySet()) { MatchResult resultLeft = entry.getValue().leftValue(); MatchResult resultRight = entry.getValue().rightValue(); System.out.println("Match " + entry.getKey().toString()); System.out.println("Left value details: "); System.out.println("Match explanation: " + resultLeft.getExplanation()); System.out.println("Right value details: "); System.out.println("Match explanation: " + resultRight.getExplanation()); } }
From source file:com.google.copybara.git.FetchResult.java
FetchResult(ImmutableMap<String, GitReference> before, ImmutableMap<String, GitReference> after) { MapDifference<String, GitReference> diff = Maps.difference(before, after); deleted = ImmutableMap.copyOf(diff.entriesOnlyOnLeft()); inserted = ImmutableMap.copyOf(diff.entriesOnlyOnRight()); updated = ImmutableMap/*from w w w . java2s. c o m*/ .copyOf(diff.entriesDiffering().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, v -> new RefUpdate(v.getValue().leftValue(), v.getValue().rightValue())))); }
From source file:additionalpipes.inventory.components.PropertyMap.java
@Override public void writeData(DataOutputStream data) throws IOException { MapDifference<Property, Property> diff = Maps.difference(prevValue, value); Map<Property, ValueDifference<Property>> changed = diff.entriesDiffering(); Map<Property, Property> added = diff.entriesOnlyOnRight(); Map<Property, Property> removed = diff.entriesOnlyOnLeft(); data.writeInt(changed.size() + added.size() + removed.size()); for (Entry<Property, ValueDifference<Property>> e : changed.entrySet()) { data.writeBoolean(false);//from w w w . ja v a2 s . c o m Property.writePacket(e.getKey(), data); Property.writePacket(e.getValue().rightValue(), data); } for (Entry<Property, Property> e : added.entrySet()) { data.writeBoolean(false); Property.writePacket(e.getKey(), data); Property.writePacket(e.getValue(), data); } for (Entry<Property, Property> e : removed.entrySet()) { data.writeBoolean(true); Property.writePacket(e.getKey(), data); } prevValue = ImmutableMap.copyOf(value); }
From source file:org.opendaylight.sxp.controller.listeners.sublisteners.MasterDatabaseListener.java
private void getChanges(DataObjectModification<MasterDatabase> c, List<MasterDatabaseBinding> removed, List<MasterDatabaseBinding> added) { Map<IpPrefix, MasterDatabaseBinding> before = c.getDataBefore() == null || c.getDataBefore().getMasterDatabaseBinding() == null ? new HashMap<>() : c.getDataBefore().getMasterDatabaseBinding().stream().filter(this::isLocalBinding) .collect(Collectors.toMap(SxpBindingFields::getIpPrefix, Function.identity())), after = c.getDataAfter() == null || c.getDataAfter().getMasterDatabaseBinding() == null ? new HashMap<>() : c.getDataAfter().getMasterDatabaseBinding().stream().filter(this::isLocalBinding) .collect(Collectors.toMap(SxpBindingFields::getIpPrefix, Function.identity())); MapDifference<IpPrefix, MasterDatabaseBinding> databaseDifference = Maps.difference(before, after); removed.addAll(databaseDifference.entriesOnlyOnLeft().values()); added.addAll(databaseDifference.entriesOnlyOnRight().values()); databaseDifference.entriesDiffering().forEach((p, d) -> { removed.add(d.leftValue());/*from w w w.j a v a2 s . c o m*/ added.add(d.rightValue()); }); }