int (int[] startOffsets, int[] endOffsets, final String text) { int fragmentCount = startOffsets.length; assert fragmentCount > 0; int totalLength = fragmentCount - 1; // number of line breaks inserted between fragments for (int i = 0; i < fragmentCount; i++) { totalLength += endOffsets[i] - startOffsets[i]; } if (totalLength < text.length() && (text.length() + 1) % fragmentCount == 0) { return (text.length() + 1) / fragmentCount - 1; } else { return -1; } }