Some extra checks.

This commit is contained in:
Magnus Ulf 2015-05-06 17:07:30 +02:00 committed by Olof Larsson
parent 96e11336ef
commit be677085ac

View File

@ -1083,23 +1083,26 @@ public class MassiveCommand
public <T> T readArgAt(int idx) throws MassiveException
{
if ( ! this.hasArgSettingForIndex(idx)) throw new IllegalArgumentException(idx + " is out of range. ArgSettings size: " + this.getArgSettings().size());
if ( ! this.argIsSet(idx)) throw new IllegalArgumentException("Trying to access arg: " + idx + " but that is not set.");
String str = this.argAt(idx);
return this.readArgFrom(str, (AR<T>)this.getArgSettings().get(idx).getReader());
return this.readArgFrom(str, (AR<T>) this.getArgReader(idx));
}
@SuppressWarnings("unchecked")
public <T> T readArgAt(int idx, T defaultNotSet) throws MassiveException
{
if ( ! this.hasArgSettingForIndex(idx)) throw new IllegalArgumentException(idx + " is out of range. ArgSettings size: " + this.getArgSettings().size());
if ( ! this.argIsSet(idx)) return defaultNotSet;
String str = this.argAt(idx);
return this.readArgFrom(str, (AR<T>)this.getArgSettings().get(idx).getReader(), defaultNotSet);
return this.readArgFrom(str, (AR<T>)this.getArgReader(idx), defaultNotSet);
}
// Core Logic
public <T> T readArgFrom(AR<T> argReader) throws MassiveException
{
if (argReader == null) throw new IllegalArgumentException("argReader is null");
return this.readArgFrom(null, argReader);
}