public static int positiveMod(int m, int n) {
            int mod = m % n;
            if (mod < 0) mod += n;
            return mod;
        }
Shifts negative modulo results to the positive to always get a valid array index.
MediaPlayer-DASH/src/main/java/net/protyposis/android/mediaplayer/dash/SimpleRateBasedAdaptationLogic.java