+ Added compare and info commands
This commit is contained in:
@@ -54,7 +54,7 @@ public class CommandShutdown extends Command
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
res.CallImmediate(LocStrings.Stub("ShutdownUnsafe"));// "`Shutting down and immediately and abandoning all threads without sync.`");
|
res.CallImmediate(LocStrings.Stub("ShutdownUnsafe"));// "``");
|
||||||
GlobalLog.Warn(LogFilter.Command, LocStrings.Lookup("ShutdownSafe"));
|
GlobalLog.Warn(LogFilter.Command, LocStrings.Lookup("ShutdownSafe"));
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package commands.benchmark;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import core.benchmark.BenchmarkCommand;
|
||||||
|
import core.benchmark.BenchmarkEntry;
|
||||||
|
import core.benchmark.BenchmarkInput;
|
||||||
|
import core.benchmark.BenchmarkManager;
|
||||||
|
|
||||||
|
public class BenchmarkCommandCompare extends BenchmarkCommand
|
||||||
|
{
|
||||||
|
public String OnRun(BenchmarkManager manager, BenchmarkInput input)
|
||||||
|
{
|
||||||
|
final String lineDelimiter = "\n";
|
||||||
|
String output = "";
|
||||||
|
String[] inputSplit = input.value.trim().split("\\s+");
|
||||||
|
|
||||||
|
if(inputSplit.length < 2)
|
||||||
|
return "You must to specify 2 models to compare!";
|
||||||
|
|
||||||
|
for(int i = 0; i < inputSplit.length; ++i)
|
||||||
|
{
|
||||||
|
if(i != 0)
|
||||||
|
output += lineDelimiter;
|
||||||
|
|
||||||
|
List<BenchmarkEntry> entries = manager.FindModel(inputSplit[i]);
|
||||||
|
|
||||||
|
if(entries.size() < 1)
|
||||||
|
output += "Couldn't find any models containing `" + inputSplit[i] + "`!";
|
||||||
|
|
||||||
|
output += BenchmarkCommandInfo.FormatInfo(entries.get(0));
|
||||||
|
output += lineDelimiter;
|
||||||
|
|
||||||
|
if(entries.size() > 1)
|
||||||
|
output += "_chose " + entries.get(0).model + " from " + entries.size() + " potential components. To see others, try the command `benchmark find " + inputSplit[i] +"`_)";
|
||||||
|
|
||||||
|
output += lineDelimiter;
|
||||||
|
output += "----------";
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,8 @@ import core.benchmark.*;
|
|||||||
|
|
||||||
public class BenchmarkCommandFind extends BenchmarkCommand
|
public class BenchmarkCommandFind extends BenchmarkCommand
|
||||||
{
|
{
|
||||||
final char lineDelimiter = '\n';
|
private final char lineDelimiter = '\n';
|
||||||
|
private final int listMax = 30;
|
||||||
|
|
||||||
public String OnRun(BenchmarkManager manager, BenchmarkInput input)
|
public String OnRun(BenchmarkManager manager, BenchmarkInput input)
|
||||||
{
|
{
|
||||||
@@ -19,7 +20,6 @@ public class BenchmarkCommandFind extends BenchmarkCommand
|
|||||||
{
|
{
|
||||||
output += "```" + lineDelimiter;
|
output += "```" + lineDelimiter;
|
||||||
int max = entries.size();
|
int max = entries.size();
|
||||||
final int listMax = 30;
|
|
||||||
|
|
||||||
boolean fencepost = true;
|
boolean fencepost = true;
|
||||||
for(int i = 0; i < entries.size() && i < listMax; ++i)
|
for(int i = 0; i < entries.size() && i < listMax; ++i)
|
||||||
@@ -33,7 +33,7 @@ public class BenchmarkCommandFind extends BenchmarkCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(max > listMax)
|
if(max > listMax)
|
||||||
output += "\n\nPlus " + (max - listMax) + " more items...";
|
output += lineDelimiter + lineDelimiter + "Plus " + (max - listMax) + " more items...";
|
||||||
|
|
||||||
output += "```";
|
output += "```";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package commands.benchmark;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import core.benchmark.BenchmarkCommand;
|
||||||
|
import core.benchmark.BenchmarkEntry;
|
||||||
|
import core.benchmark.BenchmarkInput;
|
||||||
|
import core.benchmark.BenchmarkManager;
|
||||||
|
|
||||||
|
public class BenchmarkCommandInfo extends BenchmarkCommand
|
||||||
|
{
|
||||||
|
static final String lineDelimiter = "\n";
|
||||||
|
|
||||||
|
public static String FormatInfo(BenchmarkEntry entry)
|
||||||
|
{
|
||||||
|
String output = "";
|
||||||
|
|
||||||
|
output += "`" + entry.brand + " " + entry.model + "`" + lineDelimiter;
|
||||||
|
output += "<" + entry.url + ">";
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String OnRun(BenchmarkManager manager, BenchmarkInput input)
|
||||||
|
{
|
||||||
|
String searchString = input.value.trim();
|
||||||
|
|
||||||
|
String output = "";
|
||||||
|
output += lineDelimiter;
|
||||||
|
|
||||||
|
List<BenchmarkEntry> entries = manager.FindModel(searchString);
|
||||||
|
|
||||||
|
if(entries.size() < 1)
|
||||||
|
output += "Couldn't find any models containing `" + searchString + "`!";
|
||||||
|
|
||||||
|
output += FormatInfo(entries.get(0));
|
||||||
|
output += lineDelimiter;
|
||||||
|
|
||||||
|
if(entries.size() > 1)
|
||||||
|
output += "_chose " + entries.get(0).model + " from " + entries.size() + " potential components. To see others, try the command `benchmark find " + searchString +"`_)";
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -35,6 +35,12 @@ public class LocStrings extends LocBase
|
|||||||
|
|
||||||
public static String Stub(String toStub)
|
public static String Stub(String toStub)
|
||||||
{
|
{
|
||||||
return instance.GetKey(toStub);
|
return Lookup(toStub);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Won't be picked up when scraping
|
||||||
|
public static String Lookup(String stubbedPreviously)
|
||||||
|
{
|
||||||
|
return instance.GetKey(stubbedPreviously);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,6 +17,8 @@ public class BenchmarkFramework
|
|||||||
this.benchmarkCommand = new HashMap<String, BenchmarkCommand>();
|
this.benchmarkCommand = new HashMap<String, BenchmarkCommand>();
|
||||||
|
|
||||||
RegisterCommand("find", new BenchmarkCommandFind());
|
RegisterCommand("find", new BenchmarkCommandFind());
|
||||||
|
RegisterCommand("compare", new BenchmarkCommandCompare());
|
||||||
|
RegisterCommand("info", new BenchmarkCommandInfo());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Runs a command if possible.
|
// Runs a command if possible.
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package core.benchmark;
|
package core.benchmark;
|
||||||
|
|
||||||
|
import utils.StringUtils;
|
||||||
|
|
||||||
// Lifted from an early iteration of RPGInput
|
// Lifted from an early iteration of RPGInput
|
||||||
public class BenchmarkInput
|
public class BenchmarkInput
|
||||||
{
|
{
|
||||||
@@ -17,7 +19,7 @@ public class BenchmarkInput
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
raw = raw.trim();
|
raw = raw.trim();
|
||||||
int whitespacePos = FindFirstWhitespace(raw);
|
int whitespacePos = StringUtils.FindFirstWhitespace(raw);
|
||||||
|
|
||||||
if(whitespacePos == -1)
|
if(whitespacePos == -1)
|
||||||
{
|
{
|
||||||
@@ -29,16 +31,6 @@ public class BenchmarkInput
|
|||||||
value = raw.substring(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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package core.rpg;
|
package core.rpg;
|
||||||
|
|
||||||
|
import utils.StringUtils;
|
||||||
|
|
||||||
public class RPGInput
|
public class RPGInput
|
||||||
{
|
{
|
||||||
public String raw;
|
public String raw;
|
||||||
@@ -16,7 +18,7 @@ public class RPGInput
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
raw = raw.trim();
|
raw = raw.trim();
|
||||||
int whitespacePos = FindFirstWhitespace(raw);
|
int whitespacePos = StringUtils.FindFirstWhitespace(raw);
|
||||||
|
|
||||||
if(whitespacePos == -1)
|
if(whitespacePos == -1)
|
||||||
{
|
{
|
||||||
@@ -27,16 +29,4 @@ public class RPGInput
|
|||||||
key = raw.substring(0, whitespacePos).trim();
|
key = raw.substring(0, whitespacePos).trim();
|
||||||
value = raw.substring(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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,4 +26,15 @@ public class StringUtils
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Finds first whitespace in the string
|
||||||
|
public static int FindFirstWhitespace(String str)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < str.length(); ++i)
|
||||||
|
{
|
||||||
|
if (Character.isWhitespace(str.charAt(i)))
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user