public NamePath withHead(String newHead){
  List<String> newPathPieces=new ArrayList<>();
  newPathPieces.addAll(pathPieces);
  newPathPieces.set(pathPieces.size() - 1,newHead);
  return new NamePath(newPathPieces);
}

public NamePath withHead ( String newHead ) { List < String > newPathPieces = new ArrayList < > ( ) ; newPathPieces . addAll ( pathPieces ) ; newPathPieces . set ( pathPieces . size ( ) - 1 , newHead ) ; return new NamePath ( newPathPieces ) ; }
create a new namepath where the head ( the last piece ) is replaced with the given newhead .
