sidss sidss - 6 months ago 83
Java Question

Java 8 collector for Guava Immutable Table

Use case:

Process list of string via method which returns

of type
. For instance
ImmutableTable of {Integer,String,Boolean} process(String item){...}

Collect the result i.e, merge all results and return
. Is there a way to achieve it?

Tried to write collector but couldn't get it right. Any help will great.

EDIT: Instead of writing collector I did it like this but I wonder if there is a better way to achieve this.

Builder<Integer, String, Boolean> tableBuilder =
listToProcess.parallelStream().forEach(itemString -> {
try (InputStreamReader reader = getSomeStream(itemString)) {
} catch (final Exception e) {/*...*/}

Edit :

How about using parallel stream ? Is there any concurrency issues here?

ImmutableTable<Integer, String, Boolean> buildData() {

// list of 4 AwsS3KeyName

//Create new instance via Guice dependency injection
.map(s3KeyName -> ProcessorInstanceProvider.get()
.forEach(tableBuilder::putAll); return; }


Something like this should work:

List<String> list; // given
ImmutableTable.Builder builder = new ImmutableTable.Builder();
    .map(processor::process) // converts String to ImmutableTable
ImmutableTable result =;