java - Automatically merge several collections to one -
i have guava functions
function<string,set<string>>
. using fluentiterable.transform()
leads fluentiterable<set<string>>
, need fluentiterable<string>
. idea subclass fluentiterable<e>
, add new method transform2()
merges 1 collection before returning it.
the original transform method looks this:
public final <t> fluentiterable<t> transform(function<? super e, t> function) { return from(iterables.transform(iterable, function)); }
i thought of subclass , transform2()
method:
public abstract class fluentiterable2<e> extends fluentiterable<e> { public final <t> fluentiterable<t> transform2(function<? super e, collection<t>> function) { // (problem 1) eclipse complains: field fluentiterable<e>.iterable not visible iterable<collection<t>> iterables = iterables.transform(iterable, function); // (problem 2) collection<t> merged = new collection<t>(); // need container / collection - one? for(collection<t> iterable : iterables) { // merged.addall(iterable); } // return from(merged); } }
currently have 2 problems new subclass, marked above problem 1
, problem 2
problem 1: iterable field in original fluentiterable class private - can this? can create new private field same name in subclass, ok? methods in subclass call super.somemethod() uses field? use field of super class, has different value?
problem 2: need generic collection can combine content of several collections, collections interface, can't instantiate it. so, class can use there?
it acceptable if solution works sets, though i'd prefer solution works sets , lists.
thanks hint on this!
does fluentiterable.transformandconcat(stringtosetfunction)
not work use case?
Comments
Post a Comment