private static < T > void diagnoseLoop ( List < T > loop , String excpMsgPrf ) throws IllegalArgumentException { if ( loop == null ) { throw new IllegalArgumentException ( excpMsgPrf + "a polygon must contain at least one ring " + "(with each ring at least 4 points, including repeated closing vertex)" ) ; } // 4 vertices = 3 unique vertices for polygon + 1 end point which is same as start point if ( loop . size ( ) < 4 ) { throw new IllegalArgumentException ( excpMsgPrf + "a polygon ring must contain at least 4 points " + "(including repeated closing vertex)" ) ; } // check if the end points of the loop are equal if ( loop . get ( 0 ) . equals ( loop . get ( loop . size ( ) - 1 ) ) == false ) { throw new IllegalArgumentException ( excpMsgPrf + "closing points of ring are not equal: \"" + loop . get ( 0 ) . toString ( ) + "\" != \"" + loop . get ( loop . size ( ) - 1 ) . toString ( ) + "\"" ) ; } }
A helper function to validate the loop structure If loop is invalid it generates IllegalArgumentException exception