@Override public int getIndexOffset(int index) { if (index < 0 || index > length) { throw new StringIndexOutOfBoundsException("String index: " + index + " out of range: 0, " + length()); } if (index == length) { if (length == 0) { throw new StringIndexOutOfBoundsException("String index: " + index + " out of range: 0, " + length()); } int offset = baseOffsets[baseStartOffset + index - 1]; if (offset < 0) { return -1; } else { return offset + 1; } } int offset = baseOffsets[baseStartOffset + index]; return offset < 0 ? -1 : offset; }
@Override public char charAt(int index) { if (index < 0 || index >= length) { throw new StringIndexOutOfBoundsException("String index: " + index + " out of range: 0, " + length()); } int offset = baseOffsets[baseStartOffset + index]; if (offset < 0) { /* KLUDGE: allows having characters which are not from original base sequence but with the only penalty for charAt access being an extra indirection, which is a small price to pay for having the flexibility of adding out of context text to the based sequence. */ return nonBaseChars[-offset - 1]; } return baseSeq.charAt(offset); }
@Override public int getIndexOffset(int index) { if (index < 0 || index > length) { throw new StringIndexOutOfBoundsException("String index: " + index + " out of range: 0, " + length()); } if (index == length) { if (length == 0) { throw new StringIndexOutOfBoundsException("String index: " + index + " out of range: 0, " + length()); } int offset = baseOffsets[baseStartOffset + index - 1]; if (offset < 0) { return -1; } else { return offset + 1; } } int offset = baseOffsets[baseStartOffset + index]; return offset < 0 ? -1 : offset; }
@Override public char charAt(int index) { if (index < 0 || index >= length) { throw new StringIndexOutOfBoundsException("String index: " + index + " out of range: 0, " + length()); } int offset = baseOffsets[baseStartOffset + index]; if (offset < 0) { /* KLUDGE: allows having characters which are not from original base sequence but with the only penalty for charAt access being an extra indirection, which is a small price to pay for having the flexibility of adding out of context text to the based sequence. */ return nonBaseChars[-offset - 1]; } return baseSeq.charAt(offset); }