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:ezbake.services.graph.SelectorVertexFactory.java

private Long lookup(String uniqueVal) {
    SecureTitanTx tx = graph.buildTransaction()
            .setReadToken(AccumuloSecurityToken.getInstance().newReadToken(UNIQUE_VIS)).start();

    Iterable<Vertex> itrbl = tx.getVertices(EzGraphServiceConstants.UNIQUE_KEY, uniqueVal);

    Long vid = null;/*from  ww  w .  j  a  va  2s .c o  m*/
    if (!Iterables.isEmpty(itrbl)) {
        TitanVertex selectorVertex = (TitanVertex) Iterables.getOnlyElement(itrbl);
        vid = selectorVertex.getID();
    }

    return vid;
}

From source file:com.reprezen.swagedit.editor.outline.OutlineContentProvider.java

@Override
public boolean hasChildren(Object element) {
    if (element instanceof AbstractNode) {
        return !Iterables.isEmpty(((AbstractNode) element).elements());
    }//from w ww .j  ava2 s. com
    return false;
}

From source file:org.xacml4j.v30.spi.pip.DefaultPolicyInformationPoint.java

@Override
public BagOfAttributeExp resolve(final EvaluationContext context, AttributeDesignatorKey ref) throws Exception {
    if (log.isDebugEnabled()) {
        log.debug("Trying to resolve designator=\"{}\"", ref);
    }// w w  w. ja v a 2 s.  c om
    Iterable<AttributeResolver> resolvers = registry.getMatchingAttributeResolvers(context, ref);
    if (Iterables.isEmpty(resolvers)) {
        if (log.isDebugEnabled()) {
            log.debug("No matching resolver found for designator=\"{}\"", ref);
        }
        return null;
    }
    for (AttributeResolver r : resolvers) {
        AttributeResolverDescriptor d = r.getDescriptor();
        Preconditions.checkState(d.canResolve(ref));
        ResolverContext rContext = createContext(context, d);
        AttributeSet attributes = null;
        if (d.isCacheable()) {
            if (log.isDebugEnabled()) {
                log.debug("Trying to find resolver id=\"{}\" values in cache", d.getId());
            }
            attributes = cache.getAttributes(rContext);
            if (attributes != null && !isExpired(attributes, context)) {
                if (log.isDebugEnabled()) {
                    log.debug("Found cached resolver id=\"{}\" values=\"{}\"", d.getId(), attributes);
                }
                return attributes.get(ref.getAttributeId());
            }
        }
        try {
            if (log.isDebugEnabled()) {
                log.debug("Trying to resolve values with resolver id=\"{}\"", d.getId());
            }
            attributes = r.resolve(rContext);
            if (attributes.isEmpty()) {
                if (log.isDebugEnabled()) {
                    log.debug("Resolver id=\"{}\" failed to resolve attributes", d.getId());
                }
                continue;
            }
            if (log.isDebugEnabled()) {
                log.debug("Resolved attributes=\"{}\"", attributes);
            }
        } catch (Exception e) {
            if (log.isDebugEnabled()) {
                log.debug("Resolver id=\"{}\" failed to resolve attributes", d.getId(), e);
            }
            continue;
        }
        // check if resolver
        // descriptor allows long term caching
        if (d.isCacheable() && !attributes.isEmpty()) {
            cache.putAttributes(rContext, attributes);
        }
        context.setDecisionCacheTTL(d.getPreferredCacheTTL());
        return attributes.get(ref.getAttributeId());
    }
    return ref.getDataType().emptyBag();
}

From source file:com.spectralogic.ds3cli.util.RecoveryFileManager.java

public static String deleteFileList(final Iterable<Path> files) {
    if (Iterables.isEmpty(files)) {
        return "No matching recovery files found.";
    }//from ww  w  .  j a  va  2 s  . c o  m
    final StringBuffer fileList = new StringBuffer("Deleted:\n");
    try {
        for (final Path file : files) {
            final RecoveryJob job = getRecoveryJobByName(file.getFileName().toString());
            Files.delete(file);
            fileList.append(job.toString());
            fileList.append("\n");
        }
        return fileList.toString();
    } catch (final IOException e) {
        return e.getMessage();
    }
}

From source file:org.codeseed.common.config.AnnotationPropertySource.java

/**
 * Creates a property source backed by some number of annotation property
 * sources. The resulting property source will consider annotations (in
 * order) on configuration interface methods when trying to resolve property
 * values. If the configuration method contains no annotations, this
 * property source will always return {@code null}.
 *
 * @param sources//  ww w  .  j ava  2  s  .  c  o  m
 *            the annotation property sources to aggregate
 * @return a single property source which delegates to the supplied sources
 *         in annotation declaration order
 */
public static PropertySource create(Iterable<? extends AnnotationPropertySource<?>> sources) {
    if (Iterables.isEmpty(sources)) {
        return PropertySources.empty();
    }
    return new AnnotationsPropertySource(sources);
}

From source file:org.caleydo.view.tourguide.internal.serialize.TourGuideSerializationAddon.java

@Override
public void serialize(Collection<? extends IDataDomain> toSave, Marshaller marshaller, String dirName) {
    Iterable<ISerializeableScore> toPersist = Scores.get().getPersistentScores();
    if (Iterables.isEmpty(toPersist))
        return;//from   w ww  .j a va  2s .co  m
    File f = new File(dirName, PERSISTENT_SCORES_XML);
    PersistentScores scores = new PersistentScores(toPersist);
    try {
        marshaller.marshal(scores, f);
    } catch (JAXBException e) {
        log.error("can't serialize", e);
    }
}

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

@Override
public void store(@Nonnull final Iterable<String> newLicenseKeys) {
    checkNotNull(newLicenseKeys, "newLicenseKeys");
    if (licenseRolesAreEnabled()) {
        if (Iterables.isEmpty(newLicenseKeys)) {
            throw new IllegalArgumentException("You must store at least one license.");
        }// w ww.j a v a2s  .  c  om

        if (any(newLicenseKeys, Predicates.isNull())) {
            throw new IllegalArgumentException(
                    "You cannot store null licenses - no changes have been made to licenses.");
        }

        entityEngine.delete(from(PRODUCT_LICENSE).all());

        for (String licenseKey : newLicenseKeys) {
            entityEngine.createValue(PRODUCT_LICENSE, new ProductLicense(licenseKey));
        }

        String singleLicense = trimToNull(jiraLicenseStore.retrieve());
        if (singleLicense != null) {
            jiraLicenseStore.remove();
        }
    } else {
        Iterator<String> iterator = newLicenseKeys.iterator();
        if (iterator.hasNext()) {
            jiraLicenseStore.store(iterator.next());
        } else {
            jiraLicenseStore.store(null);
        }
    }
}

From source file:eu.numberfour.n4js.scoping.utils.DynamicPseudoScope.java

@Override
public Iterable<IEObjectDescription> getElements(EObject object) {
    Iterable<IEObjectDescription> result = parent.getElements(object);
    if (Iterables.isEmpty(result)) {
        if (object instanceof IdentifiableElement) {
            return Collections.singletonList(EObjectDescription
                    .create(QualifiedName.create(((IdentifiableElement) object).getName()), object));
        }//from  w  w  w  . j  av  a 2s .  co m
    }
    return result;
}

From source file:org.trancecode.collection.TcIterables.java

public static <T> Iterable<T> getDescendants(final Iterable<T> parentElements,
        final Function<T, Iterable<T>> getChildFunction) {
    if (Iterables.isEmpty(parentElements)) {
        return parentElements;
    }/* w  ww  .j  a  v  a 2s. c om*/

    final Iterable<T> children = Iterables.concat(Iterables.transform(parentElements, getChildFunction));

    return Iterables.concat(parentElements, getDescendants(children, getChildFunction));
}

From source file:org.openscience.cdk.layout.CorrectGeometricConfiguration.java

/**
 * Adjust all double bond elements in the provided structure. <b>IMPORTANT:
 * up/down labels should be adjusted before adjust double-bond
 * configurations. coordinates are reflected by this method which can lead
 * to incorrect tetrahedral specification.</b>
 *
 * @param container the structure to adjust
 * @throws IllegalArgumentException an atom had unset coordinates
 *///from w  ww. j  a v a  2 s .c o  m
public static IAtomContainer correct(IAtomContainer container) {
    if (!Iterables.isEmpty(container.stereoElements()))
        new CorrectGeometricConfiguration(container);
    return container;
}