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

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

Introduction

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

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this set contains no elements.

Usage

From source file:edu.mit.streamjit.impl.compiler2.PeekableBufferConcreteStorage.java

public static StorageFactory factory(final Map<Token, PeekableBuffer> buffers) {
    return (Storage storage) -> {
        assert buffers.containsKey(storage.id()) : storage.id() + " not in " + buffers;
        //Hack: we don't have the throughput when making init storage,
        //but we don't need it either.
        int throughput1;
        try {//from  w w  w .j  ava  2  s  .c o m
            throughput1 = storage.throughput();
        } catch (IllegalStateException ignored) {
            throughput1 = Integer.MIN_VALUE;
        }
        ImmutableSet<ActorGroup> relevantGroups = ImmutableSet.<ActorGroup>builder()
                .addAll(storage.upstreamGroups()).addAll(storage.downstreamGroups()).build();
        ImmutableSortedSet<Integer> readIndices = storage.readIndices(Maps.asMap(relevantGroups, i -> 1));
        int minReadIndex1 = readIndices.isEmpty() ? Integer.MIN_VALUE : readIndices.first();
        return new PeekableBufferConcreteStorage(storage.type(), throughput1, minReadIndex1,
                buffers.get(storage.id()));
    };
}

From source file:com.ibm.common.geojson.BoundingBox.java

private static BoundingBox buildBoundingBox(ImmutableSortedSet<Float> xs, ImmutableSortedSet<Float> ys,
        ImmutableSortedSet<Float> zs) {
    BoundingBox.Builder bbox = new BoundingBox.Builder().add(xs.first()).add(ys.first());
    if (!zs.isEmpty())
        bbox.add(zs.first());//from   ww w  .  j  a  v  a  2s .  c  om
    bbox.add(xs.last());
    bbox.add(ys.last());
    if (!zs.isEmpty())
        bbox.add(zs.last());
    return bbox.get();
}

From source file:com.facebook.buck.apple.AppleDescriptions.java

public static Optional<AppleAssetCatalog> createBuildRuleForTransitiveAssetCatalogDependencies(
        TargetGraph targetGraph, BuildRuleParams params, SourcePathResolver sourcePathResolver,
        ApplePlatform applePlatform, Tool actool) {
    TargetNode<?, ?> targetNode = targetGraph.get(params.getBuildTarget());

    ImmutableSet<AppleAssetCatalogDescription.Arg> assetCatalogArgs = AppleBuildRules
            .collectRecursiveAssetCatalogs(targetGraph, Optional.empty(), ImmutableList.of(targetNode));

    ImmutableSortedSet.Builder<SourcePath> assetCatalogDirsBuilder = ImmutableSortedSet.naturalOrder();

    Optional<String> appIcon = Optional.empty();
    Optional<String> launchImage = Optional.empty();

    AppleAssetCatalogDescription.Optimization optimization = null;

    for (AppleAssetCatalogDescription.Arg arg : assetCatalogArgs) {
        if (optimization == null) {
            optimization = arg.optimization;
        }/*from  ww  w.  j  a v a2  s.  c o m*/

        assetCatalogDirsBuilder.addAll(arg.dirs);
        if (arg.appIcon.isPresent()) {
            if (appIcon.isPresent()) {
                throw new HumanReadableException(
                        "At most one asset catalog in the dependencies of %s " + "can have a app_icon",
                        params.getBuildTarget());
            }

            appIcon = arg.appIcon;
        }

        if (arg.launchImage.isPresent()) {
            if (launchImage.isPresent()) {
                throw new HumanReadableException(
                        "At most one asset catalog in the dependencies of %s " + "can have a launch_image",
                        params.getBuildTarget());
            }

            launchImage = arg.launchImage;
        }

        if (arg.optimization != optimization) {
            throw new HumanReadableException(
                    "At most one asset catalog optimisation style can be " + "specified in the dependencies %s",
                    params.getBuildTarget());
        }
    }

    ImmutableSortedSet<SourcePath> assetCatalogDirs = assetCatalogDirsBuilder.build();

    if (assetCatalogDirs.isEmpty()) {
        return Optional.empty();
    }

    BuildRuleParams assetCatalogParams = params.copyWithChanges(
            params.getBuildTarget().withAppendedFlavors(AppleAssetCatalog.FLAVOR),
            Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of()));

    return Optional.of(new AppleAssetCatalog(assetCatalogParams, sourcePathResolver, applePlatform.getName(),
            actool, assetCatalogDirs, appIcon, launchImage, optimization, MERGED_ASSET_CATALOG_NAME));
}

From source file:com.facebook.buck.apple.AppleBinary.java

@Override
protected ImmutableList<Step> getFinalBuildSteps(ImmutableSortedSet<Path> files, Path outputFile) {
    if (files.isEmpty()) {
        return ImmutableList.of();
    } else {/*  ww w.  j av a 2 s  . c o  m*/
        return ImmutableList.<Step>of(new CompilerStep(/* compiler */ getCompiler(), /* shouldLink */ true,
                /* srcs */ files, /* outputFile */ outputFile, /* shouldAddProjectRootToIncludePaths */ false,
                /* includePaths */ ImmutableSortedSet.<Path>of(),
                /* commandLineArgs */ ImmutableList.<String>of()));
    }
}

From source file:com.facebook.buck.apple.AppleLibrary.java

@Override
protected ImmutableList<Step> getFinalBuildSteps(ImmutableSortedSet<Path> files, Path outputFile) {
    if (files.isEmpty()) {
        return ImmutableList.of();
    } else if (linkedDynamically) {
        // TODO(user): This needs to create a dylib, not a static library.
        return ImmutableList.<Step>of(new CompilerStep(/* compiler */ getCompiler(), /* shouldLink */ true,
                /* srcs */ files, /* outputFile */ outputFile, /* shouldAddProjectRootToIncludePaths */ false,
                /* includePaths */ ImmutableSortedSet.<Path>of(),
                /* commandLineArgs */ ImmutableList.<String>of()));
    } else {//w ww . ja  v a  2s .co  m
        return ImmutableList.<Step>of(
                new ArchiveStep(getResolver().getPath(archiver), outputFile, ImmutableList.copyOf(files)));
    }
}

From source file:com.facebook.buck.core.files.FileTreeTransformer.java

@Override
public ImmutableSet<FileTreeKey> discoverDeps(FileTreeKey key, TransformationEnvironment env) {
    DirectoryList currentDir = env.getDep(ImmutableDirectoryListKey.of(key.getPath()));
    ImmutableSortedSet<Path> subDirs = currentDir.getDirectories();
    if (subDirs.isEmpty()) {
        return ImmutableSet.of();
    }//  w w w . j  a v  a 2 s .co m

    ImmutableSet.Builder<FileTreeKey> depsBuilder = ImmutableSet.builderWithExpectedSize(subDirs.size());

    for (Path path : subDirs) {
        depsBuilder.add(ImmutableFileTreeKey.of(path));
    }

    return depsBuilder.build();
}

From source file:org.cyclop.service.completion.intern.parser.CompletionHelper.java

private Optional<CqlCompletion.Builder> computeTableNameCompletionWithKeyspaceInQuery(CqlQuery query,
        CqlKeyword... kw) {//  w  ww.  ja  va  2s .c o m
    Optional<CqlKeySpace> keySpace = QueryHelper.extractKeyspace(query, kw);
    if (!keySpace.isPresent()) {
        return Optional.empty();
    }
    ImmutableSortedSet<CqlTable> tables = queryService.findTableNames(keySpace);
    if (tables.isEmpty()) {
        return Optional.empty();
    }

    CqlCompletion.Builder builder = CqlCompletion.Builder.naturalOrder();
    builder.all(tables);

    for (CqlTable ta : tables) {
        builder.full(new CqlTable(keySpace.get().part, ta.part));
    }

    return Optional.of(builder);
}

From source file:com.google.devtools.build.lib.rules.config.ConfigFeatureFlagTaggedTrimmingTransitionFactory.java

@Override
public PatchTransition buildTransitionFor(Rule rule) {
    NonconfigurableAttributeMapper attrs = NonconfigurableAttributeMapper.of(rule);
    RuleClass ruleClass = rule.getRuleClassObject();
    if (ruleClass.getName().equals(ConfigRuleClasses.ConfigFeatureFlagRule.RULE_NAME)) {
        return new ConfigFeatureFlagTaggedTrimmingTransition(ImmutableSortedSet.of(rule.getLabel()));
    }/*from   w  w  w. j a  v a 2 s. c om*/

    ImmutableSortedSet.Builder<Label> requiredLabelsBuilder = new ImmutableSortedSet.Builder<>(
            Ordering.natural());
    if (attrs.isAttributeValueExplicitlySpecified(attributeName)
            && !attrs.get(attributeName, NODEP_LABEL_LIST).isEmpty()) {
        requiredLabelsBuilder.addAll(attrs.get(attributeName, NODEP_LABEL_LIST));
    }
    if (ruleClass.getTransitionFactory() instanceof ConfigFeatureFlagTransitionFactory) {
        String settingAttribute = ((ConfigFeatureFlagTransitionFactory) ruleClass.getTransitionFactory())
                .getAttributeName();
        // Because the process of setting a flag also creates a dependency on that flag, we need to
        // include all the set flags, even if they aren't actually declared as used by this rule.
        requiredLabelsBuilder.addAll(attrs.get(settingAttribute, LABEL_KEYED_STRING_DICT).keySet());
    }

    ImmutableSortedSet<Label> requiredLabels = requiredLabelsBuilder.build();
    if (requiredLabels.isEmpty()) {
        return ConfigFeatureFlagTaggedTrimmingTransition.EMPTY;
    }

    return new ConfigFeatureFlagTaggedTrimmingTransition(requiredLabels);
}

From source file:org.quackbot.hooks.core.HelpCommand.java

@JavaCommand(name = "help", minimumLevel = AdminLevels.ADMIN, help = "Provides list of commands or help for specific command", arguments = @JavaArgument(name = "command", argumentHelp = "", required = false))
public String onHelpCommand(CommandEvent event, String command) throws Exception {
    //Does user want command list
    CommandManager commandManager = event.getBot().getController().getCommandManager();
    if (command == null) {
        //Add Java Plugins
        StringBuilder commandsResponse = new StringBuilder();
        for (String curLevel : commandManager.getUserAdminLevels(event.getUser())) {
            ImmutableSortedSet<Command> commandsForLevel = commandManager.getCommandsForAdminLevel(curLevel);
            if (commandsForLevel.isEmpty())
                continue;
            commandsResponse.append(" ").append(curLevel).append(": ");
            JOINER_COMMA.appendTo(commandsResponse,
                    Iterables.transform(commandsForLevel, new Function<Command, String>() {
                        public String apply(Command curCommand) {
                            return curCommand.getName();
                        }/*from w ww .java 2  s. c  o  m*/
                    }));
        }
        //Send to user
        return "Possible commands: " + commandsResponse.toString().trim();
    } else {
        //Command specified, get specific help
        Command requestedCommand = commandManager.getCommand(command);
        if (requestedCommand == null)
            throw new InvalidCMDException(command);
        //else if (!result.isEnabled()) //TODO: Support disabled commands
        //   throw new InvalidCMDException(command, "disabled");
        else if (!commandManager.getUserAdminLevels(event.getUser())
                .contains(requestedCommand.getMinimumAdminLevel()))
            throw new InvalidCMDException(command, "admin only");
        else if (StringUtils.isBlank(requestedCommand.getHelp()))
            return "No help avalible";
        return requestedCommand.getHelp();
    }
}

From source file:com.facebook.buck.ide.intellij.DefaultIjModuleFactory.java

@SuppressWarnings({ "unchecked", "rawtypes" })
private IjModule createModuleUsingSortedTargetNodes(Path moduleBasePath,
        ImmutableSortedSet<TargetNode<?, ?>> targetNodes, Set<Path> excludes) {
    Preconditions.checkArgument(!targetNodes.isEmpty());

    ImmutableSet<BuildTarget> moduleBuildTargets = targetNodes.stream().map(TargetNode::getBuildTarget)
            .collect(MoreCollectors.toImmutableSet());

    ModuleBuildContext context = new ModuleBuildContext(moduleBuildTargets);

    Set<Class<?>> seenTypes = new HashSet<>();
    for (TargetNode<?, ?> targetNode : targetNodes) {
        Class<?> nodeType = targetNode.getDescription().getClass();
        seenTypes.add(nodeType);//from   w w w  .  j  ava 2 s .co  m
        IjModuleRule<?> rule = Preconditions.checkNotNull(typeRegistry.getModuleRuleByTargetNodeType(nodeType));
        rule.apply((TargetNode) targetNode, context);
        context.setModuleType(rule.detectModuleType((TargetNode) targetNode));
    }

    if (seenTypes.size() > 1) {
        LOG.debug("Multiple types at the same path. Path: %s, types: %s", moduleBasePath, seenTypes);
    }

    if (context.isAndroidFacetBuilderPresent()) {
        context.getOrCreateAndroidFacetBuilder().setGeneratedSourcePath(
                IjAndroidHelper.createAndroidGenPath(projectFilesystem, moduleBasePath));
    }

    excludes.stream().map(moduleBasePath::resolve).map(ExcludeFolder::new).forEach(context::addSourceFolder);

    return IjModule.builder().setModuleBasePath(moduleBasePath).setTargets(moduleBuildTargets)
            .addAllFolders(context.getSourceFolders()).putAllDependencies(context.getDependencies())
            .setAndroidFacet(context.getAndroidFacet())
            .addAllExtraClassPathDependencies(context.getExtraClassPathDependencies())
            .addAllGeneratedSourceCodeFolders(context.getGeneratedSourceCodeFolders())
            .setLanguageLevel(context.getJavaLanguageLevel()).setModuleType(context.getModuleType())
            .setMetaInfDirectory(context.getMetaInfDirectory()).build();
}