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.facebook.buck.versions.AbstractFlavorSearchTargetNodeFinder.java

public Optional<TargetNode<?>> get(BuildTarget target) {

    // If this node is in the graph under the given name, return it.
    TargetNode<?> node = getBuildTargetIndex().get(target);
    if (node != null) {
        return Optional.of(node);
    }//from w  w  w  . j  a v a 2  s.c o  m

    ImmutableSet<ImmutableSet<Flavor>> flavorList = getBaseTargetFlavorMap()
            .get(target.getUnflavoredBuildTarget());
    if (flavorList == null) {
        return Optional.empty();
    }

    // Otherwise, see if this node exists in the graph with a "less" flavored name.  We initially
    // select all targets which contain a subset of the original flavors, which should be sorted by
    // from largest flavor set to smallest.  We then use the first match, and verify the subsequent
    // matches are subsets.
    ImmutableList<ImmutableSet<Flavor>> matches = RichStream.from(flavorList)
            .filter(target.getFlavors()::containsAll).toImmutableList();
    if (!matches.isEmpty()) {
        ImmutableSet<Flavor> firstMatch = matches.get(0);
        for (ImmutableSet<Flavor> subsequentMatch : matches.subList(1, matches.size())) {
            Preconditions
                    .checkState(firstMatch.size() > subsequentMatch.size(),
                            "Expected to find larger flavor lists earlier in the flavor map "
                                    + "index (sizeof(%s) <= sizeof(%s))",
                            firstMatch.size(), subsequentMatch.size());
            Preconditions.checkState(firstMatch.containsAll(subsequentMatch),
                    "Found multiple disjoint flavor matches for %s: %s and %s (from %s)", target, firstMatch,
                    subsequentMatch, matches);
        }
        return Optional.of(Preconditions.checkNotNull(getBaseTargetIndex().get(target.withFlavors(firstMatch)),
                "%s missing in index", target.withFlavors(firstMatch)));
    }

    // Otherwise, return `null` to indicate this node isn't in the target graph.
    return Optional.empty();
}

From source file:com.google.devtools.build.lib.bazel.repository.MavenServerFunction.java

private Map<String, FileValue> getDefaultSettingsFile(BlazeDirectories directories, Environment env)
        throws InterruptedException {
    // The system settings file is at $M2_HOME/conf/settings.xml.
    String m2Home = System.getenv("M2_HOME");
    ImmutableList.Builder<SkyKey> settingsFilesBuilder = ImmutableList.builder();
    SkyKey systemKey = null;//from w w  w.j  av  a 2 s. com
    if (m2Home != null) {
        PathFragment mavenInstallSettings = new PathFragment(m2Home).getRelative("conf/settings.xml");
        systemKey = FileValue.key(RootedPath.toRootedPath(
                directories.getWorkspace().getRelative(mavenInstallSettings), PathFragment.EMPTY_FRAGMENT));
        settingsFilesBuilder.add(systemKey);
    }

    // The user settings file is at $HOME/.m2/settings.xml.
    String userHome = System.getenv("HOME");
    SkyKey userKey = null;
    if (userHome != null) {
        PathFragment userSettings = new PathFragment(userHome).getRelative(".m2/settings.xml");
        userKey = FileValue.key(RootedPath.toRootedPath(directories.getWorkspace().getRelative(userSettings),
                PathFragment.EMPTY_FRAGMENT));
        settingsFilesBuilder.add(userKey);
    }

    ImmutableList<SkyKey> settingsFiles = settingsFilesBuilder.build();
    if (settingsFiles.isEmpty()) {
        return ImmutableMap.of();
    }
    Map<SkyKey, SkyValue> values = env.getValues(settingsFiles);
    ImmutableMap.Builder<String, FileValue> settingsBuilder = ImmutableMap.builder();
    for (Map.Entry<SkyKey, SkyValue> entry : values.entrySet()) {
        if (entry.getValue() == null) {
            return null;
        }
        if (systemKey != null && systemKey.equals(entry.getKey())) {
            settingsBuilder.put(SYSTEM_KEY, (FileValue) entry.getValue());
        } else if (userKey != null && userKey.equals(entry.getKey())) {
            settingsBuilder.put(USER_KEY, (FileValue) entry.getValue());
        }
    }
    return settingsBuilder.build();
}

From source file:com.android.ide.common.blame.Message.java

public Message(@NonNull Kind kind, @NonNull String text, @NonNull String rawMessage,
        @NonNull ImmutableList<SourceFilePosition> positions) {
    mKind = kind;/*from w w w  .  j  ava2s  .c o  m*/
    mText = text;
    mRawMessage = rawMessage;

    if (positions.isEmpty()) {
        mSourceFilePositions = ImmutableList.of(SourceFilePosition.UNKNOWN);
    } else {
        mSourceFilePositions = positions;
    }
}

From source file:de.metas.ui.web.handlingunits.process.WEBUI_M_HU_Pick.java

@Override
protected ProcessPreconditionsResolution checkPreconditionsApplicable() {
    if (HUsToPickViewFactory.WINDOW_ID.equals(getWindowId())) {
        return ProcessPreconditionsResolution.rejectWithInternalReason("not needed in HUsToPick view");
    }/*from   w  w  w  .j a  va2 s.  c  o  m*/

    final ImmutableList<HURow> firstRows = streamHURows().limit(2).collect(ImmutableList.toImmutableList());
    if (firstRows.isEmpty()) {
        // NOTE: we decided to hide this action when there is not available,
        // because we want to cover the requirements of https://github.com/metasfresh/metasfresh-webui-api/issues/683,
        // were we need to hide the action for source HU lines... and does not worth the effort to handle particularly that case.
        return ProcessPreconditionsResolution.rejectWithInternalReason("no eligible HU rows found");
        // return ProcessPreconditionsResolution.reject(msgBL.getTranslatableMsgText(WEBUI_M_HU_Messages.MSG_WEBUI_ONLY_TOP_LEVEL_HU));
    }

    if (firstRows.size() != 1) {
        return ProcessPreconditionsResolution.rejectBecauseNotSingleSelection();
    }

    return ProcessPreconditionsResolution.accept();
}

From source file:com.google.errorprone.refaster.BlockTemplate.java

private Choice<List<BlockTemplateMatch>> matchesStartingAtBeginning(final JCBlock block, final int offset,
        final ImmutableList<? extends StatementTree> statements, final Context context) {
    if (statements.isEmpty()) {
        return Choice.none();
    }// w ww  . ja  va2s . c  om
    final JCStatement firstStatement = (JCStatement) statements.get(0);
    Choice<UnifierWithUnconsumedStatements> choice = Choice
            .of(UnifierWithUnconsumedStatements.create(new Unifier(context), statements));
    for (UStatement templateStatement : templateStatements()) {
        choice = choice.thenChoose(templateStatement);
    }
    return choice.thenChoose(new Function<UnifierWithUnconsumedStatements, Choice<List<BlockTemplateMatch>>>() {
        @Override
        public Choice<List<BlockTemplateMatch>> apply(UnifierWithUnconsumedStatements state) {
            Unifier unifier = state.unifier();
            Inliner inliner = unifier.createInliner();
            try {
                Optional<Unifier> checkedUnifier = typecheck(unifier, inliner, new Warner(firstStatement),
                        expectedTypes(inliner), actualTypes(inliner));
                if (checkedUnifier.isPresent()) {
                    int consumedStatements = statements.size() - state.unconsumedStatements().size();
                    BlockTemplateMatch match = new BlockTemplateMatch(block, checkedUnifier.get(), offset,
                            offset + consumedStatements);
                    return matchesStartingAnywhere(block, offset + consumedStatements,
                            statements.subList(consumedStatements, statements.size()), context)
                                    .transform(prepend(match));
                }
            } catch (CouldNotResolveImportException e) {
                // fall through
            }
            return Choice.none();
        }
    });
}

From source file:org.gradle.internal.component.external.model.DefaultConfigurationMetadata.java

private DefaultConfigurationMetadata withConstraints(boolean constraint) {
    ImmutableList<ModuleDependencyMetadata> configDependencies = getConfigDependencies();
    if (configDependencies.isEmpty()) {
        return this;
    }//from   w ww.  j a v  a2  s .  c o  m
    int count = 0;
    ImmutableList.Builder<ModuleDependencyMetadata> filtered = new ImmutableList.Builder<ModuleDependencyMetadata>();
    for (ModuleDependencyMetadata configDependency : configDependencies) {
        if (configDependency.isConstraint() == constraint) {
            filtered.add(configDependency);
            count++;
        }
    }
    if (count == configDependencies.size()) {
        // Avoid creating a copy if the resulting configuration is identical
        return this;
    }
    return new DefaultConfigurationMetadata(getComponentId(), getName(), isTransitive(), isVisible(),
            getHierarchy(), ImmutableList.copyOf(getArtifacts()), componentMetadataRules, getExcludes(),
            componentLevelAttributes, filtered.build());
}

From source file:org.diorite.firework.FireworkEffect.java

FireworkEffect(final boolean flicker, final boolean trail, final ImmutableList<Color> colors,
        final ImmutableList<Color> fadeColors, final FireworkEffectType type) {
    if (colors.isEmpty()) {
        throw new IllegalStateException("Cannot make FireworkEffect without any color");
    }//from   w  w w  .  jav a2  s.  c  om
    this.flicker = flicker;
    this.trail = trail;
    this.colors = colors;
    this.fadeColors = fadeColors;
    this.type = type;
}

From source file:com.android.ide.common.blame.MessageJsonSerializer.java

@Override
public Message read(JsonReader in) throws IOException {
    in.beginObject();/*from www. ja  va2 s. c  om*/
    Message.Kind kind = Message.Kind.UNKNOWN;
    String text = "";
    String rawMessage = null;
    ImmutableList.Builder<SourceFilePosition> positions = new ImmutableList.Builder<SourceFilePosition>();
    SourceFile legacyFile = SourceFile.UNKNOWN;
    SourcePosition legacyPosition = SourcePosition.UNKNOWN;
    while (in.hasNext()) {
        String name = in.nextName();
        if (name.equals(KIND)) {
            //noinspection StringToUpperCaseOrToLowerCaseWithoutLocale
            Message.Kind theKind = KIND_STRING_ENUM_MAP.inverse().get(in.nextString().toLowerCase());
            kind = (theKind != null) ? theKind : Message.Kind.UNKNOWN;
        } else if (name.equals(TEXT)) {
            text = in.nextString();
        } else if (name.equals(RAW_MESSAGE)) {
            rawMessage = in.nextString();
        } else if (name.equals(SOURCE_FILE_POSITIONS)) {
            switch (in.peek()) {
            case BEGIN_ARRAY:
                in.beginArray();
                while (in.hasNext()) {
                    positions.add(mSourceFilePositionTypeAdapter.read(in));
                }
                in.endArray();
                break;
            case BEGIN_OBJECT:
                positions.add(mSourceFilePositionTypeAdapter.read(in));
                break;
            default:
                in.skipValue();
                break;
            }
        } else if (name.equals(LEGACY_SOURCE_PATH)) {
            legacyFile = new SourceFile(new File(in.nextString()));
        } else if (name.equals(LEGACY_POSITION)) {
            legacyPosition = mSourcePositionTypeAdapter.read(in);
        } else {
            in.skipValue();
        }
    }
    in.endObject();

    if (legacyFile != SourceFile.UNKNOWN || legacyPosition != SourcePosition.UNKNOWN) {
        positions.add(new SourceFilePosition(legacyFile, legacyPosition));
    }
    if (rawMessage == null) {
        rawMessage = text;
    }
    ImmutableList<SourceFilePosition> sourceFilePositions = positions.build();
    if (!sourceFilePositions.isEmpty()) {
        return new Message(kind, text, rawMessage, sourceFilePositions);
    } else {
        return new Message(kind, text, rawMessage, ImmutableList.of(SourceFilePosition.UNKNOWN));
    }
}

From source file:org.apache.james.jmap.methods.MIMEMessageConverter.java

private boolean hasAttachment(ImmutableList<MessageAttachment> messageAttachments) {
    return !messageAttachments.isEmpty();
}

From source file:com.android.common.ide.common.blame.MessageJsonSerializer.java

@Override
public Message read(JsonReader in) throws IOException {
    in.beginObject();/*from   w  ww. j  a  va 2  s.co  m*/
    Message.Kind kind = Message.Kind.UNKNOWN;
    String text = "";
    String rawMessage = null;
    Optional<String> toolName = Optional.absent();
    ImmutableList.Builder<SourceFilePosition> positions = new ImmutableList.Builder<SourceFilePosition>();
    SourceFile legacyFile = SourceFile.UNKNOWN;
    SourcePosition legacyPosition = SourcePosition.UNKNOWN;
    while (in.hasNext()) {
        String name = in.nextName();
        if (name.equals(KIND)) {
            //noinspection StringToUpperCaseOrToLowerCaseWithoutLocale
            Message.Kind theKind = KIND_STRING_ENUM_MAP.inverse().get(in.nextString().toLowerCase());
            kind = (theKind != null) ? theKind : Message.Kind.UNKNOWN;
        } else if (name.equals(TEXT)) {
            text = in.nextString();
        } else if (name.equals(RAW_MESSAGE)) {
            rawMessage = in.nextString();
        } else if (name.equals(TOOL_NAME)) {
            toolName = Optional.of(in.nextString());
        } else if (name.equals(SOURCE_FILE_POSITIONS)) {
            switch (in.peek()) {
            case BEGIN_ARRAY:
                in.beginArray();
                while (in.hasNext()) {
                    positions.add(mSourceFilePositionTypeAdapter.read(in));
                }
                in.endArray();
                break;
            case BEGIN_OBJECT:
                positions.add(mSourceFilePositionTypeAdapter.read(in));
                break;
            default:
                in.skipValue();
                break;
            }
        } else if (name.equals(LEGACY_SOURCE_PATH)) {
            legacyFile = new SourceFile(new File(in.nextString()));
        } else if (name.equals(LEGACY_POSITION)) {
            legacyPosition = mSourcePositionTypeAdapter.read(in);
        } else {
            in.skipValue();
        }
    }
    in.endObject();

    if (legacyFile != SourceFile.UNKNOWN || legacyPosition != SourcePosition.UNKNOWN) {
        positions.add(new SourceFilePosition(legacyFile, legacyPosition));
    }
    if (rawMessage == null) {
        rawMessage = text;
    }
    ImmutableList<SourceFilePosition> sourceFilePositions = positions.build();
    if (!sourceFilePositions.isEmpty()) {
        return new Message(kind, text, rawMessage, toolName, sourceFilePositions);
    } else {
        return new Message(kind, text, rawMessage, toolName, ImmutableList.of(SourceFilePosition.UNKNOWN));
    }
}