Example usage for com.google.common.collect Iterables toString

List of usage examples for com.google.common.collect Iterables toString

Introduction

In this page you can find the example usage for com.google.common.collect Iterables toString.

Prototype

public static String toString(Iterable<?> iterable) 

Source Link

Document

Returns a string representation of iterable , with the format [e1, e2, ..., en] (that is, identical to java.util.Arrays Arrays .toString(Iterables.toArray(iterable)) ).

Usage

From source file:org.apache.brooklyn.core.location.dynamic.clocker.StubInfrastructureImpl.java

/**
 * De-register our {@link DockerLocation} and its children.
 *//*from  w ww  .  ja  v  a 2s. com*/
@Override
public void stop() {
    setExpectedStateAndRecordLifecycleEvent(Lifecycle.STOPPING);
    sensors().set(SERVICE_UP, Boolean.FALSE);

    // Find all applications and stop, blocking for up to five minutes until ended
    try {
        Iterable<Entity> entities = Iterables.filter(getManagementContext().getEntityManager().getEntities(),
                StubUtils.sameInfrastructure(this));
        Set<Application> applications = ImmutableSet
                .copyOf(Iterables.transform(entities, new Function<Entity, Application>() {
                    @Override
                    public Application apply(Entity input) {
                        return input.getApplication();
                    }
                }));
        LOG.debug("Stopping applications: {}", Iterables.toString(applications));
        Entities.invokeEffectorList(this, applications, Startable.STOP).get(Duration.THIRTY_SECONDS);
    } catch (Exception e) {
        LOG.warn("Error stopping applications", e);
    }

    // Stop all Docker hosts in parallel
    try {
        DynamicCluster hosts = sensors().get(DOCKER_HOST_CLUSTER);
        LOG.debug("Stopping hosts: {}", Iterables.toString(hosts.getMembers()));
        Entities.invokeEffectorList(this, hosts.getMembers(), Startable.STOP).get(Duration.THIRTY_SECONDS);
    } catch (Exception e) {
        LOG.warn("Error stopping hosts", e);
    }

    deleteLocation();

    // Stop anything else left over
    super.stop();
}

From source file:org.onos.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeModification.java

private OperationWithModification resolveModificationFor(final YangInstanceIdentifier path) {
    upgradeIfPossible();// ww w  .j  av a 2  s  .c o m

    /*
     * Walk the strategy and modification trees in-sync, creating modification nodes as needed.
     *
     * If the user has provided wrong input, we may end up with a bunch of TOUCH nodes present
     * ending with an empty one, as we will throw the exception below. This fact could end up
     * being a problem, as we'd have bunch of phantom operations.
     *
     * That is fine, as we will prune any empty TOUCH nodes in the last phase of the ready
     * process.
     */
    ModificationApplyOperation operation = strategyTree;
    ModifiedNode modification = rootNode;

    int i = 1;
    for (final PathArgument pathArg : path.getPathArguments()) {
        final Optional<ModificationApplyOperation> potential = operation.getChild(pathArg);
        if (!potential.isPresent()) {
            throw new SchemaValidationFailedException(String.format("Child %s is not present in schema tree.",
                    Iterables.toString(Iterables.limit(path.getPathArguments(), i))));
        }
        operation = potential.get();
        ++i;

        modification = modification.modifyChild(pathArg, operation.getChildPolicy());
    }

    return OperationWithModification.from(operation, modification);
}

From source file:com.android.idegen.StandardModule.java

@Override
public String toString() {
    return Objects.toStringHelper(this).add("super", super.toString()).add("makeFileParser", makeFileParser)
            .add("directDependencies", Iterables.toString(directDependencies)).toString();
}

From source file:eu.numberfour.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager.java

@Override
protected List<WorkingSet> initializeWorkingSets() {
    checkState(projectAssociations.keySet().size() == orderedWorkingSetIds.size(),
            "Expected same number of working set names as project associations." + "\nNames were: "
                    + Iterables.toString(orderedWorkingSetIds) + "\nAssociations were: " + projectAssociations);

    if (projectAssociations.isEmpty()) {
        projectAssociations.put(OTHERS_WORKING_SET_ID, emptyList());
        orderedWorkingSetIds.add(OTHERS_WORKING_SET_ID);
    }/*from  w w  w  .  j a  v a2s  . co m*/

    final int size = projectAssociations.keySet().size();
    final WorkingSet[] workingSets = new WorkingSet[size];
    for (int i = 0; i < size; i++) {
        final String name = orderedWorkingSetIds.get(i);
        final Collection<String> projectNames = projectAssociations.get(name);
        workingSets[i] = new ManualAssociationWorkingSet(projectNames, name, this);
    }

    return Arrays.asList(workingSets);
}

From source file:co.cask.cdap.template.etl.common.RecordPutTransformer.java

@Nullable
private Schema.Field getKeyField(Schema recordSchema) {
    Schema.Field field = recordSchema.getField(rowField);
    if (field == null && !rowFieldCaseSensitive) {
        Iterable<Schema.Field> filtered = Iterables.filter(recordSchema.getFields(),
                new Predicate<Schema.Field>() {
                    @Override/*from  w  ww  .  ja v  a2  s. c o  m*/
                    public boolean apply(Schema.Field input) {
                        return input.getName().equalsIgnoreCase(rowField);
                    }
                });
        if (!Iterables.isEmpty(filtered)) {
            Preconditions.checkArgument(Iterables.size(filtered) == 1,
                    "Cannot have multiple fields in the schema that match %s in a case-insensitive "
                            + "manner when the property %s is false. Found %s.",
                    rowField, Properties.Table.CASE_SENSITIVE_ROW_FIELD, Iterables.toString(filtered));
            field = filtered.iterator().next();
            rowField = field.getName();
        }
    }
    return field;
}

From source file:minium.web.internal.WebModules.java

public static WebModule combine(final Iterable<? extends WebModule> modules) {
    return new WebModule() {
        @Override/*from w  w w. j a  va2  s  . co m*/
        public void configure(Builder<?> builder) {
            for (WebModule module : modules) {
                module.configure(builder);
            }
        }

        @Override
        public String toString() {
            return format("WebModule%s", Iterables.toString(modules));
        }
    };
}

From source file:org.apache.jackrabbit.oak.plugins.nodetype.TypePredicate.java

@Override
public String toString() {
    return Iterables.toString(names);
}

From source file:com.android.build.gradle.internal.transforms.DexTransform.java

@NonNull
@Override//w w  w.  j ava  2 s . c o  m
public Map<String, Object> getParameterInputs() {
    try {
        // ATTENTION: if you add something here, consider adding the value to DexKey - it needs
        // to be saved if affects how dx is invoked.

        Map<String, Object> params = Maps.newHashMapWithExpectedSize(4);

        params.put("optimize", getOptimize());
        params.put("predex", dexOptions.getPreDexLibraries());
        params.put("jumbo", dexOptions.getJumboMode());
        params.put("multidex", multiDex);
        params.put("multidex-legacy", multiDex && mainDexListFile != null);
        params.put("java-max-heap-size", dexOptions.getJavaMaxHeapSize());
        params.put("additional-parameters", Iterables.toString(dexOptions.getAdditionalParameters()));

        TargetInfo targetInfo = androidBuilder.getTargetInfo();
        Preconditions.checkState(targetInfo != null, "androidBuilder.targetInfo required for task '%s'.",
                getName());
        BuildToolInfo buildTools = targetInfo.getBuildTools();
        params.put("build-tools", buildTools.getRevision().toString());

        return params;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.sosy_lab.cpachecker.cfa.postprocessing.global.singleloop.AcyclicGraph.java

@Override
public String toString() {
    return Iterables.toString(getEdges());
}

From source file:com.google.devtools.build.lib.bazel.rules.android.AndroidSdkRepositoryFunction.java

@Override
public RepositoryDirectoryValue.Builder fetch(Rule rule, Path outputDirectory, BlazeDirectories directories,
        Environment env, Map<String, String> markerData) throws SkyFunctionException, InterruptedException {

    prepareLocalRepositorySymlinkTree(rule, outputDirectory);
    WorkspaceAttributeMapper attributes = WorkspaceAttributeMapper.of(rule);
    FileSystem fs = directories.getOutputBase().getFileSystem();
    Path androidSdkPath;/*from  w ww.  j  a  v a2  s.  c o m*/
    if (attributes.isAttributeValueExplicitlySpecified("path")) {
        androidSdkPath = fs.getPath(getTargetPath(rule, directories.getWorkspace()));
    } else if (clientEnvironment.containsKey(PATH_ENV_VAR)) {
        androidSdkPath = fs
                .getPath(getAndroidHomeEnvironmentVar(directories.getWorkspace(), clientEnvironment));
    } else {
        throw new RepositoryFunctionException(new EvalException(rule.getLocation(),
                "Either the path attribute of android_sdk_repository or the ANDROID_HOME environment "
                        + " variable must be set."),
                Transience.PERSISTENT);
    }

    if (!symlinkLocalRepositoryContents(outputDirectory, androidSdkPath)) {
        return null;
    }

    DirectoryListingValue platformsDirectoryValue = getDirectoryListing(fs,
            androidSdkPath.getChild(PLATFORMS_DIR_NAME), env);
    if (platformsDirectoryValue == null) {
        return null;
    }

    ImmutableSortedSet<Integer> apiLevels = getApiLevels(platformsDirectoryValue.getDirents());
    if (apiLevels.isEmpty()) {
        throw new RepositoryFunctionException(new EvalException(rule.getLocation(),
                "android_sdk_repository requires that at least one Android SDK Platform is installed "
                        + "in the Android SDK. Please install an Android SDK Platform through the "
                        + "Android SDK manager."),
                Transience.PERSISTENT);
    }

    String defaultApiLevel;
    if (attributes.isAttributeValueExplicitlySpecified("api_level")) {
        try {
            defaultApiLevel = attributes.get("api_level", Type.INTEGER).toString();
        } catch (EvalException e) {
            throw new RepositoryFunctionException(e, Transience.PERSISTENT);
        }
    } else {
        // If the api_level attribute is not explicitly set, we select the highest api level that is
        // available in the SDK.
        defaultApiLevel = String.valueOf(apiLevels.first());
    }

    String buildToolsDirectory;
    if (attributes.isAttributeValueExplicitlySpecified("build_tools_version")) {
        try {
            buildToolsDirectory = attributes.get("build_tools_version", Type.STRING);
        } catch (EvalException e) {
            throw new RepositoryFunctionException(e, Transience.PERSISTENT);
        }
    } else {
        // If the build_tools_version attribute is not explicitly set, we select the highest version
        // installed in the SDK.
        DirectoryListingValue directoryValue = getDirectoryListing(fs,
                androidSdkPath.getChild(BUILD_TOOLS_DIR_NAME), env);
        if (directoryValue == null) {
            return null;
        }
        buildToolsDirectory = getNewestBuildToolsDirectory(rule, directoryValue.getDirents());
    }

    // android_sdk_repository.build_tools_version is technically actually the name of the
    // directory in $sdk/build-tools. Most of the time this is just the actual build tools
    // version, but for preview build tools, the directory is something like 24.0.0-preview, and
    // the actual version is something like "24 rc3". The android_sdk rule in the template needs
    // the real version.
    String buildToolsVersion;
    if (buildToolsDirectory.contains("-preview")) {

        Properties sourceProperties = getBuildToolsSourceProperties(outputDirectory, buildToolsDirectory, env);
        if (env.valuesMissing()) {
            return null;
        }

        buildToolsVersion = sourceProperties.getProperty("Pkg.Revision");

    } else {
        buildToolsVersion = buildToolsDirectory;
    }

    try {
        assertValidBuildToolsVersion(rule, buildToolsVersion);
    } catch (EvalException e) {
        throw new RepositoryFunctionException(e, Transience.PERSISTENT);
    }

    String template = getStringResource("android_sdk_repository_template.txt");

    String buildFile = template.replace("%repository_name%", rule.getName())
            .replace("%build_tools_version%", buildToolsVersion)
            .replace("%build_tools_directory%", buildToolsDirectory)
            .replace("%api_levels%", Iterables.toString(apiLevels))
            .replace("%default_api_level%", defaultApiLevel);

    // All local maven repositories that are shipped in the Android SDK.
    // TODO(ajmichael): Create SkyKeys so that if the SDK changes, this function will get rerun.
    Iterable<Path> localMavenRepositories = ImmutableList.of(
            outputDirectory.getRelative("extras/android/m2repository"),
            outputDirectory.getRelative("extras/google/m2repository"));
    try {
        SdkMavenRepository sdkExtrasRepository = SdkMavenRepository
                .create(Iterables.filter(localMavenRepositories, new Predicate<Path>() {
                    @Override
                    public boolean apply(@Nullable Path path) {
                        return path.isDirectory();
                    }
                }));
        sdkExtrasRepository.writeBuildFiles(outputDirectory);
        buildFile = buildFile.replace("%exported_files%", sdkExtrasRepository.getExportsFiles(outputDirectory));
    } catch (IOException e) {
        throw new RepositoryFunctionException(e, Transience.TRANSIENT);
    }

    writeBuildFile(outputDirectory, buildFile);
    return RepositoryDirectoryValue.builder().setPath(outputDirectory);
}