public static <T> int upper_bound(Collection<? extends Comparable<T>> list, T d) {
		if (list == null || list.isEmpty()) {
			return -1;
		}
		
		int index = 0;
		for (Iterator<? extends Comparable<T>> it = list.iterator(); it.hasNext(); ) {
			Comparable<T> elem = it.next();
			if (elem.compareTo(d) > 0) {
				return index;
			}
			index++;
		}
		
		return -1;
	}