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