Search in sources :

Example 1 with MapDifference

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();
}
Also used : Logger(com.facebook.buck.log.Logger) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) BuildTargetException(com.facebook.buck.model.BuildTargetException) AutoCloseableReadWriteUpdateLock(com.facebook.buck.util.concurrent.AutoCloseableReadWriteUpdateLock) HashMap(java.util.HashMap) GuardedBy(javax.annotation.concurrent.GuardedBy) BuildTarget(com.facebook.buck.model.BuildTarget) Maps(com.google.common.collect.Maps) AtomicReference(java.util.concurrent.atomic.AtomicReference) SetMultimap(com.google.common.collect.SetMultimap) ConcurrentMap(java.util.concurrent.ConcurrentMap) MapDifference(com.google.common.collect.MapDifference) AutoCloseableLock(com.facebook.buck.util.concurrent.AutoCloseableLock) HashMultimap(com.google.common.collect.HashMultimap) Map(java.util.Map) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) Cell(com.facebook.buck.rules.Cell) Path(java.nio.file.Path) Optional(java.util.Optional) AutoCloseableLock(com.facebook.buck.util.concurrent.AutoCloseableLock) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Example 2 with MapDifference

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;
}
Also used : MapDifference(com.google.common.collect.MapDifference) ByteBuffer(java.nio.ByteBuffer)

Example 3 with MapDifference

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;
}
Also used : MapDifference(com.google.common.collect.MapDifference) HashMap(java.util.HashMap) JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with MapDifference

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);
}
Also used : Arrays(java.util.Arrays) OreGenEvent(net.minecraftforge.event.terraingen.OreGenEvent) EventType(net.minecraftforge.event.terraingen.OreGenEvent.GenerateMinable.EventType) Random(java.util.Random) IChunkGenerator(net.minecraft.world.gen.IChunkGenerator) Deque(java.util.Deque) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Side(net.minecraftforge.fml.relauncher.Side) ObfuscationReflectionHelper(net.minecraftforge.fml.common.ObfuscationReflectionHelper) Map(java.util.Map) Constants(com.mcmoddev.orespawn.data.Constants) ChunkDataEvent(net.minecraftforge.event.world.ChunkDataEvent) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Event(net.minecraftforge.fml.common.eventhandler.Event) World(net.minecraft.world.World) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ChunkPos(net.minecraft.util.math.ChunkPos) ChunkProviderServer(net.minecraft.world.gen.ChunkProviderServer) BlockPos(net.minecraft.util.math.BlockPos) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) MapDifference(com.google.common.collect.MapDifference) EventPriority(net.minecraftforge.fml.common.eventhandler.EventPriority) List(java.util.List) Queues(com.google.common.collect.Queues) TreeMap(java.util.TreeMap) Phase(net.minecraftforge.fml.common.gameevent.TickEvent.Phase) Config(com.mcmoddev.orespawn.data.Config) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) WorldTickEvent(net.minecraftforge.fml.common.gameevent.TickEvent.WorldTickEvent) Biome(net.minecraft.world.biome.Biome) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) TreeMap(java.util.TreeMap)

Example 5 with MapDifference

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;
}
Also used : Arrays(java.util.Arrays) OreGenEvent(net.minecraftforge.event.terraingen.OreGenEvent) EventType(net.minecraftforge.event.terraingen.OreGenEvent.GenerateMinable.EventType) Random(java.util.Random) IChunkGenerator(net.minecraft.world.gen.IChunkGenerator) Deque(java.util.Deque) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Side(net.minecraftforge.fml.relauncher.Side) ObfuscationReflectionHelper(net.minecraftforge.fml.common.ObfuscationReflectionHelper) Map(java.util.Map) Constants(com.mcmoddev.orespawn.data.Constants) ChunkDataEvent(net.minecraftforge.event.world.ChunkDataEvent) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Event(net.minecraftforge.fml.common.eventhandler.Event) World(net.minecraft.world.World) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ChunkPos(net.minecraft.util.math.ChunkPos) ChunkProviderServer(net.minecraft.world.gen.ChunkProviderServer) BlockPos(net.minecraft.util.math.BlockPos) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) MapDifference(com.google.common.collect.MapDifference) EventPriority(net.minecraftforge.fml.common.eventhandler.EventPriority) List(java.util.List) Queues(com.google.common.collect.Queues) TreeMap(java.util.TreeMap) Phase(net.minecraftforge.fml.common.gameevent.TickEvent.Phase) Config(com.mcmoddev.orespawn.data.Config) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) WorldTickEvent(net.minecraftforge.fml.common.gameevent.TickEvent.WorldTickEvent) Biome(net.minecraft.world.biome.Biome) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) TreeMap(java.util.TreeMap)

Aggregations

MapDifference (com.google.common.collect.MapDifference)10 Map (java.util.Map)7 Maps (com.google.common.collect.Maps)5 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 Lists (com.google.common.collect.Lists)3 AutoCloseableLock (com.facebook.buck.util.concurrent.AutoCloseableLock)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Strings (com.google.common.base.Strings)2 ImmutableList (com.google.common.collect.ImmutableList)2 Queues (com.google.common.collect.Queues)2 Config (com.mcmoddev.orespawn.data.Config)2 Constants (com.mcmoddev.orespawn.data.Constants)2 QualifiedName (com.netflix.metacat.common.QualifiedName)2 ConnectorContext (com.netflix.metacat.common.server.connectors.ConnectorContext)2 HiveMetrics (com.netflix.metacat.connector.hive.monitoring.HiveMetrics)2 HiveConnectorFastServiceMetric (com.netflix.metacat.connector.hive.util.HiveConnectorFastServiceMetric)2 Registry (com.netflix.spectator.api.Registry)2 Types (java.sql.Types)2 Arrays (java.util.Arrays)2