Release version
This commit is contained in:
46
src/main/java/com/kasetoatz/dacl/options/IntOption.java
Normal file
46
src/main/java/com/kasetoatz/dacl/options/IntOption.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package com.kasetoatz.dacl.options;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.kasetoatz.dacl.options.validators.AbstractValidator;
|
||||
|
||||
public class IntOption extends AbstractInputOption<Integer>
|
||||
{
|
||||
public IntOption(String text, String key, Integer defaultValue, AbstractValidator<Integer> validator)
|
||||
{
|
||||
super(text, key, defaultValue, validator);
|
||||
}
|
||||
|
||||
public IntOption(String text, String key, Integer defaultValue)
|
||||
{
|
||||
super(text, key, defaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean predicate(String text)
|
||||
{
|
||||
if (text.isEmpty() || text.equals("-")) {
|
||||
return true;
|
||||
}
|
||||
try
|
||||
{
|
||||
Integer.parseInt(text);
|
||||
return true;
|
||||
}
|
||||
catch (NumberFormatException exc)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeListener(String text)
|
||||
{
|
||||
this.onChange((text.isEmpty() || text.equals("-")) ? 0 : Integer.parseInt(text));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer asPrimitive(JsonElement element)
|
||||
{
|
||||
return element.getAsInt();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user