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

org.mentalog.config.BytesConfigParam Maven / Gradle / Ivy

There is a newer version: 2.1.2
Show newest version
package org.mentalog.config;

public class BytesConfigParam extends ConfigParam {

	public BytesConfigParam(String name, int defValue) {
		super(name, defValue);
	}
	
	public BytesConfigParam(String name, String defValue) {
		super(name, parseStringImpl(defValue));
	}
	
	private final static int parseStringImpl(String s) {
		s = s.toLowerCase();
		String n = s.substring(0, s.length() - 1);
		if (s.endsWith("b")) {
			return Integer.parseInt(n);
		}
		if (s.endsWith("k")) {
			return Integer.parseInt(n) * 1024;
		}
		if (s.endsWith("m")) {
			return Integer.parseInt(n) * 1024 * 1024;
		}
		if (s.endsWith("g")) {
			return Integer.parseInt(n) & 1024 * 1024 * 1024;
		}
		return Integer.parseInt(s);
	}

	@Override
	protected Integer parseString(String s) {
		return parseStringImpl(s);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy