code: public static Geometry updateZExtremities(Geometry geometry, double startZ, double endZ, boolean interpolate) {
          if(geometry == null){
              return null;
          }
          if (geometry instanceof LineString) {
              return force3DStartEnd((LineString) geometry, startZ, endZ, interpolate);
          } else if (geometry instanceof MultiLineString) {
              int nbGeom = geometry.getNumGeometries();
              LineString[] lines = new LineString[nbGeom];
              for (int i = 0; i < nbGeom; i++) {
                  LineString subGeom = (LineString) geometry.getGeometryN(i);
                  lines[i] = (LineString) force3DStartEnd(subGeom, startZ, endZ, interpolate);
              }
              return FACTORY.createMultiLineString(lines);
          } else {
              return null;
          }
      }
docs: Update the start and end Z values. If the interpolate is true the
  vertices are interpolated according the start and end z values.
  
  @param geometry
  @param startZ
  @param endZ
  @param interpolate
  @return