How to modify a specific segment of a polyline

A polyline is composed of one or more paths (part) and a path (part) is formed of one or more segments.

Modifying a specific segment of a polyline

The following are the steps to modify a polyline segment:
  1. Query interface (QI) the polyline for IHitTest and use the HitTest method (esriGeometryPartBoundary option).
  2. QI the polyline for IGeometryCollection.
  3. Use the geometry property with the part index returned by the HitTest to get the path containing the point to modify.
  4. QI the path for ISegmentCollection.
  5. Use the segment property with the segment index returned by the HitTest (get a reference to the segment).
  6. Modify the segment.
In the following code example, HitTest of the IHitTest interface is used to locate the indexes of the part and the segment that needs to be modified. When found, ITransform2D is used to move the segment:
static void modifyOneSegmentOfAPolyline()throws Exception{
    IGeometryCollection geomColl =
    IPolyline polyline = (IPolyline)geomColl;
    IHitTest hitTest = (IHitTest)geomColl;
    IPoint point = polyline.getFromPoint();
    double dr = 1;
    IPoint pHit = new Point();
    double[] dht = new double[1];
    int[] lPart = new int[1], lSeg = new int[1];
    boolean[] bright = new boolean[1];
    hitTest.hitTest(point, dr, esriGeometryHitPartType.esriGeometryPartVertex, pHit,
        dht, lPart, lSeg, bright);
    ISegmentCollection pPathColl = (ISegmentCollection)geomColl.getGeometry(lPart[0])
    ITransform2D pTrans2D = (ITransform2D)pPathColl.getSegment(lSeg[0]);
    pTrans2D.move( - 10, 0);
    //Call the next line to update the polyline