org.mentalog.config.BytesConfigParam Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of menta-log Show documentation
Show all versions of menta-log Show documentation
A log library that embraces the kiss principle.
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);
}
}