Exemple #1
0
 def distinct(self : "Stream"):
     assert self.iterator != None
     temp=[]
     iter= ListIterator(iterable=self.toList())
     while iter.hasNext():
         t= iter.next()
         if t not in temp:   
             temp.append(t)
     return ListIterator(iterable=temp)
Exemple #2
0
 def union(self : "Stream",iter):
     assert self.iterator != None
     temp=[]
     innerit= ListIterator(iterable=self.toList())
     while innerit.hasNext() :  
         t= innerit.next()
         if t not in temp  :
             temp.append(t)
     while iter.hasNext() :  
         t2= iter.next()
         if t2 not in temp   :
             temp.append(t2)
     return ListIterator(iterable=temp)
Exemple #3
0
    def intersect(self : "Stream",iter):
        assert self.iterator != None
        innerit=   ListIterator(iterable=self.toList())
        temp=[]
        temp2=[]
        while iter.hasNext() :  
            temp2.append(iter.next())

        while innerit.hasNext() :  
            t= innerit.next()
            if t in temp2 and t not in temp:
                temp.append(t)
        return ListIterator(iterable=temp)
Exemple #4
0
    def groupJoin(self : "Stream",it,p1,p2,mapf):
        assert self.iterator != None
        joined=[]
        temp=[]
        innerit= ListIterator(iterable=self.toList())
        while innerit.hasNext():
            temp.append(innerit.next())
        grouped=  groupby(temp,p1)
        temp2=[]
        while it.hasNext(): 
            temp2.append(it.next())
        grouped2= groupby(temp2,p2)

        for item in grouped :
            joined.append(mapf(grouped[item],grouped2[item]))

        return  ListIterator(iterable=joined)
Exemple #5
0
    def collect(self : "Stream"):
        collected=[]
        #Generar siguiente elemento
        elem_counter=0
        skip_counter=0
        take_counter=0
        take_while_flag=True
        skip_while_flag=True
        collect_in_sequence=False
        #setvar cont=0;
        temp=None
        #print('TAMANYO de self._ops_list ' +  len(self._ops_list));
        while self.iterator.hasNext() :
            #cont+=1;
            #if cont == 100  : raise 'PARADA.............'; end;
            temp=self.iterator.next()
            #print("\n>>>>>temp: " + _tostring(temp_) + "\n");
            #Y aplicarle todas las funciones.
            for i in range(len(self._ops_list)):
                #print('------Vuelta del for--------');
                ftype=self._ops_list[i]
                f=self._ops_funcs[i][0]
                #Coger argumento si lo hay
                argument=None
                if  len(self._ops_funcs[i])>1:
                    argument=self._ops_funcs[i][1]
                    #print("Valor de argument: " + _tostring(argument));
                #Proceder segun tipo de funcion
                if ftype  ==  1 : #map,select
                    if temp != None :
                        #_print("temp en map: " + _tostring(temp));
                        temp =f(temp)
                elif ftype ==  2 : #filter,where
                    if temp != None and f(temp) == False: 
                        temp = None
                elif ftype  ==  3 : #take
                    t_counter=argument
                    if t_counter > f()-1:
                        temp=None
                        #print('Llamada a break!!');
                        break
                    else:
                        self._ops_funcs[i][1]+=1
                        #print('Por take');
                elif ftype  ==  4 : #takeWhile
                    #_print("f(temp) en takeWhile: " + _tostring(f(temp)));
                    t_while_flag=argument
                    if t_while_flag == True:
                        if f(temp) == False:
                            temp = None
                            self._ops_funcs[i][1]=False
                    else:
                        temp=None
                elif ftype  ==  5 : #skip
                    s_counter=argument
                    if s_counter < f():
                        temp=None
                        self._ops_funcs[i][1]+=1
                        break
                elif ftype  ==  6 : #skipWhile
                    s_while_flag=argument
                    if s_while_flag == True:
                        if f(temp) == True:
                            temp = None
                            break
                        else:
                            #_print("Poniendo flag a False!!");
                            self._ops_funcs[i][1]=False

                elif ftype  ==  7: #foreach
                    if temp !=  None:
                         f(temp)
                elif ftype  ==  8 : #zip
                    if temp != None:
                        temp=f(temp,argument.next() if argument.hasNext() else None)
                elif ftype  ==  9 : #multiZip
                    if temp != None:
                        _args=[]
                        _args.append(temp)
                        for item in argument :
                            _args.append((item.next() if item.hasNext() else None))
                        temp=f(*_args)
                elif ftype  ==  10 : #mix
                    if temp != None:
                        l=[f(temp)]
                        l.append(f(argument.next() if argument.hasNext() else None))
                        temp=l
                        collect_in_sequence=True
                elif ftype  ==  11 : #multiMix
                    if temp != None:
                        l=[f(temp)]
                        for item in argument:
                            l.append(f(item.next() if item.hasNext() else None))
                        temp=l
                        collect_in_sequence=True
                elif ftype  ==  12 : #concat
                    if temp != None  :
                        l=[temp]
                        if argument.hasNext():
                            l.append(f(argument.next()))
                        else:
                            l.append(None)
                        #l.append(f(argument.next() if argument.hasNext()else None);
                        temp=l
                        collect_in_sequence=True
                elif ftype  ==  13 : #multiConcat
                    if temp != None:
                        l=[temp]
                        for item in argument:
                            l.append(f(item.next() if item.hasNext() else None))
                        temp=l
                        collect_in_sequence=True
                elif ftype ==  14 : #join
                    it,p1,p2,mapf=argument
                    u=it.next()
                    if p1(temp) == p2(u):
                        temp= mapf(temp,u)
                    else:
                        temp=None
                elif ftype  ==  15 : #flatMap
                    if temp != None:
                        #assert issubclass(temp,Iterator);
                        collect_in_sequence=True
                        l=[]
                        #Parche para aprovechar si es una lista
                        if type(temp) == type([])  :
                            temp= ListIterator(iterable=temp)
                        while temp.hasNext() :
                            l.append(f(temp.next()))
                        temp=l
                elif ftype  ==  16 : #flatFilter
                    if temp != None:
                        collect_in_sequence=True
                        l=[]
                        while temp.hasNext():
                            k= temp.next()
                            if f(k) == True:
                                l.append(k)
                        temp=l
                else :
                    raise Exception(f"La opcion {i} no esta implementada")
                #print("Temp al final de los cases en vuelta del for: " + _tostring(temp_));
            #print('----SALIMOS DEL FOR-----');
            elem_counter+=1
            #print('collect_in_sequence: ' + str(collect_in_sequence));
            if temp  !=  None:
                if collect_in_sequence == True:
                    for el in temp :
                        collected.append(el)
                    collect_in_sequence=False
                else:
                    #print("Metiendo en collected: " + _tostring(temp_));
                    collected.append(temp)
        return ListIterator(iterable=collected)
Exemple #6
0
 def reverse(self : "Stream"):
     assert self.iterator != None
     return ListIterator(iterable= self.toList()[::-1])
Exemple #7
0
 def orderBy(self : "Stream",fun):
     assert self.iterator != None
     return ListIterator(iterable=sorted(self.toList(),key=fun))