class SubroutineDeclarationSmoosher implements IndexedSmoosher<String> {

    @Override
    public String smoosh(final int startingIndex, final List<String> list) {
        if (startingIndex < 0) {
            throw new IllegalArgumentException("Starting index cannot be negative.");
        }

        if (list == null) {
            throw new IllegalArgumentException("List cannot be null.");
        }

        if (list.isEmpty()) {
            throw new IllegalArgumentException("List cannot be empty.");
        }

        if (startingIndex >= list.size()) {
            throw new IllegalArgumentException("Starting index exceeds list size; index = "
                    + Integer.toString(startingIndex) + "; size = " + Integer.toString(list.size()));
        }

        final EtmPoint point = PointFactory.getPoint(getClass(), "smoosh(int, List)");
        try {
            endingIndex = startingIndex;

            final String firstLine = uncomment(list.get(startingIndex));
            if (isSubroutineDeclarationClose(firstLine)) {
                return firstLine;
            }

            final StringBuilder declarationBuilder = new StringBuilder(firstLine);
            boolean hasClose = false;
            int iterator = startingIndex + 1;
            for (final int size = list.size(); iterator < size; iterator++) {
                endingIndex = iterator;

                final String currentLine = uncomment(list.get(iterator));
                hasClose = isSubroutineDeclarationClose(currentLine);

                declarationBuilder.append(" ").append(currentLine.trim());

                if (hasClose) {
                    break;
                }
            }

            if (!hasClose) {
                throw new InvalidSubroutineException(
                        "Unable to find close to subroutine declaration: " + declarationBuilder.toString());
            }

            return declarationBuilder.toString();
        } finally {
            point.collect();
        }
    }

}