org.solovyev.common.text.NumberParser Maven / Gradle / Ivy
/*
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
* For more information, please, contact [email protected]
* or visit http://se.solovyev.org
*/
package org.solovyev.common.text;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* User: serso
* Date: 9/26/11
* Time: 11:07 PM
*/
public class NumberParser implements Parser {
@NotNull
private final Class clazz;
public NumberParser(@NotNull Class clazz) {
this.clazz = clazz;
}
@Override
public T parseValue(@Nullable String value) throws IllegalArgumentException {
T result;
if (value != null) {
if (this.clazz.equals(Integer.class)) {
result = (T) Integer.valueOf(value);
} else if (this.clazz.equals(Float.class)) {
result = (T) Float.valueOf(value);
} else if (this.clazz.equals(Long.class)) {
result = (T) Long.valueOf(value);
} else if (this.clazz.equals(Double.class)) {
result = (T) Double.valueOf(value);
} else {
throw new UnsupportedOperationException(this.clazz + " is not supported!");
}
} else {
result = null;
}
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy