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

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

Introduction

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

Prototype

public static boolean isEmpty(Iterable<?> iterable) 

Source Link

Document

Determines if the given iterable contains no elements.

Usage

From source file:com.google.devtools.build.lib.analysis.configuredtargets.MergedConfiguredTarget.java

/** Creates an instance based on a configured target and a set of aspects. */
public static ConfiguredTarget of(ConfiguredTarget base, Iterable<ConfiguredAspect> aspects)
        throws DuplicateException {
    if (Iterables.isEmpty(aspects)) {
        // If there are no aspects, don't bother with creating a proxy object
        return base;
    }/* w w  w.j a va 2  s  .  com*/

    // Merge output group providers.
    OutputGroupProvider mergedOutputGroupProvider = OutputGroupProvider
            .merge(getAllOutputGroupProviders(base, aspects));

    // Merge extra-actions provider.
    ExtraActionArtifactsProvider mergedExtraActionProviders = ExtraActionArtifactsProvider
            .merge(getAllProviders(base, aspects, ExtraActionArtifactsProvider.class));

    TransitiveInfoProviderMapBuilder aspectProviders = new TransitiveInfoProviderMapBuilder();
    if (mergedOutputGroupProvider != null) {
        aspectProviders.put(mergedOutputGroupProvider);
    }
    if (mergedExtraActionProviders != null) {
        aspectProviders.add(mergedExtraActionProviders);
    }

    for (ConfiguredAspect aspect : aspects) {
        TransitiveInfoProviderMap providers = aspect.getProviders();
        for (int i = 0; i < providers.getProviderCount(); ++i) {
            Object providerKey = providers.getProviderKeyAt(i);
            if (OutputGroupProvider.SKYLARK_CONSTRUCTOR.getKey().equals(providerKey)
                    || ExtraActionArtifactsProvider.class.equals(providerKey)) {
                continue;
            }

            if (providerKey instanceof Class<?>) {
                @SuppressWarnings("unchecked")
                Class<? extends TransitiveInfoProvider> providerClass = (Class<? extends TransitiveInfoProvider>) providerKey;
                if (base.getProvider(providerClass) != null || aspectProviders.contains(providerClass)) {
                    throw new DuplicateException("Provider " + providerKey + " provided twice");
                }
                aspectProviders.put(providerClass, (TransitiveInfoProvider) providers.getProviderInstanceAt(i));
            } else if (providerKey instanceof String) {
                String legacyId = (String) providerKey;
                if (base.get(legacyId) != null || aspectProviders.contains(legacyId)) {
                    throw new DuplicateException("Provider " + legacyId + " provided twice");
                }
                aspectProviders.put(legacyId, providers.getProviderInstanceAt(i));
            } else if (providerKey instanceof Provider.Key) {
                Provider.Key key = (Key) providerKey;
                if (base.get(key) != null || aspectProviders.contains(key)) {
                    throw new DuplicateException("Provider " + key + " provided twice");
                }
                aspectProviders.put((Info) providers.getProviderInstanceAt(i));
            }
        }
    }
    return new MergedConfiguredTarget(base, aspectProviders.build());
}

From source file:com.atlassian.jira.license.JiraLicenseManagerImpl.java

@Override
public Iterable<LicenseDetails> getLicenses() {
    Iterable<String> licenseStrings = multiLicenseStore.retrieve();

    if (Iterables.isEmpty(licenseStrings))
        return ImmutableList.of(NullLicenseDetails.NULL_LICENSE_DETAILS);

    return Iterables.transform(licenseStrings, new Function<String, LicenseDetails>() {
        public LicenseDetails apply(@Nullable final String s) {
            return getLicense(s);
        }/*w  w w  .j a  va2 s.  c  o  m*/
    });
}

From source file:com.complexible.common.openrdf.model.ExtGraphImpl.java

/**
 * @inheritDoc//from   w ww.ja  v a2s  .  c  o  m
 */
@Override
public boolean contains(final Resource theSubj, final URI thePred, final Value theObj,
        final Resource... theContexts) {
    return !Iterables.isEmpty(Graphs.filter(this, theSubj, thePred, theObj, theContexts));
}

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

public NestedSet<Artifact> buildAsClassPathEntry(RuleContext ruleContext) {
    CustomCommandLine.Builder builder = new CustomCommandLine.Builder();
    // Set the busybox tool.
    builder.add("--tool").add("GENERATE_ROBOLECTRIC_R").add("--");

    NestedSetBuilder<Artifact> inputs = NestedSetBuilder.stableOrder();

    builder.addExecPath("--androidJar", sdk.getAndroidJar());
    inputs.add(sdk.getAndroidJar());/* w  w w .  j a v a  2 s  . c o  m*/

    if (!Iterables.isEmpty(dependencies.getResourceContainers())) {
        builder.addAll("--data", VectorArg.join(RESOURCE_CONTAINER_TO_ARG.listSeparator())
                .each(dependencies.getResourceContainers()).mapped(RESOURCE_CONTAINER_TO_ARG));
    }

    inputs.addTransitive(dependencies.getTransitiveResources())
            .addTransitive(dependencies.getTransitiveAssets())
            .addTransitive(dependencies.getTransitiveManifests())
            .addTransitive(dependencies.getTransitiveRTxt())
            .addTransitive(dependencies.getTransitiveSymbolsBin());

    builder.addExecPath("--classJarOutput", classJarOut);
    SpawnAction.Builder spawnActionBuilder = new SpawnAction.Builder();

    ParamFileInfo.Builder paramFile = ParamFileInfo.builder(ParameterFileType.SHELL_QUOTED);
    // Some flags (e.g. --mainData) may specify lists (or lists of lists) separated by special
    // characters (colon, semicolon, hashmark, ampersand) that don't work on Windows, and quoting
    // semantics are very complicated (more so than in Bash), so let's just always use a parameter
    // file.
    // TODO(laszlocsomor), TODO(corysmith): restructure the Android BusyBux's flags by deprecating
    // list-type and list-of-list-type flags that use such problematic separators in favor of
    // multi-value flags (to remove one level of listing) and by changing all list separators to a
    // platform-safe character (= comma).
    paramFile.setUseAlways(OS.getCurrent() == OS.WINDOWS);

    ruleContext.registerAction(spawnActionBuilder.useDefaultShellEnvironment()
            .addTransitiveInputs(inputs.build()).addOutput(classJarOut)
            .addCommandLine(builder.build(), paramFile.build())
            .setExecutable(ruleContext.getExecutablePrerequisite("$android_resources_busybox", Mode.HOST))
            .setProgressMessage("Generating R classes for %s", ruleContext.getLabel())
            .setMnemonic("GenerateRobolectricRClasses").build(ruleContext));

    return NestedSetBuilder.<Artifact>naiveLinkOrder().add(classJarOut).build();
}

From source file:org.apache.giraph.graph.VertexResolver.java

@Override
public BasicVertex<I, V, E, M> resolve(I vertexId, BasicVertex<I, V, E, M> vertex,
        VertexChanges<I, V, E, M> vertexChanges, Iterable<M> messages) {
    // Default algorithm:
    // 1. If the vertex exists, first prune the edges
    // 2. If vertex removal desired, remove the vertex.
    // 3. If creation of vertex desired, pick first vertex
    // 4. If vertex doesn't exist, but got messages, create
    // 5. If edge addition, add the edges
    if (vertex != null) {
        if (vertexChanges != null) {
            List<I> removedEdgeList = vertexChanges.getRemovedEdgeList();
            for (I removedDestVertex : removedEdgeList) {
                E removeEdge = ((MutableVertex<I, V, E, M>) vertex).removeEdge(removedDestVertex);
                if (removeEdge == null) {
                    LOG.warn("resolve: Failed to remove edge with " + "destination " + removedDestVertex + "on "
                            + vertex + " since it doesn't exist.");
                }//from  ww w.  j a v a  2s. c  o  m
            }
            if (vertexChanges.getRemovedVertexCount() > 0) {
                vertex = null;
            }
        }
    }

    if (vertex == null) {
        if (vertexChanges != null) {
            if (!vertexChanges.getAddedVertexList().isEmpty()) {
                vertex = vertexChanges.getAddedVertexList().get(0);
            }
        }
        if (vertex == null && messages != null && !Iterables.isEmpty(messages)) {
            vertex = instantiateVertex();
            vertex.initialize(vertexId, BspUtils.<V>createVertexValue(getConf()), null, messages);
        }
    } else {
        if ((vertexChanges != null) && (!vertexChanges.getAddedVertexList().isEmpty())) {
            LOG.warn("resolve: Tried to add a vertex with id = " + vertex.getVertexId() + " when one already "
                    + "exists.  Ignoring the add vertex request.");
        }
    }

    if (vertexChanges != null && !vertexChanges.getAddedEdgeList().isEmpty()) {
        MutableVertex<I, V, E, M> mutableVertex = (MutableVertex<I, V, E, M>) vertex;
        for (Edge<I, E> edge : vertexChanges.getAddedEdgeList()) {
            edge.setConf(getConf());
            mutableVertex.addEdge(edge.getDestVertexId(), edge.getEdgeValue());
        }
    }

    return vertex;
}

From source file:org.atlasapi.persistence.content.query.QuerySplitter.java

private Maybe<ContentQuery> split(ContentQuery query, final Set<Class<? extends Identified>> allowedTypes,
        final boolean retain) {

    List<Maybe<AtomicQuery>> extracted = query.accept(new QueryVisitor<Maybe<AtomicQuery>>() {

        @Override// ww w.  j  a v  a2s  .c  om
        public Maybe<AtomicQuery> visit(IntegerAttributeQuery query) {
            return allowed(query);
        }

        @Override
        public Maybe<AtomicQuery> visit(StringAttributeQuery query) {
            return allowed(query);
        }

        @Override
        public Maybe<AtomicQuery> visit(BooleanAttributeQuery query) {
            return allowed(query);
        }

        @Override
        public Maybe<AtomicQuery> visit(EnumAttributeQuery<?> query) {
            return allowed(query);
        }

        @Override
        public Maybe<AtomicQuery> visit(DateTimeAttributeQuery query) {
            return allowed(query);
        }

        @Override
        public Maybe<AtomicQuery> visit(MatchesNothing noOp) {
            return Maybe.nothing();
        }

        private Maybe<AtomicQuery> allowed(AttributeQuery<?> query) {
            if (allowedTypes.contains(query.getAttribute().target())) {
                return retain ? Maybe.<AtomicQuery>just(query) : Maybe.<AtomicQuery>nothing();
            } else {
                return retain ? Maybe.<AtomicQuery>nothing() : Maybe.<AtomicQuery>just(query);
            }
        }
    });

    Iterable<AtomicQuery> operands = Maybe.filterValues(extracted);
    if (Iterables.isEmpty(operands)) {
        return Maybe.nothing();
    } else {
        return Maybe.just(query.copyWithOperands(operands));
    }

}

From source file:org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeBitsProvider.java

/**
 * Returns the bits for the given privilege names
 * @param privilegeNames the names//from   www .  ja  va 2 s.  c  o m
 * @return the privilege bits
 */
@Nonnull
public PrivilegeBits getBits(@Nonnull Iterable<String> privilegeNames) {
    if (Iterables.isEmpty(privilegeNames)) {
        return PrivilegeBits.EMPTY;
    }

    Tree privilegesTree = null;
    PrivilegeBits bits = PrivilegeBits.getInstance();
    for (String privilegeName : privilegeNames) {
        PrivilegeBits builtIn = PrivilegeBits.BUILT_IN.get(privilegeName);
        if (builtIn != null) {
            bits.add(builtIn);
        } else {
            if (privilegesTree == null) {
                privilegesTree = getPrivilegesTree();
            }
            if (privilegesTree.exists() && privilegesTree.hasChild(privilegeName)) {
                Tree defTree = privilegesTree.getChild(privilegeName);
                bits.add(PrivilegeBits.getInstance(defTree));
            } else {
                log.debug("Ignoring privilege name " + privilegeName);
            }
        }
    }
    return bits.unmodifiable();
}

From source file:org.obiba.opal.core.service.security.DefaultDecryptService.java

private DatasourceEncryptionStrategy getProjectEncryptionStrategy(String projectName) {
    Project project = projectService.getProject(projectName);
    OpalKeyStore keyStore = projectsKeyStoreService.getKeyStore(project);

    DatasourceEncryptionStrategy encryptionStrategy = null;

    if (!Iterables.isEmpty(keyStore.listKeyPairs())) {
        encryptionStrategy = getDefaultEncryptionStrategy();
        encryptionStrategy.setKeyProvider(keyStore);
    }// w  ww . j  a v  a 2s . c om
    return encryptionStrategy;
}

From source file:org.janusgraph.graphdb.types.indextype.IndexTypeWrapper.java

@Override
public JanusGraphSchemaType getSchemaTypeConstraint() {
    JanusGraphSchemaType constraint;//w w  w .j a  v  a 2 s .  com
    if (!cachedTypeConstraint) {
        Iterable<SchemaSource.Entry> related = base.getRelated(TypeDefinitionCategory.INDEX_SCHEMA_CONSTRAINT,
                Direction.OUT);
        if (Iterables.isEmpty(related)) {
            constraint = null;
        } else {
            constraint = (JanusGraphSchemaType) Iterables.getOnlyElement(related, null).getSchemaType();
            assert constraint != null;
        }
        schemaTypeConstraint = constraint;
        cachedTypeConstraint = true;
    } else {
        constraint = schemaTypeConstraint;
    }
    return constraint;
}

From source file:brooklyn.entity.software.MachineInitTasks.java

protected void openIptablesImpl(Iterable<Integer> inboundPorts, SshMachineLocation machine) {
    if (inboundPorts == null || Iterables.isEmpty(inboundPorts)) {
        log.info("No ports to open in iptables (no inbound ports) for {} at {}", machine, this);
    } else {//w  w  w  .j  a va  2s . c  o m
        log.info("Opening ports in iptables for {} at {}", entity(), machine);

        List<String> iptablesRules = Lists.newArrayList();

        if (isLocationFirewalldEnabled(machine)) {
            for (Integer port : inboundPorts) {
                iptablesRules
                        .add(IptablesCommands.addFirewalldRule(Chain.INPUT, Protocol.TCP, port, Policy.ACCEPT));
            }
        } else {
            iptablesRules = createIptablesRulesForNetworkInterface(inboundPorts);
            iptablesRules.add(IptablesCommands.saveIptablesRules());
        }
        List<String> batch = Lists.newArrayList();
        // Some entities, such as Riak (erlang based) have a huge range of ports, which leads to a script that
        // is too large to run (fails with a broken pipe). Batch the rules into batches of 50
        for (String rule : iptablesRules) {
            batch.add(rule);
            if (batch.size() == 50) {
                machine.execCommands("Inserting iptables rules, 50 command batch", batch);
                batch.clear();
            }
        }
        if (batch.size() > 0) {
            machine.execCommands("Inserting iptables rules", batch);
        }
        machine.execCommands("List iptables rules", ImmutableList.of(IptablesCommands.listIptablesRule()));
    }
}