Example usage for com.google.common.collect ImmutableList isEmpty

List of usage examples for com.google.common.collect ImmutableList isEmpty

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableList isEmpty.

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this list contains no elements.

Usage

From source file:com.google.javascript.jscomp.FunctionTypeBuilder.java

/**
 * Infer the template type from the doc info.
 *//*www.  ja  v a2s.  com*/
FunctionTypeBuilder inferTemplateTypeName(@Nullable JSDocInfo info, JSType ownerType) {
    // NOTE: these template type names may override a list
    // of inherited ones from an overridden function.
    if (info != null) {
        ImmutableList.Builder<TemplateType> builder = ImmutableList.builder();
        ImmutableList<String> infoTemplateTypeNames = info.getTemplateTypeNames();
        ImmutableMap<String, Node> infoTypeTransformations = info.getTypeTransformations();
        if (!infoTemplateTypeNames.isEmpty()) {
            for (String key : infoTemplateTypeNames) {
                if (typeRegistry.isIObjectValueKey(fnName, key)) {
                    builder.add(typeRegistry.getIObjectValueKey());
                } else {
                    builder.add(typeRegistry.createTemplateType(key));
                }
            }
        }
        if (!infoTypeTransformations.isEmpty()) {
            for (Entry<String, Node> entry : infoTypeTransformations.entrySet()) {
                builder.add(
                        typeRegistry.createTemplateTypeWithTransformation(entry.getKey(), entry.getValue()));
            }
        }
        if (!infoTemplateTypeNames.isEmpty() || !infoTypeTransformations.isEmpty()) {
            templateTypeNames = builder.build();
        }
    }

    ImmutableList<TemplateType> keys = templateTypeNames;
    if (ownerType != null) {
        ImmutableList<TemplateType> ownerTypeKeys = ownerType.getTemplateTypeMap().getTemplateKeys();
        if (!ownerTypeKeys.isEmpty()) {
            ImmutableList.Builder<TemplateType> builder = ImmutableList.builder();
            builder.addAll(templateTypeNames);
            builder.addAll(ownerTypeKeys);
            keys = builder.build();
        }
    }

    if (!keys.isEmpty()) {
        typeRegistry.setTemplateTypeNames(keys);
    }
    return this;
}

From source file:com.spectralogic.dsbrowser.gui.components.ds3panel.ds3treetable.Ds3TreeTablePresenter.java

/**
 * To handle the drop event on treeTableView
 *
 * @param event event/*from   w  w  w  . java2  s. c o m*/
 * @param row   row
 */
private void handleDropEvent(final DragEvent event, final TreeTableRow<Ds3TreeTableValue> row) {
    try {
        LOG.info("Got drop event");
        final TreeItem<Ds3TreeTableValue> selectedItem = getSelectedItem(row);
        if (null != selectedItem) {
            if (!selectedItem.isLeaf() && !selectedItem.isExpanded()) {
                LOG.info("Expanding closed row");
                selectedItem.setExpanded(true);
            }
        }
        if (null != selectedItem && null != selectedItem.getValue() && !selectedItem.getValue().isSearchOn()) {
            final Dragboard db = event.getDragboard();
            LOG.info("Drop event contains files");
            final Ds3TreeTableValue value = selectedItem.getValue();
            final String bucket = value.getBucketName();
            final String targetDir = value.getDirectoryName();
            LOG.info("Passing new Ds3PutJob to jobWorkers thread pool to be scheduled");
            final ImmutableList<Pair<String, Path>> pairs = ((List<Pair<String, String>>) db
                    .getContent(DataFormat.lookupMimeType("local")))
                            .stream()
                            .map(pairStrings -> new Pair<>(pairStrings.getKey(),
                                    Paths.get(pairStrings.getValue())))
                            .collect(GuavaCollectors.immutableList());
            if (pairs.isEmpty()) {
                LOG.info("Drag contained no files");
                Ds3PanelService.refresh(selectedItem);
                return;
            }
            startPutJob(session.getClient(), pairs, bucket, targetDir, selectedItem);
        } else {
            alert.warning("operationNotAllowedHere");
        }
        event.consume();
    } catch (final Throwable t) {
        loggingService.logMessage("Could not handle drag event", LogType.ERROR);
        LOG.error("Drag Event callback failed", t);
    }
}

From source file:com.squareup.wire.schema.internal.parser.ProtoParser.java

/** Reads a reserved tags and names list like "reserved 10, 12 to 14, 'foo';". */
private ReservedElement readReserved(Location location, String documentation) {
    ImmutableList.Builder<Object> valuesBuilder = ImmutableList.builder();

    while (true) {
        char c = peekChar();
        if (c == '"' || c == '\'') {
            valuesBuilder.add(readQuotedString());
        } else {/*  w w w.  j  a  v  a 2 s. co m*/
            int tagStart = readInt();

            c = peekChar();
            if (c != ',' && c != ';') {
                if (!readWord().equals("to")) {
                    throw unexpected("expected ',', ';', or 'to'");
                }
                int tagEnd = readInt();
                valuesBuilder.add(Range.closed(tagStart, tagEnd));
            } else {
                valuesBuilder.add(tagStart);
            }
        }
        c = readChar();
        if (c == ';')
            break;
        if (c != ',')
            throw unexpected("expected ',' or ';'");
    }

    ImmutableList<Object> values = valuesBuilder.build();
    if (values.isEmpty()) {
        throw unexpected("'reserved' must have at least one field name or tag");
    }
    return ReservedElement.create(location, documentation, values);
}

From source file:com.google.javascript.jscomp.newtypes.JSTypeCreatorFromJSDoc.java

private DeclaredFunctionType getFunTypeFromTypicalFunctionJsdoc(JSDocInfo jsdoc, String functionName,
        Node funNode, RawNominalType constructorType, RawNominalType ownerType, DeclaredTypeRegistry registry,
        FunctionTypeBuilder builder, boolean ignoreJsdoc /* for when the jsdoc is malformed */) {
    Preconditions.checkArgument(!ignoreJsdoc || jsdoc == null);
    Preconditions.checkArgument(!ignoreJsdoc || funNode.isFunction());
    ImmutableList<String> typeParameters = ImmutableList.of();
    Node parent = funNode.getParent();

    // TODO(dimvar): need more @template warnings
    // - warn for multiple @template annotations
    // - warn for @template annotation w/out usage

    if (jsdoc != null) {
        typeParameters = jsdoc.getTemplateTypeNames();
        if (!typeParameters.isEmpty()) {
            if (parent.isSetterDef() || parent.isGetterDef()) {
                ignoreJsdoc = true;//from  w w  w.java 2 s.  co m
                jsdoc = null;
                warn("@template can't be used with getters/setters", funNode);
            } else {
                builder.addTypeParameters(typeParameters);
            }
        }
    }
    if (ownerType != null) {
        ImmutableList.Builder<String> paramsBuilder = new ImmutableList.Builder<>();
        paramsBuilder.addAll(typeParameters);
        paramsBuilder.addAll(ownerType.getTypeParameters());
        typeParameters = paramsBuilder.build();
    }

    fillInFormalParameterTypes(jsdoc, funNode, typeParameters, registry, builder, ignoreJsdoc);
    fillInReturnType(jsdoc, funNode, parent, typeParameters, registry, builder, ignoreJsdoc);
    if (jsdoc == null) {
        return builder.buildDeclaration();
    }

    // Look at other annotations, eg, @constructor
    NominalType parentClass = getMaybeParentClass(jsdoc, functionName, funNode, typeParameters, registry);
    ImmutableSet<NominalType> implementedIntfs = getImplementedInterfaces(jsdoc, registry, typeParameters);
    if (constructorType == null && (jsdoc.isConstructor() || jsdoc.isInterface())) {
        // Anonymous type, don't register it.
        return builder.buildDeclaration();
    } else if (jsdoc.isConstructor()) {
        handleConstructorAnnotation(functionName, funNode, constructorType, parentClass, implementedIntfs,
                registry, builder);
    } else if (jsdoc.isInterface()) {
        handleInterfaceAnnotation(jsdoc, functionName, funNode, constructorType, implementedIntfs,
                typeParameters, registry, builder);
    } else if (!implementedIntfs.isEmpty()) {
        warnings.add(JSError.make(funNode, IMPLEMENTS_WITHOUT_CONSTRUCTOR, functionName));
    }

    if (jsdoc.hasThisType() && ownerType == null) {
        Node thisRoot = jsdoc.getThisType().getRoot();
        Preconditions.checkState(thisRoot.getType() == Token.BANG);
        Node thisNode = thisRoot.getFirstChild();
        // JsDocInfoParser wraps @this types with !. But we warn when we see !T,
        // and we don't want to warn for a ! that was automatically inserted.
        // So, we bypass the ! here.
        JSType thisType = getMaybeTypeFromComment(thisNode, registry, typeParameters);
        if (thisType != null) {
            thisType = thisType.removeType(JSType.NULL);
        }
        // TODO(dimvar): thisType may be non-null but have a null
        // thisTypeAsNominal.
        // We currently only support nominal types for the receiver type, but
        // people use other types as well: unions, records, etc.
        // For now, we just use the generic Object for these.
        NominalType nt = thisType == null ? null : thisType.getNominalTypeIfSingletonObj();
        NominalType builtinObject = registry.getCommonTypes().getObjectType();
        builder.addReceiverType(nt == null ? builtinObject : nt);
    }

    return builder.buildDeclaration();
}

From source file:com.facebook.buck.java.intellij.Project.java

private boolean addSourceFolders(SerializableModule module, @Nullable BuildRule buildRule,
        @Nullable ImmutableList<SourceRoot> sourceRoots, boolean isTestSource) {
    if (buildRule == null || sourceRoots == null) {
        return false;
    }//from  w w  w .ja  v  a2s  .  c o  m

    if (buildRule.getProperties().is(PACKAGING) && sourceRoots.isEmpty()) {
        return false;
    }

    if (sourceRoots.isEmpty()) {
        // When there is a src_target, but no src_roots were specified, then the current directory is
        // treated as the SourceRoot. This is the common case when a project contains one folder of
        // Java source code with a build file for each Java package. For example, if the project's
        // only source folder were named "java/" and a build file in java/com/example/base/ contained
        // the an extremely simple set of build rules:
        //
        // java_library(
        //   name = 'base',
        //   srcs = glob(['*.java']),
        // }
        //
        // project_config(
        //   src_target = ':base',
        // )
        //
        // then the corresponding .iml file (in the same directory) should contain:
        //
        // <content url="file://$MODULE_DIR$">
        //   <sourceFolder url="file://$MODULE_DIR$"
        //                 isTestSource="false"
        //                 packagePrefix="com.example.base" />
        //   <sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" />
        //
        //   <!-- It will have an <excludeFolder> for every "subpackage" of com.example.base. -->
        //   <excludeFolder url="file://$MODULE_DIR$/util" />
        // </content>
        //
        // Note to prevent the <excludeFolder> elements from being included, the project_config()
        // rule should be:
        //
        // project_config(
        //   src_target = ':base',
        //   src_root_includes_subdirectories = True,
        // )
        //
        // Because developers who organize their code this way will have many build files, the default
        // values of project_config() assume this approach to help minimize the tedium in writing all
        // of those project_config() rules.
        String url = "file://$MODULE_DIR$";
        String packagePrefix = javaPackageFinder
                .findJavaPackage(Preconditions.checkNotNull(module.pathToImlFile));
        SerializableModule.SourceFolder sourceFolder = new SerializableModule.SourceFolder(url, isTestSource,
                packagePrefix);
        module.sourceFolders.add(sourceFolder);
    } else {
        for (SourceRoot sourceRoot : sourceRoots) {
            SerializableModule.SourceFolder sourceFolder = new SerializableModule.SourceFolder(
                    String.format("file://$MODULE_DIR$/%s", sourceRoot.getName()), isTestSource);
            module.sourceFolders.add(sourceFolder);
        }
    }

    // Include <excludeFolder> elements, as appropriate.
    for (Path relativePath : this.buildFileTree.getChildPaths(buildRule.getBuildTarget())) {
        String excludeFolderUrl = "file://$MODULE_DIR$/" + relativePath;
        SerializableModule.SourceFolder excludeFolder = new SerializableModule.SourceFolder(excludeFolderUrl,
                /* isTestSource */ false);
        module.excludeFolders.add(excludeFolder);
    }

    return true;
}

From source file:org.elasticsearch.repositories.blobstore.BlobStoreRepository.java

/**
 * {@inheritDoc}//www  . j a  v  a2  s .c om
 */
@Override
public Snapshot finalizeSnapshot(SnapshotId snapshotId, String failure, int totalShards,
        ImmutableList<SnapshotShardFailure> shardFailures) {
    BlobStoreSnapshot snapshot = (BlobStoreSnapshot) readSnapshot(snapshotId);
    if (snapshot == null) {
        throw new SnapshotMissingException(snapshotId);
    }
    if (snapshot.state().completed()) {
        throw new SnapshotException(snapshotId, "snapshot is already closed");
    }
    try {
        String blobName = snapshotBlobName(snapshotId);
        BlobStoreSnapshot.Builder updatedSnapshot = BlobStoreSnapshot.builder().snapshot(snapshot);
        if (failure == null) {
            if (shardFailures.isEmpty()) {
                updatedSnapshot.success();
            } else {
                updatedSnapshot.partial();
            }
            updatedSnapshot.failures(totalShards, shardFailures);
        } else {
            updatedSnapshot.failed(failure);
        }
        updatedSnapshot.endTime(System.currentTimeMillis());
        snapshot = updatedSnapshot.build();
        BytesStreamOutput bStream = writeSnapshot(snapshot);
        BytesReference bRef = bStream.bytes();
        snapshotsBlobContainer.writeBlob(blobName, bRef.streamInput(), bRef.length());
        ImmutableList<SnapshotId> snapshotIds = snapshots();
        if (!snapshotIds.contains(snapshotId)) {
            snapshotIds = ImmutableList.<SnapshotId>builder().addAll(snapshotIds).add(snapshotId).build();
        }
        writeSnapshotList(snapshotIds);
        return snapshot;
    } catch (IOException ex) {
        throw new RepositoryException(this.repositoryName, "failed to update snapshot in repository", ex);
    }
}

From source file:com.facebook.buck.ide.intellij.deprecated.Project.java

private boolean addSourceFolders(SerializableModule module, @Nullable BuildRule buildRule,
        @Nullable ImmutableList<SourceRoot> sourceRoots, boolean isTestSource) {
    if (buildRule == null || sourceRoots == null) {
        return false;
    }/*from ww w  . j  a  v a  2s.  c  om*/

    if (buildRule.getProperties().is(PACKAGING) && sourceRoots.isEmpty()) {
        return false;
    }

    JavaLibrary javaLibrary;
    if (buildRule instanceof JavaLibrary) {
        javaLibrary = (JavaLibrary) buildRule;
        Path basePath = buildRule.getBuildTarget().getBasePath();
        for (SourcePath path : javaLibrary.getSources()) {
            if (!(path instanceof PathSourcePath)) {
                Path pathToTarget = resolver.getRelativePath(path);
                Path relativePath = basePath.relativize(Paths.get("")).resolve(pathToTarget).getParent();
                String url = "file://$MODULE_DIR$/" + MorePaths.pathWithUnixSeparators(relativePath);
                SerializableModule.SourceFolder sourceFolder = new SerializableModule.SourceFolder(url,
                        isTestSource, "");
                module.sourceFolders.add(sourceFolder);
            }
        }
    }

    if (sourceRoots.isEmpty()) {
        // When there is a src_target, but no src_roots were specified, then the current directory is
        // treated as the SourceRoot. This is the common case when a project contains one folder of
        // Java source code with a build file for each Java package. For example, if the project's
        // only source folder were named "java/" and a build file in java/com/example/base/ contained
        // the an extremely simple set of build rules:
        //
        // java_library(
        //   name = 'base',
        //   srcs = glob(['*.java']),
        // }
        //
        // project_config(
        //   src_target = ':base',
        // )
        //
        // then the corresponding .iml file (in the same directory) should contain:
        //
        // <content url="file://$MODULE_DIR$">
        //   <sourceFolder url="file://$MODULE_DIR$"
        //                 isTestSource="false"
        //                 packagePrefix="com.example.base" />
        //   <sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" />
        //
        //   <!-- It will have an <excludeFolder> for every "subpackage" of com.example.base. -->
        //   <excludeFolder url="file://$MODULE_DIR$/util" />
        // </content>
        //
        // Note to prevent the <excludeFolder> elements from being included, the project_config()
        // rule should be:
        //
        // project_config(
        //   src_target = ':base',
        //   src_root_includes_subdirectories = True,
        // )
        //
        // Because developers who organize their code this way will have many build files, the default
        // values of project_config() assume this approach to help minimize the tedium in writing all
        // of those project_config() rules.
        String url = "file://$MODULE_DIR$";
        String packagePrefix = javaPackageFinder
                .findJavaPackage(Preconditions.checkNotNull(module.pathToImlFile));
        SerializableModule.SourceFolder sourceFolder = new SerializableModule.SourceFolder(url, isTestSource,
                packagePrefix);
        module.sourceFolders.add(sourceFolder);
    } else {
        for (SourceRoot sourceRoot : sourceRoots) {
            SerializableModule.SourceFolder sourceFolder = new SerializableModule.SourceFolder(
                    "file://$MODULE_DIR$/" + sourceRoot.getName(), isTestSource);
            module.sourceFolders.add(sourceFolder);
        }
    }

    // Include <excludeFolder> elements, as appropriate.
    for (Path relativePath : this.buildFileTree.getChildPaths(buildRule.getBuildTarget())) {
        String excludeFolderUrl = "file://$MODULE_DIR$/" + relativePath;
        SerializableModule.SourceFolder excludeFolder = new SerializableModule.SourceFolder(excludeFolderUrl,
                /* isTestSource */ false);
        module.excludeFolders.add(excludeFolder);
    }

    return true;
}

From source file:com.facebook.buck.command.Project.java

private boolean addSourceFolders(Module module, @Nullable BuildRule buildRule,
        @Nullable ImmutableList<SourceRoot> sourceRoots, boolean isTestSource) {
    if (buildRule == null || sourceRoots == null) {
        return false;
    }/* www.  j a v a 2s  . c  om*/

    if (buildRule.getProperties().is(PACKAGING) && sourceRoots.isEmpty()) {
        return false;
    }

    if (sourceRoots.isEmpty()) {
        // When there is a src_target, but no src_roots were specified, then the current directory is
        // treated as the SourceRoot. This is the common case when a project contains one folder of
        // Java source code with a build file for each Java package. For example, if the project's
        // only source folder were named "java/" and a build file in java/com/example/base/ contained
        // the an extremely simple set of build rules:
        //
        // java_library(
        //   name = 'base',
        //   srcs = glob(['*.java']),
        // }
        //
        // project_config(
        //   src_target = ':base',
        // )
        //
        // then the corresponding .iml file (in the same directory) should contain:
        //
        // <content url="file://$MODULE_DIR$">
        //   <sourceFolder url="file://$MODULE_DIR$"
        //                 isTestSource="false"
        //                 packagePrefix="com.example.base" />
        //   <sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" />
        //
        //   <!-- It will have an <excludeFolder> for every "subpackage" of com.example.base. -->
        //   <excludeFolder url="file://$MODULE_DIR$/util" />
        // </content>
        //
        // Note to prevent the <excludeFolder> elements from being included, the project_config()
        // rule should be:
        //
        // project_config(
        //   src_target = ':base',
        //   src_root_includes_subdirectories = True,
        // )
        //
        // Because developers who organize their code this way will have many build files, the default
        // values of project_config() assume this approach to help minimize the tedium in writing all
        // of those project_config() rules.
        String url = "file://$MODULE_DIR$";
        String packagePrefix = javaPackageFinder.findJavaPackageForPath(module.pathToImlFile);
        SourceFolder sourceFolder = new SourceFolder(url, isTestSource, packagePrefix);
        module.sourceFolders.add(sourceFolder);
    } else {
        for (SourceRoot sourceRoot : sourceRoots) {
            SourceFolder sourceFolder = new SourceFolder(
                    String.format("file://$MODULE_DIR$/%s", sourceRoot.getName()), isTestSource);
            module.sourceFolders.add(sourceFolder);
        }
    }

    // Include <excludeFolder> elements, as appropriate.
    for (String relativePath : this.buildFileTree.getChildPaths(buildRule.getBuildTarget())) {
        String excludeFolderUrl = "file://$MODULE_DIR$/" + relativePath;
        SourceFolder excludeFolder = new SourceFolder(excludeFolderUrl, /* isTestSource */ false);
        module.excludeFolders.add(excludeFolder);
    }

    return true;
}

From source file:com.android.tools.idea.editors.theme.ThemesListModel.java

/**
 * Updates the themes list reloading all the themes from the resolver
 */// www  . jav  a  2 s.  c o  m
private void updateThemes() {
    // We sort the themes, displaying the local project themes at the top sorted alphabetically. The non local themes are sorted
    // alphabetically right below the project themes.
    ImmutableList<String> editableThemes = ThemeEditorUtils
            .getModuleThemeQualifiedNamesList(myContext.getCurrentContextModule());

    ImmutableList.Builder<String> availableThemesListBuilder = ImmutableList.builder();
    ImmutableList.Builder<String> disabledThemesListBuilder = ImmutableList.builder();
    ThemeResolver themeResolver = myContext.getThemeResolver();

    for (String themeName : editableThemes) {
        if (themeResolver.getTheme(themeName) != null) {
            availableThemesListBuilder.add(themeName);
        } else {
            disabledThemesListBuilder.add(themeName);
        }
    }

    myAvailableProjectThemes = availableThemesListBuilder.build();
    ImmutableList<String> disabledProjectThemes = disabledThemesListBuilder.build();

    String selectedItem = getSelectedItem();
    if (selectedItem == null) {
        if (myDefaultThemeName != null && (editableThemes.contains(myDefaultThemeName)
                || themeResolver.getTheme(myDefaultThemeName) != null)) {
            selectedItem = myDefaultThemeName;
        } else if (!editableThemes.isEmpty()) {
            selectedItem = editableThemes.get(0);
        } else if (!myDefaultThemeNames.isEmpty()) {
            selectedItem = myDefaultThemeNames.get(0);
        }
    }

    myEditOptions.clear();
    buildEditOptionsList(selectedItem);

    myAllItems = new SeparatedList(mySeparator, group(myAvailableProjectThemes), group(disabledProjectThemes),
            group(myDefaultThemeNames, SHOW_ALL_THEMES), group(myEditOptions));

    // Set the default selection to the first element.
    setSelectedItem(selectedItem);
}

From source file:omakase.syntax.Parser.java

private FormalParameterListTree parseParameterListDeclaration(boolean typesRequired) {
    Token start = peek();//w w  w .ja  va 2 s . c  om
    ImmutableList.Builder<ParameterDeclarationTree> result = new ImmutableList.Builder<ParameterDeclarationTree>();
    eat(TokenKind.OPEN_PAREN);
    if (peekParameter()) {
        result.add(parseParameter());
        while (eatOpt(TokenKind.COMMA)) {
            result.add(parseParameter());
        }
    }
    eat(TokenKind.CLOSE_PAREN);
    ImmutableList<ParameterDeclarationTree> parameters = result.build();
    if (!parameters.isEmpty()) {
        // Types are either all specified or none.
        if (typesRequired || parameters.get(0).asParameterDeclaration().type != null) {
            for (ParameterDeclarationTree parameter : parameters) {
                if (parameter.type == null) {
                    reportError(parameter.name, "Parameter type required");
                }
            }
        } else {
            for (ParameterDeclarationTree parameter : parameters) {
                if (parameter.type != null) {
                    reportError(parameter.type.start(), "Parameter type unexpected.");
                }
            }
        }
    }

    return new FormalParameterListTree(getRange(start), parameters);
}