+ Added benchmark find command and internal structure
This commit is contained in:
@@ -4,9 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
import commands.*;
|
||||
import core.benchmark.BenchmarkManager;
|
||||
import core.lua.PluginManager;
|
||||
import dataStructures.*;
|
||||
import net.dv8tion.jda.core.entities.Emote;
|
||||
@@ -42,10 +40,7 @@ public class ObjectBuilderFactory
|
||||
|
||||
// Plugin manager
|
||||
private static PluginManager pluginManager;
|
||||
|
||||
// Userbenchmark csv manager instance
|
||||
private static BenchmarkManager benchmarkManager;
|
||||
|
||||
|
||||
// Localization classes - these are singletons, but should be initialized before almost all other
|
||||
// things so their inclusion in the factory is to ensure they're started at the correct time.
|
||||
@SuppressWarnings("unused") private static LocStrings locStrings;
|
||||
@@ -438,17 +433,7 @@ public class ObjectBuilderFactory
|
||||
|
||||
return pluginManager;
|
||||
}
|
||||
|
||||
public static BenchmarkManager ConstructBenchmarkManager()
|
||||
{
|
||||
LazyInit();
|
||||
|
||||
if(benchmarkManager == null)
|
||||
benchmarkManager = new BenchmarkManager();
|
||||
|
||||
return benchmarkManager;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////
|
||||
// Utility Methods //
|
||||
/////////////////////
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package core.rpg;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
// This is for testing only, and generally doesn't run unless it's specified.
|
||||
public class RPGMain
|
||||
{
|
||||
private static RPGFramework framework;
|
||||
|
||||
Reference in New Issue
Block a user