SIRSplitJoin result = new SIRSplitJoin(sj.getParent(), sj.getIdent() + "_Hier", sj.getFields(), sj.getMethods());
SIRSplitJoin result = new SIRSplitJoin(sj.getParent(), sj.getIdent() + "_Hier");
    public static SIRSplitJoin addHierarchicalChildren(SIRSplitJoin sj, PartitionGroup partition) {	// make result	SIRSplitJoin result = new SIRSplitJoin(sj.getParent(), sj.getIdent() + "_Hier", sj.getFields(), sj.getMethods());	result.setInit(SIRStream.makeEmptyInit());	// get copy of children and params	List children = sj.getParallelStreams();	List params = sj.getParams();		// the new and old weights for the splitter and joiner	int[] oldSplit=sj.getSplitter().getWeights();	int[] oldJoin=sj.getJoiner().getWeights();	JExpression[] newSplit=new JExpression[partition.size()];	JExpression[] newJoin=new JExpression[partition.size()];	// for all the partitions...	for(int i=0;i<partition.size();i++) {	    int partSize=partition.get(i);	    if (partSize==1) {		// if there is only one stream in the partition, then		// we don't need to do anything; just add the children		int pos = partition.getFirst(i);		result.add((SIRStream)children.get(pos), (List)params.get(pos));		newSplit[i]=new JIntLiteral(oldSplit[pos]);		newJoin[i]=new JIntLiteral(oldJoin[pos]);	    } else {		int sumSplit=0;		int sumJoin=0;		// child split and join weights		JExpression[] childSplit=new JExpression[partSize];		JExpression[] childJoin=new JExpression[partSize];		// the child splitjoin		SIRSplitJoin childSplitJoin=new SIRSplitJoin(sj,							     sj.getIdent() + "_child" + i);		childSplitJoin.setInit(SIRStream.makeEmptyInit());		// move children into hierarchical splitjoin		for(int k=0,l=partition.getFirst(i);k<partSize;k++,l++) {		    sumSplit+=oldSplit[l];		    sumJoin+=oldJoin[l];		    childSplit[k]=new JIntLiteral(oldSplit[l]);		    childJoin[k]=new JIntLiteral(oldJoin[l]);		    childSplitJoin.add((SIRStream)children.get(l), (List)params.get(l));		}		// in the case of a duplicate splitter, <create>		// disregards the weights array and makes them all 1		childSplitJoin.setSplitter(SIRSplitter.create(childSplitJoin,sj.getSplitter().getType(),childSplit));		childSplitJoin.setJoiner(SIRJoiner.create(childSplitJoin,sj.getJoiner().getType(),childJoin));		// update new toplevel splitjoin		newSplit[i]=new JIntLiteral(sumSplit);		newJoin[i]=new JIntLiteral(sumJoin);		result.add(childSplitJoin);	    }	}	// set the splitter and joiner types according to the new weights	result.setSplitter(SIRSplitter.create(result,sj.getSplitter().getType(),newSplit));	result.setJoiner(SIRJoiner.create(result,sj.getJoiner().getType(),newJoin));	// return new sj	return result;    }