Example usage for com.google.common.collect ImmutableMap keySet

List of usage examples for com.google.common.collect ImmutableMap keySet

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableMap keySet.

Prototype

public ImmutableSet<K> keySet() 

Source Link

Usage

From source file:com.facebook.buck.dotnet.DotnetFramework.java

private static Path findProgramFiles(FileSystem osFilesystem, ImmutableMap<String, String> env) {
    for (String envName : PROGRAM_FILES_ENV_NAMES) {
        for (String key : env.keySet()) {
            if (envName.equals(key.toLowerCase(US))) {
                String value = env.get(key);
                Path path = osFilesystem.getPath(value);
                if (Files.exists(path)) {
                    return path;
                } else {
                    LOG.info("Found a program files path with %s that did not exist: %s", key, value);
                }/*from www.  j  a  va2  s.c om*/
            }
        }
    }

    throw new HumanReadableException("Unable to find ProgramFiles or ProgramFiles(x86) env var");
}

From source file:com.google.enterprise.connector.persist.StoreMigrator.java

/**
 * Checks for missing persistently stored data in the
 * {@code persistentStore}.  If items are missing from the store,
 * log a message.//  w  w  w.  ja  v a2  s  . co m
 *
 * @param persistentStore PersistentStore to check.
 * @param connectorNames Collection of connector names to check.
 */
public static void checkMissing(PersistentStore persistentStore, Collection<String> connectorNames) {
    // Check for missing objects in the specified store.
    ImmutableMap<StoreContext, ConnectorStamps> inventory = persistentStore.getInventory();
    for (StoreContext context : inventory.keySet()) {
        if (connectorNames != null && !connectorNames.contains(context.getConnectorName())) {
            continue;
        }
        if (persistentStore.getConnectorConfiguration(context) == null) {
            logMissing(context, "configuration");
        }
        if (persistentStore.getConnectorSchedule(context) == null) {
            logMissing(context, "traversal schedule");
        }
        if (persistentStore.getConnectorState(context) == null) {
            logMissing(context, "traversal state");
        }
    }
}

From source file:org.apache.beam.runners.core.construction.ReplacementOutputs.java

public static Map<PValue, ReplacementOutput> tagged(Map<TupleTag<?>, PValue> original, POutput replacement) {
    Map<TupleTag<?>, TaggedPValue> originalTags = new HashMap<>();
    for (Map.Entry<TupleTag<?>, PValue> originalValue : original.entrySet()) {
        originalTags.put(originalValue.getKey(),
                TaggedPValue.of(originalValue.getKey(), originalValue.getValue()));
    }/*w  w w. j  a  v a2s .c  o  m*/
    ImmutableMap.Builder<PValue, ReplacementOutput> resultBuilder = ImmutableMap.builder();
    Set<TupleTag<?>> missingTags = new HashSet<>(originalTags.keySet());
    for (Map.Entry<TupleTag<?>, PValue> replacementValue : replacement.expand().entrySet()) {
        TaggedPValue mapped = originalTags.get(replacementValue.getKey());
        checkArgument(mapped != null,
                "Missing original output for Tag %s and Value %s Between original %s and replacement %s",
                replacementValue.getKey(), replacementValue.getValue(), original, replacement.expand());
        resultBuilder.put(replacementValue.getValue(), ReplacementOutput.of(mapped,
                TaggedPValue.of(replacementValue.getKey(), replacementValue.getValue())));
        missingTags.remove(replacementValue.getKey());
    }
    ImmutableMap<PValue, ReplacementOutput> result = resultBuilder.build();
    checkArgument(missingTags.isEmpty(), "Missing replacement for tags %s. Encountered tags: %s", missingTags,
            result.keySet());
    return result;
}

From source file:com.google.enterprise.connector.persist.StoreMigrator.java

/**
 * Migrates data from the {@code sourceStore} to the {@code destStore}.
 *
 * @param sourceStore source {@link PersistentStore}
 * @param destStore destination {@link PersistentStore}
 * @param connectorNames Collection of connector names to migrate.
 * @param force if {@code true} overwrite existing data in the
 *        {@code destStore}.//from   ww w.j av a2  s  .c  o m
 */
public static void migrate(PersistentStore sourceStore, PersistentStore destStore,
        Collection<String> connectorNames, boolean force) {
    ImmutableMap<StoreContext, ConnectorStamps> inventory = sourceStore.getInventory();
    for (StoreContext context : inventory.keySet()) {
        if (connectorNames != null && !connectorNames.contains(context.getConnectorName())) {
            continue;
        }
        // This double assignment ensures that we check the same
        // object type that we're storing.
        Configuration config = destStore.getConnectorConfiguration(context);
        if (force || config == null) {
            config = sourceStore.getConnectorConfiguration(context);
            if (config != null) {
                logMigration(sourceStore, destStore, context, "configuration");
                destStore.storeConnectorConfiguration(context, config);
            }
        }
        Schedule sched = destStore.getConnectorSchedule(context);
        if (force || sched == null) {
            sched = sourceStore.getConnectorSchedule(context);
            if (sched != null) {
                logMigration(sourceStore, destStore, context, "traversal schedule");
                destStore.storeConnectorSchedule(context, sched);
            }
        }
        String state = destStore.getConnectorState(context);
        if (force || state == null) {
            state = sourceStore.getConnectorState(context);
            if (state != null) {
                logMigration(sourceStore, destStore, context, "traversal state");
                destStore.storeConnectorState(context, state);
            }
        }
    }
}

From source file:ai.grakn.graql.internal.gremlin.spanningtree.Arborescence.java

public static <T> Arborescence<T> of(ImmutableMap<T, T> parents) {
    if (parents != null && !parents.isEmpty()) {
        HashSet<T> allParents = Sets.newHashSet(parents.values());
        allParents.removeAll(parents.keySet());
        if (allParents.size() == 1) {
            return new Arborescence<>(parents, allParents.iterator().next());
        }/* www.  j a  v a2 s .com*/
    }
    return new Arborescence<>(parents, null);
}

From source file:org.apache.beam.runners.core.ReplacementOutputs.java

public static Map<PValue, ReplacementOutput> tagged(List<TaggedPValue> original, POutput replacement) {
    Map<TupleTag<?>, TaggedPValue> originalTags = new HashMap<>();
    for (TaggedPValue value : original) {
        TaggedPValue former = originalTags.put(value.getTag(), value);
        checkArgument(former == null || former.equals(value),
                "Found two tags in an expanded output which map to different values: output: %s "
                        + "Values: %s and %s",
                original, former, value);
    }/*from   w w w .  ja v  a2 s.  c  o  m*/
    ImmutableMap.Builder<PValue, ReplacementOutput> resultBuilder = ImmutableMap.builder();
    Set<TupleTag<?>> missingTags = new HashSet<>(originalTags.keySet());
    for (TaggedPValue replacementValue : replacement.expand()) {
        TaggedPValue mapped = originalTags.get(replacementValue.getTag());
        checkArgument(mapped != null,
                "Missing original output for Tag %s and Value %s Between original %s and replacement %s",
                replacementValue.getTag(), replacementValue.getValue(), original, replacement.expand());
        resultBuilder.put(replacementValue.getValue(), ReplacementOutput.of(mapped, replacementValue));
        missingTags.remove(replacementValue.getTag());
    }
    ImmutableMap<PValue, ReplacementOutput> result = resultBuilder.build();
    checkArgument(missingTags.isEmpty(), "Missing replacement for tags %s. Encountered tags: %s", missingTags,
            result.keySet());
    return result;
}

From source file:de.adrodoc55.minecraft.mpl.conversion.SchematicConverter.java

public static TagCompound convert(MplCompilationResult result) {
    ImmutableMap<Coordinate3D, MplBlock> blockMap = result.getBlocks();
    ImmutableSet<Coordinate3D> coordinates = blockMap.keySet();
    Coordinate3D min = getMinCoordinate(coordinates);
    Coordinate3D max = getMaxCoordinate(coordinates);
    short width = (short) (1 + max.getX() - min.getX());
    short heigth = (short) (1 + max.getY() - min.getY());
    short length = (short) (1 + max.getZ() - min.getZ());
    int volume = width * heigth * length;
    ByteBuffer blocks = ByteBuffer.allocate(volume);
    ByteBuffer data = ByteBuffer.allocate(volume);
    List<ITag> tileEntities = new ArrayList<>(blockMap.size());
    for (int y = min.getY(); y <= max.getY(); y++) {
        for (int z = min.getZ(); z <= max.getZ(); z++) {
            for (int x = min.getX(); x <= max.getX(); x++) {
                Coordinate3D coord = new Coordinate3D(x, y, z);
                MplBlock block = blockMap.get(coord);
                if (block == null) {
                    block = new AirBlock(coord);
                }/*  w ww . j  ava2 s .c  o  m*/

                // block
                blocks.put(block.getByteBlockId());

                // data
                if (block instanceof CommandBlock) {
                    data.put(((CommandBlock) block).getDamageValue());
                } else {
                    data.put((byte) 0);
                }

                // tile entity
                if (block instanceof CommandBlock) {
                    tileEntities.add(toControl((CommandBlock) block));
                }
            }
        }
    }
    TagCompound schematic = new TagCompound("Schematic");
    schematic.setTag(new TagShort("Width", width));
    schematic.setTag(new TagShort("Height", heigth));
    schematic.setTag(new TagShort("Length", length));
    schematic.setTag(new TagString("Materials", "Alpha"));
    schematic.setTag(new TagByteArray("Blocks", blocks.array()));
    schematic.setTag(new TagByteArray("Data", data.array()));
    schematic.setTag(new TagList("TileEntities", tileEntities));
    schematic.setTag(new TagList("Entities", new ArrayList<>()));
    schematic.setTag(new TagList("TileTicks", new ArrayList<>()));
    return schematic;
}

From source file:com.spectralogic.ds3contractcomparator.Ds3ApiSpecComparatorImpl.java

/**
 * Gets the union of all {@link Ds3Type} names in both maps
 *///from www  . j  a v a 2  s .  c o  m
static ImmutableSet<String> getTypeNameUnion(final ImmutableMap<String, Ds3Type> oldTypes,
        final ImmutableMap<String, Ds3Type> newTypes) {
    final ImmutableSet.Builder<String> builder = ImmutableSet.builder();
    if (hasContent(oldTypes)) {
        oldTypes.keySet().forEach(builder::add);
    }
    if (hasContent(newTypes)) {
        newTypes.keySet().forEach(builder::add);
    }
    return builder.build();
}

From source file:no.ssb.vtl.script.expressions.FunctionExpression.java

@VisibleForTesting
static Map<String, VTLExpression> mergeArguments(VTLFunction.Signature signature, List<VTLExpression> arguments,
        Map<String, VTLExpression> namedArguments) {

    // Check unnamed arguments count.
    checkArgument(arguments.size() <= signature.size(), TOO_MANY_ARGUMENTS, signature.size(), arguments.size());

    ImmutableMap.Builder<String, VTLExpression> builder = ImmutableMap.builder();

    // Match the list with the signature names.
    Iterator<String> namesIterator = signature.keySet().iterator();
    for (VTLExpression argument : arguments) {
        builder.put(namesIterator.next(), argument);
    }//w  w  w.  j a  v a  2 s . co  m

    // Check for duplicates
    Set<String> duplicates = Sets.intersection(namedArguments.keySet(), builder.build().keySet());
    checkArgument(duplicates.isEmpty(), DUPLICATE_ARGUMENTS, String.join(", ", duplicates));

    ImmutableMap<String, VTLExpression> computedArguments = builder.putAll(namedArguments).build();

    // Check for unknown arguments.
    Set<String> unknown = Sets.difference(computedArguments.keySet(), signature.keySet());
    checkArgument(unknown.isEmpty(), UNKNOWN_ARGUMENTS, String.join(", ", unknown));

    // Check for missing arguments
    Set<String> required = Maps.filterValues(signature, VTLFunction.Argument::isRequired).keySet();
    Set<String> missing = Sets.difference(required, computedArguments.keySet());
    checkArgument(missing.isEmpty(), MISSING_ARGUMENTS, String.join(", ", missing));

    return computedArguments;
}

From source file:com.telefonica.iot.cygnus.management.MetricsHandlers.java

/**
 * Deletes metrics from all the given sources and sinks.
 * @param sources//from  ww  w.j  a v a2 s  . co  m
 * @param sinks
 */
private static void deleteMetrics(ImmutableMap<String, SourceRunner> sources,
        ImmutableMap<String, SinkRunner> sinks) {
    if (sources != null) {
        for (String key : sources.keySet()) {
            Source source;
            HTTPSourceHandler handler;

            try {
                SourceRunner sr = sources.get(key);
                source = sr.getSource();
                Field f = source.getClass().getDeclaredField("handler");
                f.setAccessible(true);
                handler = (HTTPSourceHandler) f.get(source);
            } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException
                    | SecurityException e) {
                LOGGER.error("There was a problem when getting a sink. Details: " + e.getMessage());
                continue;
            } // try catch

            if (handler instanceof CygnusHandler) {
                CygnusHandler ch = (CygnusHandler) handler;
                ch.setServiceMetrics(new CygnusMetrics());
            } // if
        } // for
    } // if

    if (sinks != null) {
        for (String key : sinks.keySet()) {
            Sink sink;

            try {
                SinkRunner sr = sinks.get(key);
                SinkProcessor sp = sr.getPolicy();
                Field f = sp.getClass().getDeclaredField("sink");
                f.setAccessible(true);
                sink = (Sink) f.get(sp);
            } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException
                    | SecurityException e) {
                LOGGER.error("There was a problem when getting a sink. Details: " + e.getMessage());
                continue;
            } // try catch

            if (sink instanceof CygnusSink) {
                CygnusSink cs = (CygnusSink) sink;
                cs.setServiceMetrics(new CygnusMetrics());
            } // if
        } // for
    } // if
}