code: public static AffineTransformation reorderAxesTransformation(int dim, int... axes) {
      double[][] m = zeroMatrix(dim + 1);
      // insert ones appropriately:
      for(int i = 0; i < axes.length; i++) {
        assert (0 < axes[i] && axes[i] <= dim);
        m[i][axes[i] - 1] = 1.0;
      }
      int useddim = 1;
      for(int i = axes.length; i < dim + 1; i++) {
        // find next "unused" dimension.
        {
          boolean search = true;
          while(search) {
            search = false;
            for(int a : axes) {
              if(a == useddim) {
                search = true;
                useddim++;
                break;
              }
            }
          }
        }
        m[i][useddim - 1] = 1.0;
        useddim++;
      }
      assert (useddim - 2 == dim);
      return new AffineTransformation(dim, m, null);
    }
docs: Generate a transformation that reorders axes in the given way.
  
  The list of axes to be used should not contain duplicates, or the resulting
  matrix will not be invertible. It does not have to be complete however, in
  particular an empty list will result in the identity transform: unmentioned
  axes will be appended in their original order.
  
  @param dim Dimensionality of vector space (resulting Matrix will be dim+1 x
  dim+1)
  @param axes (Partial) list of axes
  @return new transformation to do the requested reordering