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.spectralogic.dsbrowser.gui.services.ds3Panel.DeleteService.java

/**
 * Delete files from BlackPearl bucket/folder
 *
 * @param ds3Common ds3Common object// w  ww .j a  va  2  s.c om
 * @param values    list of objects to be deleted
 */
public static void deleteFiles(final Ds3Common ds3Common,
        final ImmutableList<TreeItem<Ds3TreeTableValue>> values) {
    LOG.info("Got delete file(s) event");

    final ImmutableList<String> buckets = getBuckets(values);

    final ArrayList<Ds3TreeTableValue> filesToDelete = new ArrayList<>(
            values.stream().map(TreeItem::getValue).collect(Collectors.toList()));
    final Map<String, List<Ds3TreeTableValue>> bucketObjectsMap = filesToDelete.stream()
            .collect(Collectors.groupingBy(Ds3TreeTableValue::getBucketName));

    final Ds3DeleteFilesTask ds3DeleteFilesTask = new Ds3DeleteFilesTask(
            ds3Common.getCurrentSession().getClient(), buckets, bucketObjectsMap);

    DeleteFilesPopup.show(ds3DeleteFilesTask, ds3Common);
}

From source file:org.ow2.authzforce.core.pdp.api.io.BaseXacmlJaxbResultPostprocessor.java

private static List<AttributeAssignment> convert(
        ImmutableList<PepActionAttributeAssignment<?>> attributeAssignments) {
    if (attributeAssignments == null) {
        return null;
    }/*from  w w  w. j a  v  a  2  s. c o m*/

    return attributeAssignments.stream().map(attAssignment -> {
        final AttributeValue attVal = attAssignment.getValue();
        return new AttributeAssignment(attVal.getContent(), attAssignment.getDatatype().getId(),
                attVal.getXmlAttributes(), attAssignment.getAttributeId(),
                attAssignment.getCategory().orElse(null), attAssignment.getIssuer().orElse(null));
    }).collect(Collectors.toList());
}

From source file:org.apache.james.jmap.model.Message.java

private static Predicate<BlobId> inAttachments(ImmutableList<Attachment> attachments) {
    return (key) -> {
        return attachments.stream().map(Attachment::getBlobId).anyMatch(blobId -> blobId.equals(key));
    };// w  ww.  ja  va2  s. c  o  m
}

From source file:com.spectralogic.dsbrowser.gui.util.ParseJobInterruptionMap.java

public static Map<String, FilesAndFolderMap> removeJobID(final JobInterruptionStore jobInterruptionStore,
        final String uuid, final String endpoint, final DeepStorageBrowserPresenter deepStorageBrowserPresenter,
        final LoggingService loggingService) {
    final ImmutableList<Map<String, Map<String, FilesAndFolderMap>>> completeArrayList = jobInterruptionStore
            .getJobIdsModel().getEndpoints().stream().collect(GuavaCollectors.immutableList());
    if (!Guard.isNullOrEmpty(completeArrayList)
            && completeArrayList.stream().anyMatch(i -> i.containsKey(endpoint))) {
        try {/*from   w w  w.j av a  2  s  .c om*/
            removeJobIdFromFile(jobInterruptionStore, uuid, endpoint);
        } catch (final IOException e) {
            LOG.error("Encountered an exception when trying to remove a job", e);
            loggingService.logMessage("Failed to remove job id: " + e, LogType.ERROR);
        }
    }
    if (deepStorageBrowserPresenter != null && jobInterruptionStore.getJobIdsModel().getEndpoints() != null) {
        final ImmutableList<Map<String, Map<String, FilesAndFolderMap>>> endpointsMap = jobInterruptionStore
                .getJobIdsModel().getEndpoints().stream().collect(GuavaCollectors.immutableList());
        return getJobIDMap(endpointsMap, endpoint, deepStorageBrowserPresenter.getJobProgressView(), null);
    }
    return null;
}

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

public static void createFolderPrompt(final Ds3Common ds3Common, final LoggingService loggingService,
        final ResourceBundle resourceBundle) {
    ImmutableList<TreeItem<Ds3TreeTableValue>> values = ds3Common.getDs3TreeTableView().getSelectionModel()
            .getSelectedItems().stream().collect(GuavaCollectors.immutableList());
    final TreeItem<Ds3TreeTableValue> root = ds3Common.getDs3TreeTableView().getRoot();
    final LazyAlert alert = new LazyAlert(resourceBundle);

    if (values.stream().map(TreeItem::getValue).anyMatch(Ds3TreeTableValue::isSearchOn)) {
        LOG.info("You can not create folder here. Please refresh your view");
        alert.info("cantCreateFolderHere");
        return;/*from   w  ww.  jav  a  2 s .  c  o m*/
    } else if (values.isEmpty() && root != null && root.getValue() != null) {
        final ImmutableList.Builder<TreeItem<Ds3TreeTableValue>> builder = ImmutableList.builder();
        values = builder.add(root).build();
    } else if (values.isEmpty()) {
        loggingService.logMessage(resourceBundle.getString("selectLocation"), LogType.ERROR);
        alert.info("locationNotSelected");
        return;
    } else if (values.size() > 1) {
        LOG.info("Only a single location can be selected to create empty folder");
        alert.info("selectSingleLocation");
        return;
    }

    final Optional<TreeItem<Ds3TreeTableValue>> first = values.stream().findFirst();
    if (first.isPresent()) {
        final TreeItem<Ds3TreeTableValue> ds3TreeTableValueTreeItem = first.get();

        final String destinationDirectory = ds3TreeTableValueTreeItem.getValue().getDirectoryName();

        final ImmutableList<String> buckets = values.stream().map(TreeItem::getValue)
                .map(Ds3TreeTableValue::getBucketName).distinct().collect(GuavaCollectors.immutableList());
        final Optional<String> bucketElement = buckets.stream().findFirst();
        bucketElement.ifPresent(bucket -> CreateFolderPopup.show(
                new CreateFolderModel(ds3Common.getCurrentSession().getClient(), destinationDirectory, bucket),
                resourceBundle));

        Ds3PanelService.refresh(ds3TreeTableValueTreeItem);
    }
}

From source file:com.spectralogic.ds3autogen.python.utils.FunctionalTestHelper.java

/**
 * Determines if the code contains the python request handler init line
 *//*from   w  ww.  ja v a2  s  .c o  m*/
private static boolean hasRequestHandlerInit(final ImmutableList<String> reqArgs,
        final ImmutableList<String> optArgs, final String requestPayload, final String code) {
    final StringBuilder search = new StringBuilder();
    search.append("def __init__(self");
    if (hasContent(reqArgs)) {
        final String reqArgString = reqArgs.stream().collect(Collectors.joining(", "));
        search.append(", ").append(reqArgString);
    }
    if (hasContent(requestPayload)) {
        search.append(", ").append(requestPayload);
    }
    if (hasContent(optArgs)) {
        final String optArgString = optArgs.stream().map(i -> i + "=None").collect(Collectors.joining(", "));
        search.append(", ").append(optArgString);
    }
    search.append("):");
    return code.contains(search.toString());
}

From source file:com.facebook.buck.android.resources.ResourceTable.java

public static ResourceTable slice(ResourceTable table, Map<Integer, Integer> countsToExtract) {
    ResTablePackage newPackage = ResTablePackage.slice(table.resPackage, countsToExtract);

    StringPool strings = table.strings;/*from w ww  . ja v  a  2  s .c  om*/
    // Figure out what strings are used by the retained references.
    ImmutableSortedSet.Builder<Integer> stringRefs = ImmutableSortedSet
            .orderedBy(Comparator.comparing(strings::getString).thenComparingInt(i -> i));
    newPackage.visitStringReferences(stringRefs::add);
    ImmutableList<Integer> stringsToExtract = stringRefs.build().asList();
    ImmutableMap<Integer, Integer> stringMapping = Maps
            .uniqueIndex(IntStream.range(0, stringsToExtract.size())::iterator, stringsToExtract::get);

    // Extract a StringPool that contains just the strings used by the new package.
    // This drops styles.
    StringPool newStrings = StringPool.create(stringsToExtract.stream().map(strings::getString)::iterator);

    // Adjust the string references.
    newPackage.transformStringReferences(stringMapping::get);

    return new ResourceTable(newStrings, newPackage);
}

From source file:com.facebook.buck.android.RedexArgsHelper.java

static Optional<RedexOptions> getRedexOptions(AndroidBuckConfig androidBuckConfig, BuildTarget buildTarget,
        ActionGraphBuilder graphBuilder, CellPathResolver cellRoots, boolean redexRequested,
        ImmutableList<StringWithMacros> redexExtraArgs, Optional<SourcePath> redexConfig) {
    if (!redexRequested) {
        return Optional.empty();
    }/*from  ww  w  . j av a  2s . c o  m*/

    Tool redexBinary = androidBuckConfig.getRedexTool(graphBuilder);

    StringWithMacrosConverter macrosConverter = StringWithMacrosConverter.builder().setBuildTarget(buildTarget)
            .setCellPathResolver(cellRoots).setExpanders(MacroExpandersForAndroidRules.MACRO_EXPANDERS).build();
    List<Arg> redexExtraArgsList = redexExtraArgs.stream().map(x -> macrosConverter.convert(x, graphBuilder))
            .collect(Collectors.toList());

    return Optional.of(RedexOptions.builder().setRedex(redexBinary).setRedexConfig(redexConfig)
            .setRedexExtraArgs(redexExtraArgsList).build());
}

From source file:com.facebook.buck.android.resources.ResTablePackage.java

public static ResTablePackage slice(ResTablePackage resPackage, Map<Integer, Integer> countsToSlice) {
    resPackage.assertValidIds(countsToSlice.keySet());

    int packageId = resPackage.packageId;
    byte[] nameData = Arrays.copyOf(resPackage.nameData, NAME_DATA_LENGTH);

    List<ResTableTypeSpec> newSpecs = resPackage.getTypeSpecs().stream()
            .map(spec -> ResTableTypeSpec.slice(spec, countsToSlice.getOrDefault(spec.getResourceType(), 0)))
            .collect(ImmutableList.toImmutableList());

    StringPool keys = resPackage.keys;/*ww  w.j  av  a2s  .  c o  m*/

    // Figure out what keys are used by the retained references.
    ImmutableSortedSet.Builder<Integer> keyRefs = ImmutableSortedSet
            .orderedBy(Comparator.comparing(keys::getString));
    newSpecs.forEach(spec -> spec.visitKeyReferences(keyRefs::add));
    ImmutableList<Integer> keysToExtract = keyRefs.build().asList();
    Map<Integer, Integer> keyMapping = Maps.uniqueIndex(IntStream.range(0, keysToExtract.size())::iterator,
            keysToExtract::get);

    // Extract a StringPool that contains just the keys used by the new specs.
    StringPool newKeys = StringPool.create(keysToExtract.stream().map(keys::getString)::iterator);

    // Adjust the key references.
    for (ResTableTypeSpec spec : newSpecs) {
        spec.transformKeyReferences(keyMapping::get);
    }

    StringPool types = resPackage.types.copy();

    int chunkSize = HEADER_SIZE + types.getChunkSize() + newKeys.getChunkSize();
    for (ResTableTypeSpec spec : newSpecs) {
        chunkSize += spec.getTotalSize();
    }

    return new ResTablePackage(chunkSize, packageId, nameData, types, newKeys, newSpecs);
}

From source file:com.spectralogic.ds3autogen.java.generators.requestmodels.BaseRequestGenerator.java

/**
 * Converts a list of Ds3Params into a list of Arguments
 * @param ds3Params A list of Ds3Params//from  ww  w.j a  v  a 2s.co  m
 * @return A list of Arguments
 */
protected static ImmutableList<Arguments> toArgumentsList(final ImmutableList<Ds3Param> ds3Params) {
    if (isEmpty(ds3Params)) {
        return ImmutableList.of();
    }

    return ds3Params.stream().filter(param -> !param.getName().equals("Operation"))
            .map(param -> new Arguments(param.getType().substring(param.getType().lastIndexOf(".") + 1),
                    param.getName()))
            .collect(GuavaCollectors.immutableList());
}