Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: stream collect with own class Date: Sat, 5 Dec 2015 08:34:02 -0500 Organization: A noiseless patient Spider Lines: 49 Message-ID: References: <82287705-7d7d-46b8-bbc7-6a78e6568079@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sat, 5 Dec 2015 13:31:45 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="858a9d65d95f4ea4d355bd116aa2cdbf"; logging-data="16290"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX188zFUqQ/N7WSpcB/OdWkVJ" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 In-Reply-To: <82287705-7d7d-46b8-bbc7-6a78e6568079@googlegroups.com> Cancel-Lock: sha1:7eLf88dS55ON/gtwWYnn/W0O/QE= Xref: csiph.com comp.lang.java.programmer:33305 On 12/4/2015 5:46 PM, Philipp Kraus wrote: > Am Freitag, 4. Dezember 2015 14:58:48 UTC+1 schrieb Eric Sosman: >> On 12/4/2015 8:12 AM, Philipp Kraus wrote: >>> Hello, >>> >>> I'm using streams and I would like to create "fuzzy logic implications". In short call, I have a collection with >>> >>> Set x; >>> >>> and my IFuzzy interface is defined like >>> >>> public interface IFuzzy >>> { >>> public Boolean getResult(); >>> >>> public Double getFuzzy(); >>> } >>> >>> I run in my code >>> >>> IFuzzy y = x.stream()...... >>> >>> I would like to implode / aggregate each IFuzzy object into one result, so I need to call on each element from x the getResult() and the getFuzzy() method and collect / implode the data. >>> >>> How can I do this call with a stream operation? IMHO I need to write an operator like allMatch() >> >> If I understand you correctly, you want to combine information >> from many IFuzzy's into a single IFuzzy instance. (Just ignore me >> if I've understood *in*correctly.) In that case, you need some kind >> of a .reduce() operation, either something from the Collectors class >> or something you write yourself. > > Yes, that's correct. I have found the Collector interface, but how I can implement this in a correct way (for stream and parallelstream)? IMHO T is the type IFuzyy, but A and B? Is is correct to define T=A=B => Collector ? Why would you want a Collector? You're trying to combine a Set of IFuzzy's into *one* IFuzzy, not into a collection of (modified, derived, whatever) IFuzzy's. (Aside: The JavaDoc for SE 8 lists gives Collector's type parameters as , not . Did you misread R as B, or are you looking at some other description?) I'm still not clear on what you're trying to do. Perhaps it would help me understand if you showed the IFuzzy's => IFuzzy transformation: How would you write it using a plain old `for(IFuzzy i : x)' loop? -- esosman@comcast-dot-net.invalid "Don't be afraid of work. Make work afraid of you." -- TLM