Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #33295 > unrolled thread

stream collect with own class

Started byPhilipp Kraus <philipp.kraus.flashpixx@gmail.com>
First post2015-12-04 05:12 -0800
Last post2015-12-05 10:57 -0500
Articles 6 — 2 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  stream collect with own class Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2015-12-04 05:12 -0800
    Re: stream collect with own class Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-12-04 08:58 -0500
      Re: stream collect with own class Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2015-12-04 14:46 -0800
        Re: stream collect with own class Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-12-05 08:34 -0500
          Re: stream collect with own class Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2015-12-05 07:36 -0800
            Re: stream collect with own class Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-12-05 10:57 -0500

#33295 — stream collect with own class

FromPhilipp Kraus <philipp.kraus.flashpixx@gmail.com>
Date2015-12-04 05:12 -0800
Subjectstream collect with own class
Message-ID<ebc5a67f-5968-4b4e-8461-913f69587492@googlegroups.com>
Hello,

I'm using streams and I would like to create "fuzzy logic implications". In short call, I have a collection with

Set<IFuzzy> 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()

Thanks

Phil

[toc] | [next] | [standalone]


#33296

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2015-12-04 08:58 -0500
Message-ID<n3s61p$h2a$1@dont-email.me>
In reply to#33295
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<IFuzzy> 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.

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

[toc] | [prev] | [next] | [standalone]


#33298

FromPhilipp Kraus <philipp.kraus.flashpixx@gmail.com>
Date2015-12-04 14:46 -0800
Message-ID<82287705-7d7d-46b8-bbc7-6a78e6568079@googlegroups.com>
In reply to#33296
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<IFuzzy> 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<T,A,B> 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<T,T,T> ?

Thanks

Phil

[toc] | [prev] | [next] | [standalone]


#33305

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2015-12-05 08:34 -0500
Message-ID<n3up01$ft2$1@dont-email.me>
In reply to#33298
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<IFuzzy> 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<T,A,B> 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<T,T,T> ?

     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 <T,A,R>, not <T,A,B>.  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

[toc] | [prev] | [next] | [standalone]


#33307

FromPhilipp Kraus <philipp.kraus.flashpixx@gmail.com>
Date2015-12-05 07:36 -0800
Message-ID<6d912b3d-d67f-4cba-a069-337b76d03f1f@googlegroups.com>
In reply to#33305
Am Samstag, 5. Dezember 2015 14:34:21 UTC+1 schrieb Eric Sosman:
> 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<IFuzzy> 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<T,A,B> 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<T,T,T> ?
> 
>      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 <T,A,R>, not <T,A,B>.  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?

Okay, yes I miss this information. The transformation can be a logical or (||) of the boolean values
and a min of each floating point value. But there are a lot of more tranformation algorithms, see
https://en.wikipedia.org/wiki/T-norm#Prominent_examples
Reduction like Hamacher product is a little bit difficult, because I need an algebraic expression to calculate the floating point value, so imho I need access to all elements within the stream

Phil

[toc] | [prev] | [next] | [standalone]


#33308

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2015-12-05 10:57 -0500
Message-ID<n3v1ds$rho$1@dont-email.me>
In reply to#33307
On 12/5/2015 10:36 AM, Philipp Kraus wrote:
> Am Samstag, 5. Dezember 2015 14:34:21 UTC+1 schrieb Eric Sosman:
>> 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<IFuzzy> 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<T,A,B> 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<T,T,T> ?
>>
>>       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 <T,A,R>, not <T,A,B>.  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?
>
> Okay, yes I miss this information. The transformation can be a logical or (||) of the boolean values
> and a min of each floating point value. But there are a lot of more tranformation algorithms, see
> https://en.wikipedia.org/wiki/T-norm#Prominent_examples
> Reduction like Hamacher product is a little bit difficult, because I need an algebraic expression to calculate the floating point value, so imho I need access to all elements within the stream

     If you can't show me the transformation you want to perform,
I can't help you package it as a stream operation.  Sorry, but the
Wikipedia page (which describes *binary* operations) does not convey
to me the nature of the N-ary transformations that interest you.

     All I can suggest is that you write a plain old for-loop.  For
one thing, it may suffice for whatever your needs are.  For another,
if you'll show us your for-loop maybe somebody can show you how to
reformulate it as a stream operation.  For yet another, NetBeans (and
perhaps other IDE's) can sometimes do the reformulation for you: You
write your for-loop and NetBeans offers to rearrange it -- the form it
chooses isn't always the slickest possible, but even so it gives you a
good running start.

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web