Document exceptions. Use IllegalArgumentException instead of assert. Throw IllegalArgumentException for empty arrays.