public static <T extends Comparable<T>> int getAddIndex(T element, List<T> list)
    {
        if (list.size() == 0)
        {
            return 0;
        }
        
        int low = 0;
        int high = list.size() - 1;
        int mid;
        
        while (high >= low)
        {
            mid = (low + high) / 2;
            int comparison = list.get(mid).compareTo(element);
            if (comparison > 0)         // mid > element
            {
                if (mid == 0)
                {
                    return mid;         // element < first element < all other elements
                                // thus, add at index 0
                }
                else if (list.get(mid - 1).compareTo(element) < 0)
                {
                    return mid;         // mid > element and mid - 1 < element
                                // thus, add at mid
                }
                high = mid - 1;
            }
            else if (comparison < 0)    // mid < element
            {
                if (mid == list.size() - 1)
                {
                    return mid + 1;     // element > last element > all other elements
                                    // thus add at the last index (list.size())
                }
                else if (list.get(mid + 1).compareTo(element) > 0)
                {
                    return mid + 1;     // element > mid, mid + 1 > element
                                    // thus, add at mid + 1
                }
                low = mid + 1;
            }
            else
            // mid = element
            {
                return mid;
            }
        }
        
        return -1; // should never happen unless the list is not sorted
    }