code: private Geometry makeLineStringValid(LineString lineString) {
          CoordinateSequence sequence = lineString.getCoordinateSequence();
          CoordinateSequence sequenceWithoutDuplicates = makeSequenceValid(sequence, false, false);
          GeometryFactory factory = lineString.getFactory();
          if (sequenceWithoutDuplicates.size() == 0) {
              // no valid point -> empty LineString
              return factory.createLineString(factory.getCoordinateSequenceFactory().create(0, sequence.getDimension()));
          } else if (sequenceWithoutDuplicates.size() == 1) {
              // a single valid point -> returns a Point
              if (preserveGeomDim) {
                  return factory.createLineString(factory.getCoordinateSequenceFactory().create(0, sequence.getDimension()));
              } else {
                  return factory.createPoint(sequenceWithoutDuplicates);
              }
          } else if (preserveDuplicateCoord) {
              return factory.createLineString(makeSequenceValid(sequence, true, false));
          } else {
              return factory.createLineString(sequenceWithoutDuplicates);
          }
      }
docs: Returns
  <ul>
  <li>an empty LineString if input CoordinateSequence has no valid
  point</li>
  <li>a Point if input CoordinateSequence has a single valid Point</li>
  </ul>
  makeLineStringValid keeps the original dimension of input sequence.
  
  @param lineString the LineString to make valid
  @return a valid LineString or a Point if lineString length equals 0