All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.venky.core.math.SpreadCalculator Maven / Gradle / Ivy

There is a newer version: 1.18
Show newest version
package com.venky.core.math;

import java.util.Comparator;

public class SpreadCalculator {
	private final Comparator ourComparator;
	public SpreadCalculator(){
		this(null);
	}
	public SpreadCalculator(final Comparator comparator){
		this.ourComparator = new Comparator() {

    		@Override
    		public int compare(T o1, T o2) {
    			if (comparator != null) {
            		return comparator.compare(o1, o2);
            	}
            	@SuppressWarnings("unchecked")
    			Comparable k1 = (Comparable) o1;
            	return k1.compareTo(o2);
    		}
    	};
	}
	
	private T min = null;
	private T max = null ;
	public void add(T item){
		if (min == null || ourComparator.compare(min, item) > 0){
			min = item;
		}
		if (max == null || ourComparator.compare(max, item) < 0) {
			max = item;
		}
	}
	public T min(){
		return min;
	}
	public T max(){
		return max;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy