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

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

Introduction

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

Prototype

public ImmutableCollection<V> values() 

Source Link

Usage

From source file:com.facebook.buck.distributed.DistBuildTargetGraphCodec.java

public TargetGraph createTargetGraph(BuildJobStateTargetGraph remoteTargetGraph,
        Function<Integer, Cell> cellLookup) throws IOException {

    ImmutableMap.Builder<BuildTarget, TargetNode<?, ?>> targetNodeIndexBuilder = ImmutableMap.builder();

    for (BuildJobStateTargetNode remoteNode : remoteTargetGraph.getNodes()) {
        Cell cell = cellLookup.apply(remoteNode.getCellIndex());
        ProjectFilesystem projectFilesystem = cell.getFilesystem();
        BuildTarget target = decodeBuildTarget(remoteNode.getBuildTarget(), cell);

        @SuppressWarnings("unchecked")
        Map<String, Object> rawNode = objectMapper.readValue(remoteNode.getRawNode(), Map.class);
        Path buildFilePath = projectFilesystem.resolve(target.getBasePath()).resolve(cell.getBuildFileName());

        TargetNode<?, ?> targetNode = parserTargetNodeFactory.createTargetNode(cell, buildFilePath, target,
                rawNode, input -> SimplePerfEvent.scope(Optional.empty(), input));
        targetNodeIndexBuilder.put(targetNode.getBuildTarget(), targetNode);
    }//from ww  w.j  a  va  2  s .c  om
    ImmutableMap<BuildTarget, TargetNode<?, ?>> targetNodeIndex = targetNodeIndexBuilder.build();

    MutableDirectedGraph<TargetNode<?, ?>> mutableTargetGraph = new MutableDirectedGraph<>();
    for (TargetNode<?, ?> targetNode : targetNodeIndex.values()) {
        mutableTargetGraph.addNode(targetNode);
        for (BuildTarget dep : targetNode.getDeps()) {
            mutableTargetGraph.addEdge(targetNode, Preconditions.checkNotNull(targetNodeIndex.get(dep)));
        }
    }

    // TODO(csarbora): make this work with TargetGroups
    return new TargetGraph(mutableTargetGraph, targetNodeIndex, ImmutableSet.of());
}

From source file:org.elasticsearch.gateway.blobstore.BlobStoreGateway.java

public CommitPoint findCommitPoint(String index, int shardId) throws IOException {
    BlobPath path = BlobStoreIndexGateway.shardPath(basePath, index, shardId);
    ImmutableBlobContainer container = blobStore.immutableBlobContainer(path);
    ImmutableMap<String, BlobMetaData> blobs = container.listBlobs();
    List<CommitPoint> commitPointsList = Lists.newArrayList();
    for (BlobMetaData md : blobs.values()) {
        if (md.length() == 0) { // a commit point that was not flushed yet...
            continue;
        }//  ww  w.ja  v a  2 s. c o  m
        if (md.name().startsWith("commit-")) {
            try {
                commitPointsList.add(CommitPoints.fromXContent(container.readBlobFully(md.name())));
            } catch (Exception e) {
                logger.warn("failed to read commit point at path {} with name [{}]", e, path, md.name());
            }
        }
    }
    CommitPoints commitPoints = new CommitPoints(commitPointsList);
    if (commitPoints.commits().isEmpty()) {
        return null;
    }
    return commitPoints.commits().get(0);
}

From source file:org.apache.beam.sdk.io.kinesis.ShardReadersPool.java

KinesisReaderCheckpoint getCheckpointMark() {
    ImmutableMap<String, ShardRecordsIterator> currentShardIterators = shardIteratorsMap.get();
    return new KinesisReaderCheckpoint(currentShardIterators.values().stream().map(shardRecordsIterator -> {
        checkArgument(shardRecordsIterator != null, "shardRecordsIterator can not be null");
        return shardRecordsIterator.getCheckpoint();
    }).collect(Collectors.toList()));
}

From source file:org.elasticsearch.rest.action.admin.indices.mapping.get.RestGetFieldMappingAction.java

/**
 * Helper method to find out if the only included fieldmapping metadata is typed NULL, which means
 * that type and index exist, but the field did not
 *///from w ww  . jav  a  2 s  . c  o m
private boolean isFieldMappingMissingField(
        ImmutableMap<String, ImmutableMap<String, ImmutableMap<String, FieldMappingMetaData>>> mappingsByIndex)
        throws IOException {
    if (mappingsByIndex.size() != 1) {
        return false;
    }

    for (ImmutableMap<String, ImmutableMap<String, FieldMappingMetaData>> value : mappingsByIndex.values()) {
        for (ImmutableMap<String, FieldMappingMetaData> fieldValue : value.values()) {
            for (Map.Entry<String, FieldMappingMetaData> fieldMappingMetaDataEntry : fieldValue.entrySet()) {
                if (fieldMappingMetaDataEntry.getValue().isNull()) {
                    return true;
                }
            }
        }
    }
    return false;
}

From source file:com.facebook.buck.rules.coercer.StringWithMacrosTypeCoercer.java

private StringWithMacrosTypeCoercer(ImmutableMap<String, Class<? extends Macro>> macros,
        ImmutableMap<Class<? extends Macro>, MacroTypeCoercer<? extends Macro>> coercers) {
    Preconditions.checkArgument(Sets.difference(coercers.keySet(), new HashSet<>(macros.values())).isEmpty());
    this.macros = macros;
    this.coercers = coercers;
}

From source file:org.apache.beam.sdk.io.kinesis.ShardReadersPool.java

boolean allShardsUpToDate() {
    boolean shardsUpToDate = true;
    ImmutableMap<String, ShardRecordsIterator> currentShardIterators = shardIteratorsMap.get();
    for (ShardRecordsIterator shardRecordsIterator : currentShardIterators.values()) {
        shardsUpToDate &= shardRecordsIterator.isUpToDate();
    }//from   ww  w . ja  v  a  2s.  co m
    return shardsUpToDate;
}

From source file:com.facebook.buck.core.rules.actions.ActionWrapperDataFactory.java

/**
 * Creates the {@link ActionWrapperData} and its related {@link Action} from a set of {@link
 * DeclaredArtifact}s. The created {@link ActionWrapperData} is registered to the {@link
 * ActionAnalysisDataRegistry}./*from  ww  w . j  a v  a2 s.  co  m*/
 *
 * <p>This will materialize the declared {@link DeclaredArtifact}s into {@link BuildArtifact}s
 * that can be passed via {@link com.google.devtools.build.lib.packages.Provider}s to be consumed.
 *
 * @param actionClazz
 * @param target the built target
 * @param inputs the inputs to the {@link Action}
 * @param outputs the declared outputs of the {@link Action}
 * @param args the arguments for construction the {@link Action}
 * @param <T> the concrete type of the {@link Action}
 * @return a map of the given {@link DeclaredArtifact} to the corresponding {@link BuildArtifact}
 *     to propagate to other rules
 */
@SuppressWarnings("unchecked")
public <T extends AbstractAction> ImmutableMap<DeclaredArtifact, BuildArtifact> createActionAnalysisData(
        Class<T> actionClazz, BuildTarget target, ImmutableSet<Artifact> inputs,
        ImmutableSet<DeclaredArtifact> outputs, Object... args) throws ActionCreationException {
    ActionAnalysisDataKey key = ImmutableActionAnalysisDataKey.of(target, new ID() {
    });
    ImmutableMap<DeclaredArtifact, BuildArtifact> materializedOutputsMap = ImmutableMap
            .copyOf(Maps.toMap(outputs, declared -> declared.materialize(key)));
    Object[] fullArgs = new Object[args.length + 3];
    fullArgs[0] = target;
    fullArgs[1] = inputs;
    fullArgs[2] = materializedOutputsMap.values();
    System.arraycopy(args, 0, fullArgs, 3, args.length);
    try {
        // TODO(bobyf): we can probably do some stuff here with annotation processing to generate
        // typed creation
        T action = (T) actionClazz.getConstructors()[0].newInstance(fullArgs);
        ActionWrapperData actionAnalysisData = ImmutableActionWrapperData.of(key, action);
        actionRegistry.registerAction(actionAnalysisData);

        return materializedOutputsMap;
    } catch (Exception e) {
        throw new ActionCreationException(e, actionClazz, fullArgs);
    }
}

From source file:com.facebook.buck.distributed.DistributedBuildTargetGraphCodec.java

public TargetGraph createTargetGraph(BuildJobStateTargetGraph remoteTargetGraph)
        throws IOException, InterruptedException {
    ImmutableMap.Builder<Integer, Cell> cellBuilder = ImmutableMap.builder();
    // TODO(marcinkosiba): Sort out the story around Cells.
    for (Map.Entry<Integer, String> remoteFileSystemRoot : remoteTargetGraph.getFileSystemRoots().entrySet()) {
        Path remoteFilesystemRoot = Files.createTempDirectory(
                rootFilesystem.resolve(rootFilesystem.getBuckPaths().getBuckOut()), "remote_");
        ProjectFilesystem projectFilesystem = new ProjectFilesystem(remoteFilesystemRoot);
        Cell cell = rootCell.createCellForDistributedBuild(console, clock, projectFilesystem,
                rootCell.getBuckConfig());
        cellBuilder.put(remoteFileSystemRoot.getKey(), cell);
    }//from  ww  w . ja  v  a 2 s  .  c  o  m
    ImmutableMap<Integer, Cell> cells = cellBuilder.build();

    ImmutableMap.Builder<BuildTarget, TargetNode<?>> targetNodeIndexBuilder = ImmutableMap.builder();

    for (BuildJobStateTargetNode remoteNode : remoteTargetGraph.getNodes()) {
        Cell cell = Preconditions.checkNotNull(cells.get(remoteNode.getFileSystemRootIndex()));
        ProjectFilesystem projectFilesystem = cell.getFilesystem();
        BuildTarget target = decodeBuildTarget(remoteNode.getBuildTarget(), cell);

        @SuppressWarnings("unchecked")
        Map<String, Object> rawNode = objectMapper.readValue(remoteNode.getRawNode(), Map.class);
        Path buildFilePath = projectFilesystem.resolve(target.getBasePath()).resolve(cell.getBuildFileName());

        TargetNode<?> targetNode = parserTargetNodeFactory.createTargetNode(cell, buildFilePath, target,
                rawNode);
        targetNodeIndexBuilder.put(targetNode.getBuildTarget(), targetNode);
    }
    ImmutableMap<BuildTarget, TargetNode<?>> targetNodeIndex = targetNodeIndexBuilder.build();

    MutableDirectedGraph<TargetNode<?>> mutableTargetGraph = new MutableDirectedGraph<>();
    for (TargetNode<?> targetNode : targetNodeIndex.values()) {
        mutableTargetGraph.addNode(targetNode);
        for (BuildTarget dep : targetNode.getDeps()) {
            mutableTargetGraph.addEdge(targetNode, Preconditions.checkNotNull(targetNodeIndex.get(dep)));
        }
    }

    return new TargetGraph(mutableTargetGraph, targetNodeIndex);
}

From source file:org.apache.rya.shell.util.RyaDetailsFormatter.java

/**
 * Pretty formats an instance of {@link RyaDetails}.
 *
 * @param details - The object to format. (not null)
 * @return A pretty render of the object.
 *//*from   w  w w  .ja va 2  s.com*/
public String format(final RyaDetails details) {
    requireNonNull(details);

    final StringBuilder report = new StringBuilder();

    report.append("General Metadata:\n");
    report.append("  Instance Name: ").append(details.getRyaInstanceName()).append("\n");
    report.append("  RYA Version: ").append(details.getRyaVersion()).append("\n");
    report.append("  Users: ").append(Joiner.on(", ").join(details.getUsers())).append("\n");

    report.append("Secondary Indicies:\n");
    report.append("  Entity Centric Index:\n");
    report.append("    Enabled: ").append(details.getEntityCentricIndexDetails().isEnabled()).append("\n");
    //RYA-215        report.append("  Geospatial Index:\n");
    //RYA-215        report.append("    Enabled: ").append( details.getGeoIndexDetails().isEnabled() ).append("\n");
    report.append("  Free Text Index:\n");
    report.append("    Enabled: ").append(details.getFreeTextIndexDetails().isEnabled()).append("\n");
    report.append("  Temporal Index:\n");
    report.append("    Enabled: ").append(details.getTemporalIndexDetails().isEnabled()).append("\n");

    report.append("  PCJ Index:\n");
    final PCJIndexDetails pcjDetails = details.getPCJIndexDetails();
    report.append("    Enabled: ").append(pcjDetails.isEnabled()).append("\n");
    if (pcjDetails.isEnabled()) {
        if (pcjDetails.getFluoDetails().isPresent()) {
            final String fluoAppName = pcjDetails.getFluoDetails().get().getUpdateAppName();
            report.append("    Fluo App Name: ").append(fluoAppName).append("\n");
        }

        final ImmutableMap<String, PCJDetails> pcjs = pcjDetails.getPCJDetails();
        report.append("    PCJs:\n");
        if (pcjs.isEmpty()) {
            report.append("      No PCJs have been added yet.\n");
        } else {
            for (final PCJDetails pcj : pcjs.values()) {
                report.append("      ID: ").append(pcj.getId()).append("\n");

                final String updateStrategy = format(pcj.getUpdateStrategy(), "None");
                report.append("        Update Strategy: ").append(updateStrategy).append("\n");

                final String lastUpdateTime = format(pcj.getLastUpdateTime(), "unavailable");
                report.append("        Last Update Time: ").append(lastUpdateTime).append("\n");
            }
        }
    }

    report.append("Statistics:\n");
    report.append("  Prospector:\n");
    final String prospectorLastUpdateTime = format(details.getProspectorDetails().getLastUpdated(),
            "unavailable");
    report.append("    Last Update Time: ").append(prospectorLastUpdateTime).append("\n");

    report.append("  Join Selectivity:\n");
    final String jsLastUpdateTime = format(details.getJoinSelectivityDetails().getLastUpdated(), "unavailable");
    report.append("    Last Updated Time: ").append(jsLastUpdateTime).append("\n");

    return report.toString();
}

From source file:com.google.devtools.build.lib.rules.platform.Platform.java

@Override
public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException {

    Iterable<ConstraintValueInfo> constraintValues = ConstraintValueInfo
            .fromTargets(ruleContext.getPrerequisites(PlatformRule.CONSTRAINT_VALUES_ATTR, Mode.DONT_CHECK));

    // Verify the constraints - no two values for the same setting, and construct the map.
    ImmutableMap<ConstraintSettingInfo, ConstraintValueInfo> constraints = validateConstraints(ruleContext,
            constraintValues);//from  w w  w.  j a  va  2  s.  c o  m
    if (constraints == null) {
        // An error occurred, return null.
        return null;
    }

    PlatformInfo.Builder platformProviderBuilder = PlatformInfo.builder();
    platformProviderBuilder.constraints(constraints.values());

    Map<String, String> remoteExecutionProperties = ruleContext.attributes()
            .get(PlatformRule.REMOTE_EXECUTION_PROPS_ATTR, Type.STRING_DICT);
    platformProviderBuilder.remoteExecutionProperties(remoteExecutionProperties);

    return new RuleConfiguredTargetBuilder(ruleContext)
            .addProvider(RunfilesProvider.class, RunfilesProvider.EMPTY)
            .addProvider(FileProvider.class, FileProvider.EMPTY)
            .addProvider(FilesToRunProvider.class, FilesToRunProvider.EMPTY)
            .addNativeDeclaredProvider(platformProviderBuilder.build()).build();
}