+ Added benchmark find command and internal structure

This commit is contained in:
Matthew Cech
2019-05-05 15:56:55 -07:00
parent 645e632dcb
commit 40d4812e2a
13 changed files with 185 additions and 39 deletions
+8
View File
@@ -0,0 +1,8 @@
package core.benchmark;
public abstract class BenchmarkCommand {
public BenchmarkCommand() { }
// OVERRIDE ME
public abstract String OnRun(BenchmarkManager manager, BenchmarkInput input);
}
@@ -0,0 +1,49 @@
package core.benchmark;
import java.util.HashMap;
import commands.benchmark.*;
// Based on general core structure, this registers sub-commands and keeps tabs on them.
public class BenchmarkFramework
{
// Variables
public HashMap<String, BenchmarkCommand> benchmarkCommand;
public BenchmarkManager benchmarkManager;
// Constructor and command registration
public BenchmarkFramework()
{
this.benchmarkManager = new BenchmarkManager();
this.benchmarkCommand = new HashMap<String, BenchmarkCommand>();
RegisterCommand("find", new BenchmarkCommandFind());
}
// Runs a command if possible.
public String Run(String args)
{
BenchmarkInput input = new BenchmarkInput(args);
return ExecuteCommand(input.key, input);
}
// Registers a command
private void RegisterCommand(String commandName, BenchmarkCommand command)
{
commandName = commandName.toLowerCase();
if(benchmarkCommand.put(commandName, command) != null)
BenchmarkLog.Log("Multiple registration of a command with name '" + commandName + "'!");
BenchmarkLog.Log("Registered " + commandName);
}
// Executes a command with the specified name, and provides it with some extra input data.
private String ExecuteCommand(String name, BenchmarkInput input)
{
BenchmarkCommand command = benchmarkCommand.get(name.toLowerCase());
if(command != null && benchmarkManager != null)
return command.OnRun(benchmarkManager, input);
return null;
}
}
+44
View File
@@ -0,0 +1,44 @@
package core.benchmark;
// Lifted from an early iteration of RPGInput
public class BenchmarkInput
{
public String raw;
public String key;
public String value;
public BenchmarkInput(String raw)
{
this.raw = raw;
this.key = "";
this.value = "";
if(raw == null || raw.length() == 0)
return;
raw = raw.trim();
int whitespacePos = FindFirstWhitespace(raw);
if(whitespacePos == -1)
{
key = raw;
return;
}
key = raw.substring(0, whitespacePos).trim();
value = raw.substring(whitespacePos).trim();
}
// Finds first whitespace in the string
private int FindFirstWhitespace(String str)
{
for (int i = 0; i < str.length(); ++i)
{
if (Character.isWhitespace(str.charAt(i)))
return i;
}
return -1;
}
}