Example usage for com.google.common.collect ImmutableList stream

List of usage examples for com.google.common.collect ImmutableList stream

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableList stream.

Prototype

default Stream<E> stream() 

Source Link

Document

Returns a sequential Stream with this collection as its source.

Usage

From source file:com.github.gv2011.util.icol.guava.AbstractISetBuilder.java

@Override
public final <F extends E> B tryAddAll(final Collection<F> elements) {
    final ImmutableList<E> copy = ImmutableList.copyOf(elements);
    verify(copy.stream().allMatch(e -> e != null));
    set.addAll(copy);/*from w  w w.ja  v a 2 s.  c o  m*/
    return self();
}

From source file:org.apache.james.dlp.api.DLPRules.java

private void checkNotContainDuplicateIds(ImmutableList<DLPConfigurationItem> items)
        throws DuplicateRulesIdsException {
    long uniqueIdCount = items.stream().map(DLPConfigurationItem::getId).distinct().count();

    if (uniqueIdCount != items.size()) {
        throw new DuplicateRulesIdsException();
    }//from w  w  w  .  j  a v a2  s  . c o m
}

From source file:com.facebook.buck.remoteexecution.grpc.GrpcCasBlobUploader.java

@Override
public ImmutableList<UploadResult> batchUpdateBlobs(ImmutableList<UploadData> blobs) throws IOException {
    long totalBlobSizeBytes = blobs.stream().mapToLong(blob -> blob.digest.getSize()).sum();
    try (Scope unused = CasBlobUploadEvent.sendEvent(buckEventBus, blobs.size(), totalBlobSizeBytes)) {
        BatchUpdateBlobsRequest.Builder requestBuilder = BatchUpdateBlobsRequest.newBuilder();
        for (UploadData blob : blobs) {
            try (InputStream dataStream = blob.data.get()) {
                requestBuilder.addRequests(BatchUpdateBlobsRequest.Request.newBuilder()
                        .setDigest(GrpcProtocol.get(blob.digest)).setData(ByteString.readFrom(dataStream)));
            }// w  w w .j  a v a2 s.c o  m
        }
        BatchUpdateBlobsResponse batchUpdateBlobsResponse = storageStub.batchUpdateBlobs(requestBuilder.build())
                .get();
        ImmutableList.Builder<UploadResult> resultBuilder = ImmutableList.builder();
        for (Response response : batchUpdateBlobsResponse.getResponsesList()) {
            resultBuilder.add(new UploadResult(new GrpcDigest(response.getDigest()),
                    response.getStatus().getCode(), response.getStatus().getMessage()));
        }
        return resultBuilder.build();
    } catch (InterruptedException | ExecutionException e) {
        MoreThrowables.throwIfInitialCauseInstanceOf(e, IOException.class);
        throw new BuckUncheckedExecutionException(e, "When uploading a batch of blobs: <%s>. Digests: %s.",
                blobs.stream().map(b -> b.data.describe()).collect(Collectors.joining(">, <")),
                blobs.stream().map(b -> b.digest.toString()).collect(Collectors.joining(" ")));
    }
}

From source file:com.github.gv2011.util.icol.guava.AbstractISetBuilder.java

@Override
public final <F extends E> B addAll(final Collection<F> elements) {
    final ImmutableList<E> copy = ImmutableList.copyOf(elements);
    synchronized (set) {
        verify(copy.stream().allMatch(e -> e != null && !set.contains(e)));
        set.addAll(copy);/*from   w  ww .  jav  a2 s  . c o m*/
    }
    return self();
}

From source file:com.torodb.core.metrics.Hierarchy.java

public Hierarchy(ImmutableList<Map.Entry<String, String>> list) {
    this.list = list;
    list.stream().flatMap(entry -> Stream.of(entry.getKey(), entry.getValue())).forEach(Hierarchy::checkName);
}

From source file:com.spectralogic.dsbrowser.gui.services.ds3Panel.DeleteService.java

/**
 * Delete a Single Selected Spectra S3 bucket
 *
 * @param ds3Common ds3Common object// w ww. j  a va2 s  .co m
 * @param values    list of objects to be deleted
 */
public static void deleteBucket(final Ds3Common ds3Common,
        final ImmutableList<TreeItem<Ds3TreeTableValue>> values, final Workers workers,
        final LoggingService loggingService, final DateTimeUtils dateTimeUtils,
        final ResourceBundle resourceBundle) {
    LOG.info("Got delete bucket event");
    final LazyAlert alert = new LazyAlert(resourceBundle);

    final Ds3PanelPresenter ds3PanelPresenter = ds3Common.getDs3PanelPresenter();

    final Session currentSession = ds3Common.getCurrentSession();
    if (currentSession != null) {
        final ImmutableList<String> buckets = getBuckets(values);
        if (buckets.size() > 1) {
            loggingService.logMessage(resourceBundle.getString("multiBucketNotAllowed"), LogType.ERROR);
            LOG.info("The user selected objects from multiple buckets.  This is not allowed.");
            alert.error("multiBucketNotAllowed");
            return;
        }
        final Optional<TreeItem<Ds3TreeTableValue>> first = values.stream().findFirst();
        if (first.isPresent()) {
            final TreeItem<Ds3TreeTableValue> value = first.get();
            final String bucketName = value.getValue().getBucketName();
            if (!Ds3PanelService.checkIfBucketEmpty(bucketName, currentSession)) {
                loggingService.logMessage(resourceBundle.getString("failedToDeleteBucket"), LogType.ERROR);
                alert.error("failedToDeleteBucket");
            } else {
                final Ds3DeleteBucketTask ds3DeleteBucketTask = new Ds3DeleteBucketTask(
                        currentSession.getClient(), bucketName);
                DeleteFilesPopup.show(ds3DeleteBucketTask, ds3Common);
                ds3Common.getDs3TreeTableView().setRoot(new TreeItem<>());
                RefreshCompleteViewWorker.refreshCompleteTreeTableView(ds3Common, workers, dateTimeUtils,
                        loggingService);
                ds3PanelPresenter.getDs3PathIndicator().setText(StringConstants.EMPTY_STRING);
                ds3PanelPresenter.getDs3PathIndicatorTooltip().setText(StringConstants.EMPTY_STRING);
            }
        }
    } else {
        LOG.error("NULL Session when attempting to deleteBucket");
    }
}

From source file:org.graylog2.security.OrderedAuthenticatingRealms.java

private void sortRealms() {
    final AuthenticationConfig config = clusterConfigService.getOrDefault(AuthenticationConfig.class,
            AuthenticationConfig.defaultInstance());

    final LenientExplicitOrdering<String> ordering = new LenientExplicitOrdering<>(config.realmOrder());

    final ImmutableList<String> newRealmOrder = ordering.immutableSortedCopy(availableRealms.keySet());
    orderedRealms.set(newRealmOrder.stream().filter(name -> !config.disabledRealms().contains(name))
            .map(availableRealms::get).collect(Collectors.toList()));
}

From source file:com.facebook.buck.cxx.CxxWriteArgsToFileStep.java

private void createArgFile() throws IOException {
    if (Files.notExists(argFilePath.getParent())) {
        Files.createDirectories(argFilePath.getParent());
    }/*w w w  .ja  va  2 s .c  om*/
    ImmutableList<String> argFileContents = stringify(args, currentCellPath);
    if (escaper.isPresent()) {
        argFileContents = argFileContents.stream().map(escaper.get()::apply)
                .collect(MoreCollectors.toImmutableList());
    }
    MoreFiles.writeLinesToFile(argFileContents, argFilePath);
}

From source file:com.google.errorprone.bugpatterns.OverrideThrowableToString.java

@Override
public Description matchClass(ClassTree classTree, VisitorState state) {
    if (!ASTHelpers.isSubtype(ASTHelpers.getType(classTree), state.getSymtab().throwableType, state)) {
        return Description.NO_MATCH;
    }//from w  ww  .  java 2s  .  c om
    ImmutableList<MethodTree> methods = classTree.getMembers().stream().filter(m -> m instanceof MethodTree)
            .map(m -> (MethodTree) m).collect(toImmutableList());
    if (methods.stream().anyMatch(m -> m.getName().contentEquals("getMessage"))) {
        return Description.NO_MATCH;
    }
    return methods.stream().filter(m -> Matchers.toStringMethodDeclaration().matches(m, state)).findFirst()
            .map(m -> describeMatch(classTree, SuggestedFixes.renameMethod(m, "getMessage", state)))
            .orElse(Description.NO_MATCH);
}

From source file:com.spectralogic.ds3autogen.java.generators.responsemodels.HeadObjectResponseGenerator.java

/**
 * Retrieves the list of parameters needed to create the response POJO
 * for head object// w  w w  . j a v  a 2 s  .  c om
 */
@Override
public ImmutableList<Arguments> toParamList(final ImmutableList<Ds3ResponseCode> ds3ResponseCodes) {
    final ImmutableList<Arguments> params = ImmutableList.of(new Arguments("Metadata", "Metadata"),
            new Arguments("long", "ObjectSize"), new Arguments("Status", "Status"));

    return params.stream().sorted(new CustomArgumentComparator()).collect(GuavaCollectors.immutableList());
}