package io.domisum.lib.auxiliumlib.contracts;

import io.domisum.lib.auxiliumlib.annotations.API;

import java.util.Collection;

public interface SmartComparable<T>
	extends Comparable<T>
{
	
	@API
	default boolean isLessThan(T other)
	{
		return compareTo(other) < 0;
	}
	
	@API
	default boolean isLessThanOrEqual(T other)
	{
		return compareTo(other) <= 0;
	}
	
	@API
	default boolean isEqual(T other)
	{
		return compareTo(other) == 0;
	}
	
	@API
	default boolean isGreaterThanOrEqual(T other)
	{
		return compareTo(other) >= 0;
	}
	
	@API
	default boolean isGreaterThan(T other)
	{
		return compareTo(other) > 0;
	}
	
	
	@API
	static <T extends SmartComparable<T>> T max(T a, T b)
	{
		return a.isLessThan(b) ? b : a;
	}
	
	@API
	static <T extends SmartComparable<T>> T min(T a, T b)
	{
		return b.isLessThan(b) ? b : a;
	}
	
	@API
	static <T extends SmartComparable<T>> T max(Collection<T> collection)
	{
		if(collection.isEmpty())
			throw new IllegalArgumentException("Can't get maximum from empty collection");
		
		T max = null;
		for(T t : collection)
			if(max == null || t.isGreaterThan(max))
				max = t;
		
		return max;
	}
	
	@API
	static <T extends SmartComparable<T>> T min(Collection<T> collection)
	{
		if(collection.isEmpty())
			throw new IllegalArgumentException("Can't get minimum from empty collection");
		
		T min = null;
		for(T t : collection)
			if(min == null || t.isLessThan(min))
				min = t;
		
		return min;
	}
	
}

@@ -185,16 +185,31 @@
 %3CT%3E%0A%7B%0A%09%0A
+%09// COMPARISON%0A
 %09@API%0A%09d
@@ -632,16 +632,898 @@
 %0A%09%7D%0A%09%0A%09%0A
+%09// ALL COMPARISON%0A%09@API%0A%09default boolean isLessThanAll(Collection%3C? extends T%3E collection)%0A%09%7B%0A%09%09for(T t : collection)%0A%09%09%09if(!isLessThan(t))%0A%09%09%09%09return false;%0A%09%09%0A%09%09return true;%0A%09%7D%0A%09%0A%09@API%0A%09default boolean isLessThanOrEqualAll(Collection%3C? extends T%3E collection)%0A%09%7B%0A%09%09for(T t : collection)%0A%09%09%09if(!isLessThanOrEqual(t))%0A%09%09%09%09return false;%0A%09%09%0A%09%09return true;%0A%09%7D%0A%09%0A%09@API%0A%09default boolean isEqualAll(Collection%3C? extends T%3E collection)%0A%09%7B%0A%09%09for(T t : collection)%0A%09%09%09if(!isEqual(t))%0A%09%09%09%09return false;%0A%09%09%0A%09%09return true;%0A%09%7D%0A%09%0A%09@API%0A%09default boolean isGreaterThanOrEqualAll(Collection%3C? extends T%3E collection)%0A%09%7B%0A%09%09for(T t : collection)%0A%09%09%09if(!isGreaterThanOrEqual(t))%0A%09%09%09%09return false;%0A%09%09%0A%09%09return true;%0A%09%7D%0A%09%0A%09@API%0A%09default boolean isGreaterThanAll(Collection%3C? extends T%3E collection)%0A%09%7B%0A%09%09for(T t : collection)%0A%09%09%09if(!isGreaterThan(t))%0A%09%09%09%09return false;%0A%09%09%0A%09%09return true;%0A%09%7D%0A%09%0A%09%0A%09// MIN MAX%0A
 %09@API%0A%09s

Add all comparison