use of org.apache.flink.shaded.guava30.com.google.common.collect.MapDifference in project buck by facebook.
the class DaemonicCellState method invalidateIfEnvHasChanged.
Optional<MapDifference<String, String>> invalidateIfEnvHasChanged(Cell cell, Path buildFile) {
// Invalidate if env vars have changed.
ImmutableMap<String, Optional<String>> usedEnv;
try (AutoCloseableLock readLock = rawAndComputedNodesLock.readLock()) {
usedEnv = buildFileEnv.get(buildFile);
}
if (usedEnv == null) {
this.cell.set(cell);
return Optional.empty();
}
for (Map.Entry<String, Optional<String>> ent : usedEnv.entrySet()) {
Optional<String> value = Optional.ofNullable(cell.getBuckConfig().getEnvironment().get(ent.getKey()));
if (!value.equals(ent.getValue())) {
invalidatePath(buildFile);
this.cell.set(cell);
return Optional.of(Maps.difference(value.map(v -> ImmutableMap.of(ent.getKey(), v)).orElse(ImmutableMap.of()), ent.getValue().map(v -> ImmutableMap.of(ent.getKey(), v)).orElse(ImmutableMap.of())));
}
}
return Optional.empty();
}
use of org.apache.flink.shaded.guava30.com.google.common.collect.MapDifference in project cassandra by apache.
the class SchemaKeyspace method makeUpdateTableMutation.
static Mutation.SimpleBuilder makeUpdateTableMutation(KeyspaceMetadata keyspace, TableMetadata oldTable, TableMetadata newTable, long timestamp) {
Mutation.SimpleBuilder builder = makeCreateKeyspaceMutation(keyspace.name, keyspace.params, timestamp);
addTableToSchemaMutation(newTable, false, builder);
MapDifference<ByteBuffer, ColumnMetadata> columnDiff = Maps.difference(oldTable.columns, newTable.columns);
// columns that are no longer needed
for (ColumnMetadata column : columnDiff.entriesOnlyOnLeft().values()) dropColumnFromSchemaMutation(oldTable, column, builder);
// newly added columns
for (ColumnMetadata column : columnDiff.entriesOnlyOnRight().values()) addColumnToSchemaMutation(newTable, column, builder);
// old columns with updated attributes
for (ByteBuffer name : columnDiff.entriesDiffering().keySet()) addColumnToSchemaMutation(newTable, newTable.getColumn(name), builder);
// dropped columns
MapDifference<ByteBuffer, DroppedColumn> droppedColumnDiff = Maps.difference(oldTable.droppedColumns, newTable.droppedColumns);
// newly dropped columns
for (DroppedColumn column : droppedColumnDiff.entriesOnlyOnRight().values()) addDroppedColumnToSchemaMutation(newTable, column, builder);
// columns added then dropped again
for (ByteBuffer name : droppedColumnDiff.entriesDiffering().keySet()) addDroppedColumnToSchemaMutation(newTable, newTable.droppedColumns.get(name), builder);
MapDifference<String, TriggerMetadata> triggerDiff = triggersDiff(oldTable.triggers, newTable.triggers);
// dropped triggers
for (TriggerMetadata trigger : triggerDiff.entriesOnlyOnLeft().values()) dropTriggerFromSchemaMutation(oldTable, trigger, builder);
// newly created triggers
for (TriggerMetadata trigger : triggerDiff.entriesOnlyOnRight().values()) addTriggerToSchemaMutation(newTable, trigger, builder);
MapDifference<String, IndexMetadata> indexesDiff = indexesDiff(oldTable.indexes, newTable.indexes);
// dropped indexes
for (IndexMetadata index : indexesDiff.entriesOnlyOnLeft().values()) dropIndexFromSchemaMutation(oldTable, index, builder);
// newly created indexes
for (IndexMetadata index : indexesDiff.entriesOnlyOnRight().values()) addIndexToSchemaMutation(newTable, index, builder);
// updated indexes need to be updated
for (MapDifference.ValueDifference<IndexMetadata> diff : indexesDiff.entriesDiffering().values()) addUpdatedIndexToSchemaMutation(newTable, diff.rightValue(), builder);
return builder;
}
use of org.apache.flink.shaded.guava30.com.google.common.collect.MapDifference in project metron by apache.
the class GrokParserTest method compare.
public boolean compare(JSONObject expected, JSONObject actual) {
MapDifference mapDifferences = Maps.difference(expected, actual);
if (mapDifferences.entriesOnlyOnLeft().size() > 0) {
fail("Expected JSON has extra parameters: " + mapDifferences.entriesOnlyOnLeft());
}
if (mapDifferences.entriesOnlyOnRight().size() > 0) {
fail("Actual JSON has extra parameters: " + mapDifferences.entriesOnlyOnRight());
}
Map actualDifferences = new HashMap();
if (mapDifferences.entriesDiffering().size() > 0) {
Map differences = Collections.unmodifiableMap(mapDifferences.entriesDiffering());
for (Object key : differences.keySet()) {
Object expectedValueObject = expected.get(key);
Object actualValueObject = actual.get(key);
if (expectedValueObject instanceof Long || expectedValueObject instanceof Integer) {
Long expectedValue = Long.parseLong(expectedValueObject.toString());
Long actualValue = Long.parseLong(actualValueObject.toString());
if (!expectedValue.equals(actualValue)) {
actualDifferences.put(key, differences.get(key));
}
} else {
actualDifferences.put(key, differences.get(key));
}
}
}
if (actualDifferences.size() > 0) {
fail("Expected and Actual JSON values don't match: " + actualDifferences);
}
return true;
}
use of org.apache.flink.shaded.guava30.com.google.common.collect.MapDifference in project OreSpawn by MinecraftModDevelopmentMods.
the class EventHandlers method getDifferingTags.
private List<String> getDifferingTags(NBTTagCompound chunkTag, int dim, Biome biome) {
NBTTagCompound tagList = chunkTag.getCompoundTag(Constants.FEATURES_TAG);
Map<String, String> currentBits = new TreeMap<>();
Map<String, String> oldBits = new TreeMap<>();
OreSpawn.API.getAllSpawns().entrySet().stream().filter(ent -> ent.getValue().dimensionAllowed(dim)).filter(ent -> ent.getValue().biomeAllowed(biome)).forEach(ent -> currentBits.put(ent.getKey(), ent.getValue().getFeature().getFeatureName()));
tagList.getKeySet().stream().forEach(tag -> oldBits.put(tag, tagList.getString(tag)));
MapDifference<String, String> diff = Maps.difference(oldBits, currentBits);
List<String> stuff = Lists.newLinkedList();
stuff.addAll(diff.entriesDiffering().entrySet().stream().map(ent -> ent.getKey()).collect(Collectors.toList()));
stuff.addAll(diff.entriesOnlyOnRight().entrySet().stream().map(ent -> ent.getKey()).collect(Collectors.toList()));
return ImmutableList.copyOf(stuff);
}
use of org.apache.flink.shaded.guava30.com.google.common.collect.MapDifference in project OreSpawn by MinecraftModDevelopmentMods.
the class EventHandlers method featuresAreDifferent.
private boolean featuresAreDifferent(NBTTagCompound chunkTag, int dim, Biome biome) {
NBTTagCompound tagList = chunkTag.getCompoundTag(Constants.FEATURES_TAG);
Map<String, String> currentBits = new TreeMap<>();
Map<String, String> oldBits = new TreeMap<>();
OreSpawn.API.getAllSpawns().entrySet().stream().filter(ent -> ent.getValue().dimensionAllowed(dim)).filter(ent -> ent.getValue().biomeAllowed(biome)).forEach(ent -> currentBits.put(ent.getKey(), ent.getValue().getFeature().getFeatureName()));
tagList.getKeySet().stream().forEach(tag -> oldBits.put(tag, tagList.getString(tag)));
MapDifference<String, String> diff = Maps.difference(oldBits, currentBits);
return diff.entriesDiffering().size() == 0 && diff.entriesOnlyOnLeft().size() == 0 && diff.entriesOnlyOnRight().size() == 0;
}
Aggregations