Пример #1
0
  @Override
  public final char charAt(int i) {
    if (i < 0 || i >= length()) {
      throw new IndexOutOfBoundsException("Wrong offset: " + i + "; count:" + length());
    }
    i += myStart;
    if (myOriginalSequence != null) return myOriginalSequence.charAt(i);
    final char result;
    if (hasDeferredChanges()) {
      TextChangesStorage storage = myDeferredChangesStorage.get();
      storage.getLock().lock();
      try {
        result = storage.charAt(myArray, i);
      } finally {
        storage.getLock().unlock();
      }
    } else {
      result = myArray[i];
    }

    if (myDebugDeferredProcessing && isDeferredChangeMode()) {
      char expected = myDebugArray.charAt(i);
      if (expected != result) {
        dumpDebugInfo(
            String.format(
                "Incorrect charAt() processing for index %d. Expected: '%c', actual: '%c'",
                i, expected, result));
      }
    }
    return result;
  }