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

panda.util.Percent Maven / Gradle / Ivy

Go to download

Panda Core is the core module of Panda Framework, it contains commonly used utility classes similar to apache-commons.

There is a newer version: 1.8.0
Show newest version
package panda.util;

/**
 * Percent
 * 
 */
public class Percent {
	/**
	 * DEFAULT_MIN = 1;
	 */
	public static int DEFAULT_MIN = 1;
	
	/**
	 * DEFAULT_MAX = 100;
	 */
	public static int DEFAULT_MAX = 100;
	
	/**
	 * DEFAULT_STEP = 1;
	 */
	public static int DEFAULT_STEP = 1;
	
	protected long min;
	protected long max;
	protected long step;
	protected long value;
	
	/**
	 * constructor
	 */
	public Percent() {
		min = DEFAULT_MIN;
		max = DEFAULT_MAX;
		step = DEFAULT_STEP;
		value = min;
	}

	/**
	 * @return max
	 */
	public long getMax() {
		return max;
	}

	/**
	 * @param max max
	 */
	public void setMax(long max) {
		this.max = max;
	}

	/**
	 * @return min
	 */
	public long getMin() {
		return min;
	}

	/**
	 * @param min min
	 */
	public void setMin(long min) {
		this.min = min;
	}

	/**
	 * @return step
	 */
	public long getStep() {
		return step;
	}

	/**
	 * @param step step
	 */
	public void setStep(long step) {
		this.step = step;
	}
	
	/**
	 * step it
	 */
	public void stepIt() {
		setValue(value + step);
	}
	
	/**
	 * @return value
	 */
	public long getValue() {
		return value;
	}

	/**
	 * @param value value
	 */
	public void setValue(long value) {
		this.value = value > max ? max : value;
	}

	/**
	 * @return percent
	 */
	public int getPercent() {
		return (int)((float)(value - min) * 100.00 / (max - min));
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy