List of usage examples for com.google.common.collect Maps difference
public static <K, V> SortedMapDifference<K, V> difference(SortedMap<K, ? extends V> left, Map<? extends K, ? extends V> right)
From source file:org.jfrog.hudson.util.ExtractorUtils.java
private static void addEnvVars(Map<String, String> env, Run<?, ?> build, ArtifactoryClientConfiguration configuration, IncludesExcludes envVarsPatterns, TaskListener listener) { IncludeExcludePatterns patterns = new IncludeExcludePatterns( Util.replaceMacro(envVarsPatterns.getIncludePatterns(), env), Util.replaceMacro(envVarsPatterns.getExcludePatterns(), env)); // Add only the jenkins specific environment variables MapDifference<String, String> envDifference = Maps.difference(env, System.getenv()); Map<String, String> filteredEnvDifference = envDifference.entriesOnlyOnLeft(); configuration.info.addBuildVariables(filteredEnvDifference, patterns); // Add Jenkins build variables EnvVars buildVariables = getEnvVars(build, listener); MapDifference<String, String> buildVarDifference = Maps.difference(buildVariables, System.getenv()); Map<String, String> filteredBuildVarDifferences = buildVarDifference.entriesOnlyOnLeft(); configuration.info.addBuildVariables(filteredBuildVarDifferences, patterns); // Write all the deploy (matrix params) properties. configuration.fillFromProperties(buildVariables, patterns); for (Map.Entry<String, String> entry : buildVariables.entrySet()) { if (entry.getKey().startsWith(ClientProperties.PROP_DEPLOY_PARAM_PROP_PREFIX)) { configuration.publisher.addMatrixParam(entry.getKey(), entry.getValue()); }//from w w w . j a v a2s . c o m } MultiConfigurationUtils.addMatrixCombination(build, configuration); }
From source file:org.apache.cassandra.schema.LegacySchemaTables.java
private static void mergeFunctions(Map<DecoratedKey, ColumnFamily> before, Map<DecoratedKey, ColumnFamily> after) { List<UDFunction> created = new ArrayList<>(); List<UDFunction> altered = new ArrayList<>(); List<UDFunction> dropped = new ArrayList<>(); MapDifference<DecoratedKey, ColumnFamily> diff = Maps.difference(before, after); // New keyspace with functions for (Map.Entry<DecoratedKey, ColumnFamily> entry : diff.entriesOnlyOnRight().entrySet()) if (entry.getValue().hasColumns()) created.addAll(//from w ww. j a v a2 s. c o m createFunctionsFromFunctionsPartition(new Row(entry.getKey(), entry.getValue())).values()); for (Map.Entry<DecoratedKey, MapDifference.ValueDifference<ColumnFamily>> entry : diff.entriesDiffering() .entrySet()) { ColumnFamily pre = entry.getValue().leftValue(); ColumnFamily post = entry.getValue().rightValue(); if (pre.hasColumns() && post.hasColumns()) { MapDifference<ByteBuffer, UDFunction> delta = Maps.difference( createFunctionsFromFunctionsPartition(new Row(entry.getKey(), pre)), createFunctionsFromFunctionsPartition(new Row(entry.getKey(), post))); dropped.addAll(delta.entriesOnlyOnLeft().values()); created.addAll(delta.entriesOnlyOnRight().values()); Iterables.addAll(altered, Iterables.transform(delta.entriesDiffering().values(), new Function<MapDifference.ValueDifference<UDFunction>, UDFunction>() { public UDFunction apply(MapDifference.ValueDifference<UDFunction> pair) { return pair.rightValue(); } })); } else if (pre.hasColumns()) { dropped.addAll(createFunctionsFromFunctionsPartition(new Row(entry.getKey(), pre)).values()); } else if (post.hasColumns()) { created.addAll(createFunctionsFromFunctionsPartition(new Row(entry.getKey(), post)).values()); } } for (UDFunction udf : created) Schema.instance.addFunction(udf); for (UDFunction udf : altered) Schema.instance.updateFunction(udf); for (UDFunction udf : dropped) Schema.instance.dropFunction(udf); }
From source file:org.apache.abdera2.activities.extra.Extra.java
/** * Two ASObject's are considered equivalent in identity if * they share the same objectType and id property * values. Note: This implementation does not yet take * the downstreamDuplicates and upstreamDuplicates properties * into account when determining equivalence. *///from w ww . j a va 2 s . c o m public static <X extends ASObject> Equivalence<X> identity() { return new Equivalence<X>() { protected boolean doEquivalent(X a, X b) { Selector<Map.Entry<String, Object>> filter = ASBase.withFields("id", "alias", "objectType", "displayName"); Map<String, Object> map1 = Maps.transformEntries(a.toMap(filter), lower_val); Map<String, Object> map2 = Maps.transformEntries(b.toMap(filter), lower_val); MapDifference<String, Object> diff = Maps.difference(map1, map2); return ((diff.entriesInCommon().containsKey("alias") || diff.entriesInCommon().containsKey("id") || diff.entriesInCommon().containsKey("displayName")) && !diff.entriesDiffering().containsKey("objectType") && !diff.entriesDiffering().containsKey("id") && !diff.entriesOnlyOnLeft().containsKey("id") && !diff.entriesOnlyOnRight().containsKey("id")); } protected int doHash(ASObject t) { return MoreFunctions.genHashCode(1, t.getId(), t.getProperty("alias"), t.getObjectType()); } }; }
From source file:org.apache.cassandra.schema.LegacySchemaTables.java
private static void mergeAggregates(Map<DecoratedKey, ColumnFamily> before, Map<DecoratedKey, ColumnFamily> after) { List<UDAggregate> created = new ArrayList<>(); List<UDAggregate> altered = new ArrayList<>(); List<UDAggregate> dropped = new ArrayList<>(); MapDifference<DecoratedKey, ColumnFamily> diff = Maps.difference(before, after); // New keyspace with functions for (Map.Entry<DecoratedKey, ColumnFamily> entry : diff.entriesOnlyOnRight().entrySet()) if (entry.getValue().hasColumns()) created.addAll(createAggregatesFromAggregatesPartition(new Row(entry.getKey(), entry.getValue())) .values());//w w w. j a v a2s . c o m for (Map.Entry<DecoratedKey, MapDifference.ValueDifference<ColumnFamily>> entry : diff.entriesDiffering() .entrySet()) { ColumnFamily pre = entry.getValue().leftValue(); ColumnFamily post = entry.getValue().rightValue(); if (pre.hasColumns() && post.hasColumns()) { MapDifference<ByteBuffer, UDAggregate> delta = Maps.difference( createAggregatesFromAggregatesPartition(new Row(entry.getKey(), pre)), createAggregatesFromAggregatesPartition(new Row(entry.getKey(), post))); dropped.addAll(delta.entriesOnlyOnLeft().values()); created.addAll(delta.entriesOnlyOnRight().values()); Iterables.addAll(altered, Iterables.transform(delta.entriesDiffering().values(), new Function<MapDifference.ValueDifference<UDAggregate>, UDAggregate>() { public UDAggregate apply(MapDifference.ValueDifference<UDAggregate> pair) { return pair.rightValue(); } })); } else if (pre.hasColumns()) { dropped.addAll(createAggregatesFromAggregatesPartition(new Row(entry.getKey(), pre)).values()); } else if (post.hasColumns()) { created.addAll(createAggregatesFromAggregatesPartition(new Row(entry.getKey(), post)).values()); } } for (UDAggregate udf : created) Schema.instance.addAggregate(udf); for (UDAggregate udf : altered) Schema.instance.updateAggregate(udf); for (UDAggregate udf : dropped) Schema.instance.dropAggregate(udf); }
From source file:org.apache.cassandra.schema.SchemaKeyspace.java
public static Mutation.SimpleBuilder makeUpdateViewMutation(KeyspaceMetadata keyspace, ViewDefinition oldView, ViewDefinition newView, long timestamp) { Mutation.SimpleBuilder builder = makeCreateKeyspaceMutation(keyspace.name, keyspace.params, timestamp); addViewToSchemaMutation(newView, false, builder); MapDifference<ByteBuffer, ColumnDefinition> columnDiff = Maps .difference(oldView.metadata.getColumnMetadata(), newView.metadata.getColumnMetadata()); // columns that are no longer needed for (ColumnDefinition column : columnDiff.entriesOnlyOnLeft().values()) dropColumnFromSchemaMutation(oldView.metadata, column, builder); // newly added columns for (ColumnDefinition column : columnDiff.entriesOnlyOnRight().values()) addColumnToSchemaMutation(newView.metadata, column, builder); // old columns with updated attributes for (ByteBuffer name : columnDiff.entriesDiffering().keySet()) addColumnToSchemaMutation(newView.metadata, newView.metadata.getColumnDefinition(name), builder); // dropped columns MapDifference<ByteBuffer, CFMetaData.DroppedColumn> droppedColumnDiff = Maps .difference(oldView.metadata.getDroppedColumns(), oldView.metadata.getDroppedColumns()); // newly dropped columns for (CFMetaData.DroppedColumn column : droppedColumnDiff.entriesOnlyOnRight().values()) addDroppedColumnToSchemaMutation(oldView.metadata, column, builder); // columns added then dropped again for (ByteBuffer name : droppedColumnDiff.entriesDiffering().keySet()) addDroppedColumnToSchemaMutation(newView.metadata, newView.metadata.getDroppedColumns().get(name), builder);/* ww w. j a v a 2 s. co m*/ return builder; }
From source file:org.apache.ambari.server.state.ConfigHelper.java
/** * A helper method to create a new {@link Config} for a given configuration * type and updates to the current values, if any. This method will perform the following tasks: * <ul>/*from w ww . java 2s.c o m*/ * <li>Marge the specified updates with the properties of the current version of the * configuration</li> * <li>Create a {@link Config} in the cluster for the specified type. This * will have the proper versions and tags set automatically.</li> * <li>Set the cluster's {@link DesiredConfig} to the new configuration</li> * <li>Create an entry in the configuration history with a note and username.</li> * <ul> * * @param cluster * @param controller * @param configType * @param updates * @param authenticatedUserName * @param serviceVersionNote * @throws AmbariException */ public void updateConfigType(Cluster cluster, AmbariManagementController controller, String configType, Map<String, String> updates, String authenticatedUserName, String serviceVersionNote) throws AmbariException { if ((configType != null) && (updates != null) && !updates.isEmpty()) { Config oldConfig = cluster.getDesiredConfigByType(configType); Map<String, String> oldConfigProperties; Map<String, String> properties = new HashMap<String, String>(); if (oldConfig == null) { oldConfigProperties = null; } else { oldConfigProperties = oldConfig.getProperties(); if (oldConfigProperties != null) { properties.putAll(oldConfig.getProperties()); } } properties.putAll(updates); if ((oldConfigProperties == null) || !Maps.difference(oldConfigProperties, properties).areEqual()) { createConfigType(cluster, controller, configType, properties, authenticatedUserName, serviceVersionNote); } } }
From source file:edu.mit.streamjit.impl.compiler2.Compiler2.java
/** * Removes an Actor from this compiler's data structures. The Actor should * already have been unlinked from the graph (no incoming edges); this takes * care of removing it from the actors set, its actor group (possibly * removing the group if it's now empty), and the schedule. * @param a the actor to remove/*w w w .j a v a 2 s . c o m*/ */ private void removeActor(Actor a) { assert actors.contains(a) : a; actors.remove(a); ActorGroup g = a.group(); g.remove(a); if (g.actors().isEmpty()) { groups = ImmutableSortedSet.copyOf(Sets.difference(groups, ImmutableSet.of(g))); externalSchedule = ImmutableMap .copyOf(Maps.difference(externalSchedule, ImmutableMap.of(g, 0)).entriesOnlyOnLeft()); initSchedule = ImmutableMap .copyOf(Maps.difference(initSchedule, ImmutableMap.of(g, 0)).entriesOnlyOnLeft()); } }
From source file:org.apache.cassandra.schema.LegacySchemaTables.java
public static Mutation makeUpdateTableMutation(KSMetaData keyspace, CFMetaData oldTable, CFMetaData newTable, long timestamp, boolean fromThrift) { Mutation mutation = makeCreateKeyspaceMutation(keyspace, timestamp, false); addTableToSchemaMutation(newTable, timestamp, false, mutation); MapDifference<ByteBuffer, ColumnDefinition> columnDiff = Maps.difference(oldTable.getColumnMetadata(), newTable.getColumnMetadata()); // columns that are no longer needed for (ColumnDefinition column : columnDiff.entriesOnlyOnLeft().values()) { // Thrift only knows about the REGULAR ColumnDefinition type, so don't consider other type // are being deleted just because they are not here. if (fromThrift && column.kind != ColumnDefinition.Kind.REGULAR) continue; dropColumnFromSchemaMutation(oldTable, column, timestamp, mutation); }/* w ww . j a va 2s . co m*/ // newly added columns for (ColumnDefinition column : columnDiff.entriesOnlyOnRight().values()) addColumnToSchemaMutation(newTable, column, timestamp, mutation); // old columns with updated attributes for (ByteBuffer name : columnDiff.entriesDiffering().keySet()) addColumnToSchemaMutation(newTable, newTable.getColumnDefinition(name), timestamp, mutation); MapDifference<String, TriggerDefinition> triggerDiff = Maps.difference(oldTable.getTriggers(), newTable.getTriggers()); // dropped triggers for (TriggerDefinition trigger : triggerDiff.entriesOnlyOnLeft().values()) dropTriggerFromSchemaMutation(oldTable, trigger, timestamp, mutation); // newly created triggers for (TriggerDefinition trigger : triggerDiff.entriesOnlyOnRight().values()) addTriggerToSchemaMutation(newTable, trigger, timestamp, mutation); return mutation; }
From source file:org.apache.cassandra.schema.SchemaKeyspace.java
private static void updateKeyspace(String keyspaceName, KeyspaceMetadata keyspaceBefore, KeyspaceMetadata keyspaceAfter) { // calculate the deltas MapDifference<String, CFMetaData> tablesDiff = keyspaceBefore.tables.diff(keyspaceAfter.tables); MapDifference<String, ViewDefinition> viewsDiff = keyspaceBefore.views.diff(keyspaceAfter.views); MapDifference<ByteBuffer, UserType> typesDiff = keyspaceBefore.types.diff(keyspaceAfter.types); Map<Pair<FunctionName, List<String>>, UDFunction> udfsBefore = new HashMap<>(); keyspaceBefore.functions.udfs()/* w w w . ja v a2 s .c o m*/ .forEach(f -> udfsBefore.put(Pair.create(f.name(), functionArgumentsList(f)), f)); Map<Pair<FunctionName, List<String>>, UDFunction> udfsAfter = new HashMap<>(); keyspaceAfter.functions.udfs() .forEach(f -> udfsAfter.put(Pair.create(f.name(), functionArgumentsList(f)), f)); MapDifference<Pair<FunctionName, List<String>>, UDFunction> udfsDiff = Maps.difference(udfsBefore, udfsAfter); Map<Pair<FunctionName, List<String>>, UDAggregate> udasBefore = new HashMap<>(); keyspaceBefore.functions.udas() .forEach(f -> udasBefore.put(Pair.create(f.name(), functionArgumentsList(f)), f)); Map<Pair<FunctionName, List<String>>, UDAggregate> udasAfter = new HashMap<>(); keyspaceAfter.functions.udas() .forEach(f -> udasAfter.put(Pair.create(f.name(), functionArgumentsList(f)), f)); MapDifference<Pair<FunctionName, List<String>>, UDAggregate> udasDiff = Maps.difference(udasBefore, udasAfter); // update keyspace params, if changed if (!keyspaceBefore.params.equals(keyspaceAfter.params)) Schema.instance.updateKeyspace(keyspaceName, keyspaceAfter.params); // drop everything removed udasDiff.entriesOnlyOnLeft().values().forEach(Schema.instance::dropAggregate); udfsDiff.entriesOnlyOnLeft().values().forEach(Schema.instance::dropFunction); viewsDiff.entriesOnlyOnLeft().values().forEach(v -> Schema.instance.dropView(v.ksName, v.viewName)); tablesDiff.entriesOnlyOnLeft().values().forEach(t -> Schema.instance.dropTable(t.ksName, t.cfName)); typesDiff.entriesOnlyOnLeft().values().forEach(Schema.instance::dropType); // add everything created typesDiff.entriesOnlyOnRight().values().forEach(Schema.instance::addType); tablesDiff.entriesOnlyOnRight().values().forEach(Schema.instance::addTable); viewsDiff.entriesOnlyOnRight().values().forEach(Schema.instance::addView); udfsDiff.entriesOnlyOnRight().values().forEach(Schema.instance::addFunction); udasDiff.entriesOnlyOnRight().values().forEach(Schema.instance::addAggregate); // update everything altered for (MapDifference.ValueDifference<UserType> diff : typesDiff.entriesDiffering().values()) Schema.instance.updateType(diff.rightValue()); for (MapDifference.ValueDifference<CFMetaData> diff : tablesDiff.entriesDiffering().values()) Schema.instance.updateTable(diff.rightValue()); for (MapDifference.ValueDifference<ViewDefinition> diff : viewsDiff.entriesDiffering().values()) Schema.instance.updateView(diff.rightValue()); for (MapDifference.ValueDifference<UDFunction> diff : udfsDiff.entriesDiffering().values()) Schema.instance.updateFunction(diff.rightValue()); for (MapDifference.ValueDifference<UDAggregate> diff : udasDiff.entriesDiffering().values()) Schema.instance.updateAggregate(diff.rightValue()); }