static int wrap(int value, int max)
    {
        int result = value % max;
        if (result < 0) 
        {
            return result + (max > 0 ? max : - max);        
        }
        return result;
    }
static int wrap ( int value , int max ) { int result = value % max ; if ( result < 0 ) { return result + ( max > 0 ? max : - max ) ; } return result ; }
Wrap the given value to be in [0,|max|)

@param value The value
@param max The maximum value
@return The wrapped value
@throws ArithmeticException If the given maximum value is 0