code: static String[] merge( @Nonnull String[] mainSelector, @Nonnull String[] base ) {
          int count = 0;
  
          // counting the & characters and calculate the resulting selectors
          int[] counts = new int[base.length];
          for( int j = 0; j < base.length; j++ ) {
              String selector = base[j];
              int andCount = 0;
              int idx = -1;
              while( (idx = selector.indexOf( '&', idx + 1 )) >= 0 ) {
                  andCount++;
              }
              count += counts[j] = (int)Math.pow( mainSelector.length, Math.max( 1, andCount ) );
          }
  
          String[] sel = new String[count];
          for( int j = 0, t = 0; j < base.length; j++ ) {
              String selector = base[j];
              int idx = selector.lastIndexOf( '&' );
              if( idx < 0 ) {
                  for( String mainSel : mainSelector ) {
                      sel[t++] = mainSel.isEmpty() ? selector : mainSel + ' ' + selector;
                  }
              } else {
                  int off = t;
                  count = counts[j];
                  do {
                      int a = (t - off);
                      int idx2 = idx;
                      selector = base[j];
                      do {
                          int x = a % mainSelector.length;
                          selector = selector.substring( 0, idx2 ) + mainSelector[x] + selector.substring( idx2 + 1 );
                          a /= mainSelector.length;
                      } while( (idx2 = selector.lastIndexOf( '&', idx2 - 1 )) >= 0 );
                      sel[t++] = selector;
                  } while( (t - off) < count );
              }
          }
          return sel;
      }
docs: Merge the main selector together with base selector. The base selector can contain '&' as place holder for the main selector.
  @param mainSelector the parent selector
  @param base the current selector
  @return the resulting selector