static int calcCapacity(int currentArraySize, int index) {
    if (currentArraySize == 0) {
      currentArraySize = 16;
    }
    else {
      currentArraySize += currentArraySize / 5; // avoid overflow
    }
    if (index >= currentArraySize) {
      currentArraySize = index + index / 5; // avoid overflow
    }
    return currentArraySize;
  }
static int calcCapacity(int currentArraySize, int index)