public PainterChain addPainter(Painter p){
  if (chain.length != 0) {
    Painter[] newChain=new Painter[chain.length + 1];
    System.arraycopy(chain,0,newChain,0,chain.length);
    newChain[chain.length]=p;
    return new PainterChain(newChain);
  }
  return new PainterChain(new Painter[]{p});
}

public PainterChain addPainter ( Painter p ) { if ( chain . length != 0 ) { Painter [ ] newChain = new Painter [ chain . length + 1 ] ; System . arraycopy ( chain , 0 , newChain , 0 , chain . length ) ; newChain [ chain . length ] = p ; return new PainterChain ( newChain ) ; } return new PainterChain ( new Painter [ ] { p } ) ; }
creates a new chain based on the existing chain with the new element added at the end
