protected static void computeCartesian(List<EventBean[]> streamOne,int[] subStreamNumsOne,List<EventBean[]> streamTwo,int[] subStreamNumsTwo,List<EventBean[]> resultList){
  if ((streamTwo == null) || (streamTwo.isEmpty())) {
    if ((streamOne == null) || (streamOne.isEmpty())) {
      return;
    }
    resultList.addAll(streamOne);
    return;
  }
  if ((streamOne == null) || (streamOne.isEmpty())) {
    resultList.addAll(streamTwo);
    return;
  }
  int streamOneSize=streamOne.size();
  int streamTwoSize=streamTwo.size();
  if (streamOneSize == 1) {
    copyToEach(subStreamNumsOne,streamOne.get(0),streamTwo);
    resultList.addAll(streamTwo);
    return;
  }
  if (streamTwoSize == 1) {
    copyToEach(subStreamNumsTwo,streamTwo.get(0),streamOne);
    resultList.addAll(streamOne);
    return;
  }
  if (streamTwoSize > streamOneSize) {
    List<EventBean[]> holdRows=streamOne;
    int holdSize=streamOneSize;
    streamOne=streamTwo;
    streamOneSize=streamTwoSize;
    streamTwo=holdRows;
    streamTwoSize=holdSize;
    subStreamNumsTwo=subStreamNumsOne;
  }
  int cartesianTotalRows=streamOneSize * streamTwoSize;
  int numColumns=streamOne.get(0).length;
  EventBean[][] results=new EventBean[cartesianTotalRows][];
  int streamOneCount=0;
  for (  EventBean[] row : streamOne) {
    results[streamOneCount]=row;
    for (int i=1; i < streamTwoSize; i++) {
      EventBean[] dupRow=new EventBean[numColumns];
      System.arraycopy(row,0,dupRow,0,numColumns);
      int index=streamOneSize * i + streamOneCount;
      results[index]=dupRow;
    }
    streamOneCount++;
  }
  int streamTwoCount=0;
  for (  EventBean[] row : streamTwo) {
    for (int i=0; i < streamOneSize; i++) {
      int index=streamTwoCount * streamOneSize + i;
      copy(subStreamNumsTwo,row,results[index]);
    }
    streamTwoCount++;
  }
  resultList.addAll(Arrays.asList(results));
}

protected static void computeCartesian ( List < EventBean [ ] > streamOne , int [ ] subStreamNumsOne , List < EventBean [ ] > streamTwo , int [ ] subStreamNumsTwo , List < EventBean [ ] > resultList ) { if ( ( streamTwo == null ) || ( streamTwo . isEmpty ( ) ) ) { if ( ( streamOne == null ) || ( streamOne . isEmpty ( ) ) ) { return ; } resultList . addAll ( streamOne ) ; return ; } if ( ( streamOne == null ) || ( streamOne . isEmpty ( ) ) ) { resultList . addAll ( streamTwo ) ; return ; } int streamOneSize = streamOne . size ( ) ; int streamTwoSize = streamTwo . size ( ) ; if ( streamOneSize == 1 ) { copyToEach ( subStreamNumsOne , streamOne . get ( 0 ) , streamTwo ) ; resultList . addAll ( streamTwo ) ; return ; } if ( streamTwoSize == 1 ) { copyToEach ( subStreamNumsTwo , streamTwo . get ( 0 ) , streamOne ) ; resultList . addAll ( streamOne ) ; return ; } if ( streamTwoSize > streamOneSize ) { List < EventBean [ ] > holdRows = streamOne ; int holdSize = streamOneSize ; streamOne = streamTwo ; streamOneSize = streamTwoSize ; streamTwo = holdRows ; streamTwoSize = holdSize ; subStreamNumsTwo = subStreamNumsOne ; } int cartesianTotalRows = streamOneSize * streamTwoSize ; int numColumns = streamOne . get ( 0 ) . length ; EventBean [ ] [ ] results = new EventBean [ cartesianTotalRows ] [ ] ; int streamOneCount = 0 ; for ( EventBean [ ] row : streamOne ) { results [ streamOneCount ] = row ; for ( int i = 1 ; i < streamTwoSize ; i ++ ) { EventBean [ ] dupRow = new EventBean [ numColumns ] ; System . arraycopy ( row , 0 , dupRow , 0 , numColumns ) ; int index = streamOneSize * i + streamOneCount ; results [ index ] = dupRow ; } streamOneCount ++ ; } int streamTwoCount = 0 ; for ( EventBean [ ] row : streamTwo ) { for ( int i = 0 ; i < streamOneSize ; i ++ ) { int index = streamTwoCount * streamOneSize + i ; copy ( subStreamNumsTwo , row , results [ index ] ) ; } streamTwoCount ++ ; } resultList . addAll ( Arrays . asList ( results ) ) ; }
form the 2 - ary cartesian product between zero or more events from 2 streams .
