code: public int nextItem(IPlaylist playlist, int itemIndex) {
          if (itemIndex < 0) {
              itemIndex = -1;
          }
          if (playlist.isRepeat()) {
              return itemIndex;
          }
          if (playlist.isRandom()) {
              int lastIndex = itemIndex;
              if (playlist.getItemSize() > 1) {
                  // continuously generate a random number
                  // until you get one that was not the last...
                  while (itemIndex == lastIndex) {
                      itemIndex = rand.nextInt(playlist.getItemSize());
                  }
              }
              return itemIndex;
          }
          int nextIndex = itemIndex + 1;
          if (nextIndex < playlist.getItemSize()) {
              return nextIndex;
          } else if (playlist.isRewind()) {
              return playlist.getItemSize() > 0 ? 0 : -1;
          } else {
              return -1;
          }
      }
docs: {@inheritDoc}