Source:
<code>private void add(Point point) throws IllegalStateException { if (done) { <START> throw new IllegalStateException("Computation of spherical excess has already been performed"); <END> } double phi = toRadians(point.getY()); double tan = Math.tan(phi / 2); double longitude = toRadians(point.getX()); if (longitude == previousLongitude && phi == previousPhi) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Polygon is not valid: it has two identical consecutive vertices"); } double deltaLongitude = longitude - previousLongitude; sphericalExcess += 2 * Math.atan2(Math.tan(deltaLongitude / 2) * (previousTan + tan), 1 + previousTan * tan); double cos = Math.cos(phi); double sin = Math.sin(phi); double sinOfDeltaLongitude = Math.sin(deltaLongitude); double cosOfDeltaLongitude = Math.cos(deltaLongitude); double y = sinOfDeltaLongitude * cos; double x = previousCos * sin - previousSin * cos * cosOfDeltaLongitude; double initialBearing = (Math.atan2(y, x) + TWO_PI) % TWO_PI; double finalY = -sinOfDeltaLongitude * previousCos; double finalX = previousSin * cos - previousCos * sin * cosOfDeltaLongitude; double finalBearing = (Math.atan2(finalY, finalX) + PI) % TWO_PI; if (firstPoint) { firstInitialBearing = initialBearing; firstPoint = false; } else { courseDelta += (initialBearing - previousFinalBearing + THREE_PI) % TWO_PI - PI; } courseDelta += (finalBearing - initialBearing + THREE_PI) % TWO_PI - PI; previousFinalBearing = finalBearing; previousCos = cos; previousSin = sin; previousPhi = phi; previousTan = tan; previousLongitude = longitude; }</code><technical_language>checkState(!done, "Computation of spherical excess is complete")</technical_language>

Target:
private void add(Point point) throws IllegalStateException { checkState(!done, "Computation of spherical excess is complete"); double phi = toRadians(point.getY()); double tan = Math.tan(phi / 2); double longitude = toRadians(point.getX()); if (longitude == previousLongitude && phi == previousPhi) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Polygon is not valid: it has two identical consecutive vertices"); } double deltaLongitude = longitude - previousLongitude; sphericalExcess += 2 * Math.atan2(Math.tan(deltaLongitude / 2) * (previousTan + tan), 1 + previousTan * tan); double cos = Math.cos(phi); double sin = Math.sin(phi); double sinOfDeltaLongitude = Math.sin(deltaLongitude); double cosOfDeltaLongitude = Math.cos(deltaLongitude); double y = sinOfDeltaLongitude * cos; double x = previousCos * sin - previousSin * cos * cosOfDeltaLongitude; double initialBearing = (Math.atan2(y, x) + TWO_PI) % TWO_PI; double finalY = -sinOfDeltaLongitude * previousCos; double finalX = previousSin * cos - previousCos * sin * cosOfDeltaLongitude; double finalBearing = (Math.atan2(finalY, finalX) + PI) % TWO_PI; if (firstPoint) { firstInitialBearing = initialBearing; firstPoint = false; } else { courseDelta += (initialBearing - previousFinalBearing + THREE_PI) % TWO_PI - PI; } courseDelta += (finalBearing - initialBearing + THREE_PI) % TWO_PI - PI; previousFinalBearing = finalBearing; previousCos = cos; previousSin = sin; previousPhi = phi; previousTan = tan; previousLongitude = longitude; }