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:de.dobermai.mqttbot.config.IRCProperties.java

@PostConstruct
public void postConstruct() {
    //Governator does not allow property lists out of the box. See https://github.com/Netflix/governator/issues/74

    ircChannels = Splitter.on(",").omitEmptyStrings().trimResults().split(ircChannelsRawString);

    if (Iterables.isEmpty(ircChannels)) {
        log.warn("No IRC channels were set!");
    }//from   ww  w  .  j a  v  a 2s.c  o m
}

From source file:com.palantir.util.paging.SimpleResultsPage.java

/**
 * Constructs a page of iterable chunks.
 *
 * @param chunks a set of chunks//  w w w .  j  ava  2 s. c o  m
 */
public SimpleResultsPage(Iterable<T> chunks) {
    this(chunks, !Iterables.isEmpty(chunks));
}

From source file:org.wso2.carbon.identity.application.authenticator.fido.u2f.data.messages.AuthenticateRequestData.java

public AuthenticateRequestData(String appId, Iterable<? extends DeviceRegistration> devices, U2F u2f,
        ChallengeGenerator challengeGenerator) throws U2fException {
    if (Iterables.isEmpty(devices)) {
        throw new NoDevicesRegisteredException();
    }//  www  .  j  a v a 2  s  .  c om
    ImmutableList.Builder<AuthenticateRequest> requestBuilder = ImmutableList.builder();
    byte[] challenge = challengeGenerator.generateChallenge();
    for (DeviceRegistration device : devices) {
        requestBuilder.add(u2f.startAuthentication(appId, device, challenge));
    }
    this.authenticateRequests = requestBuilder.build();
}

From source file:com.spectralogic.ds3cli.views.csv.DetailedObjectsPhysicalView.java

@Override
public String render(final GetDetailedObjectsResult obj) {
    final Iterable<DetailedS3Object> detailedS3Objects = obj.getResult();
    if (detailedS3Objects == null || Iterables.isEmpty(detailedS3Objects)) {
        return "No objects returned";
    }/*w ww .j ava2  s .co m*/

    final ImmutableList<String> headers = ImmutableList.of("Name", "Bucket", "Owner", "Size", "Type",
            "Creation Date", "Barcode", "State");

    final FluentIterable<DetailedTapeInfo> objects = FluentIterable.from(detailedS3Objects)
            .filter(new Predicate<DetailedS3Object>() {
                @Override
                public boolean apply(@Nullable final DetailedS3Object input) {
                    return input.getBlobs() != null && !Guard.isNullOrEmpty(input.getBlobs().getObjects());
                }
            }).transformAndConcat(new DetailedDs3ObjectMapper());

    return new CsvOutput<>(headers, objects, new CsvOutput.ContentFormatter<DetailedTapeInfo>() {
        @Override
        public Iterable<String> format(final DetailedTapeInfo content) {

            final ImmutableList.Builder<String> csvRow = ImmutableList.builder();
            final DetailedS3Object detailedObject = content.getDetailedS3Object();
            final Tape tape = content.getTape();

            csvRow.add(nullGuard(detailedObject.getName()));
            csvRow.add(nullGuardToString(detailedObject.getBucketId()));
            csvRow.add(nullGuardToString(detailedObject.getOwner()));
            csvRow.add(nullGuardToString(detailedObject.getSize()));
            csvRow.add(nullGuardToString(detailedObject.getType()));
            csvRow.add(nullGuardFromDate(detailedObject.getCreationDate(), DATE_FORMAT));
            csvRow.add(nullGuard(tape.getBarCode()));
            csvRow.add(nullGuardToString(tape.getState()));
            return csvRow.build();
        }
    }).toString();
}

From source file:org.eclipse.xtend.core.scoping.LocalResourceFilteringTypeScope.java

private boolean isFiltered(QualifiedName name) {
    Iterable<IEObjectDescription> exportedObjects = filterDescription
            .getExportedObjects(TypesPackage.Literals.JVM_TYPE, name, false);
    return !Iterables.isEmpty(exportedObjects);
}

From source file:org.jboss.hal.dmr.ModelNodeHelper.java

/**
 * Tries to get a deeply nested model node from the specified model node. Nested paths must be separated with "/".
 *
 * @param modelNode The model node to read from
 * @param path      A path separated with "/"
 *
 * @return The nested node or an empty / undefined model node
 *///from ww  w .ja va2s . c  om
public static ModelNode failSafeGet(ModelNode modelNode, String path) {
    ModelNode undefined = new ModelNode();

    if (Strings.emptyToNull(path) != null) {
        Iterable<String> keys = Splitter.on('/').omitEmptyStrings().trimResults().split(path);
        if (!Iterables.isEmpty(keys)) {
            ModelNode context = modelNode;
            for (String key : keys) {
                String safeKey = decodeValue(key);
                if (context.hasDefined(safeKey)) {
                    context = context.get(safeKey);
                } else {
                    context = undefined;
                    break;
                }
            }
            return context;
        }
    }

    return undefined;
}

From source file:org.jclouds.s3.binders.BindIterableAsPayloadToDeleteRequest.java

@SuppressWarnings("unchecked")
@Override/*from   w  ww  .  j  a  v a  2s  .  c  o  m*/
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
    checkArgument(checkNotNull(input, "input is null") instanceof Iterable,
            "this binder is only valid for an Iterable");
    checkNotNull(request, "request is null");

    Iterable<String> keys = (Iterable<String>) input;
    checkArgument(!Iterables.isEmpty(keys), "The list of keys should not be empty.");

    String content;
    try {
        XMLBuilder rootBuilder = XMLBuilder.create("Delete");
        for (String key : keys) {
            XMLBuilder ownerBuilder = rootBuilder.elem("Object");
            XMLBuilder keyBuilder = ownerBuilder.elem("Key").text(key);
        }

        Properties outputProperties = new Properties();
        outputProperties.put(OutputKeys.OMIT_XML_DECLARATION, "yes");
        content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + rootBuilder.asString(outputProperties);
    } catch (ParserConfigurationException pce) {
        throw Throwables.propagate(pce);
    } catch (TransformerException te) {
        throw Throwables.propagate(te);
    }

    Payload payload = Payloads.newStringPayload(content);
    payload.getContentMetadata().setContentType(MediaType.TEXT_XML);
    byte[] md5 = md5().hashString(content, UTF_8).asBytes();
    payload.getContentMetadata().setContentMD5(md5);
    request.setPayload(payload);
    return request;
}

From source file:dagger.internal.codegen.writer.TypeVariableName.java

@Override
public Appendable write(Appendable appendable, Context context) throws IOException {
    appendable.append(name);//  w  w w.j a va2  s  . c  o  m
    if (!Iterables.isEmpty(extendsBounds)) {
        appendable.append(" extends ");
        Iterator<? extends TypeName> iter = extendsBounds.iterator();
        iter.next().write(appendable, context);
        while (iter.hasNext()) {
            appendable.append(" & ");
            iter.next().write(appendable, context);
        }
    }
    return appendable;
}

From source file:com.palantir.giraffe.file.base.CrossSystemTransfers.java

public static void moveDirectory(Path source, Path target, CopyFlags flags) throws IOException {
    checkPaths(source, target, flags);/*w  w  w  .  ja va2s.  co  m*/
    checkNoAtomicMove(source, target, flags);

    if (!Iterables.isEmpty(Files.newDirectoryStream(source))) {
        throw new DirectoryNotEmptyException(source.toString());
    }

    if (flags.replaceExisting) {
        Files.deleteIfExists(target);
    }
    Files.createDirectory(target);
    Files.delete(source);
}

From source file:brooklyn.entity.basic.BasicStartableImpl.java

@Override
public void start(Collection<? extends Location> locations) {
    log.info("Starting entity " + this + " at " + locations);
    addLocations(locations);/*w w  w .  j a  v  a  2 s .c o m*/

    // essentially does StartableMethods.start(this, locations),
    // but optionally filters locations for each child

    brooklyn.location.basic.Locations.LocationsFilter filter = getConfig(LOCATIONS_FILTER);
    Iterable<Entity> startables = filterStartableManagedEntities(getChildren());
    if (startables == null || Iterables.isEmpty(startables))
        return;

    List<Task<?>> tasks = Lists.newArrayList();
    for (final Entity entity : startables) {
        Collection<? extends Location> l2 = locations;
        if (filter != null) {
            l2 = filter.filterForContext(new ArrayList<Location>(locations), entity);
            log.debug("Child " + entity + " of " + this + " being started in filtered location list: " + l2);
        }
        tasks.add(Entities.invokeEffectorWithArgs(this, entity, Startable.START, l2));
    }
    for (Task<?> t : tasks)
        t.getUnchecked();
}