Skip to content
This repository was archived by the owner on Jul 23, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/net/fornwall/eclipsecoder/stats/CodeGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public abstract class CodeGenerator {
public static final String TAG_METHODNAME = "$METHODNAME$";
public static final String TAG_METHODPARAMS = "$METHODPARAMS$";
public static final String TAG_RETURNTYPE = "$RETURNTYPE$";
public static final String TAG_MODULO = "$MODULO$";

protected ProblemStatement problemStatement;

Expand Down Expand Up @@ -70,7 +71,8 @@ public String getSolutionStub(String codeTemplate) {
.replaceAll(Pattern.quote(TAG_METHODNAME), problemStatement.getSolutionMethodName())
.replaceAll(Pattern.quote(TAG_METHODPARAMS), getMethodParamsString())
.replaceAll(Pattern.quote(TAG_DUMMYRETURN), getDummyReturnString())
.replaceAll(Pattern.quote(TAG_RETURNTYPE), getTypeString(problemStatement.getReturnType()));
.replaceAll(Pattern.quote(TAG_RETURNTYPE), getTypeString(problemStatement.getReturnType()))
.replaceAll(Pattern.quote(TAG_MODULO), getModuloString());
}

/**
Expand All @@ -88,4 +90,13 @@ public String getSolutionStub(String codeTemplate) {
* @return The matching language type.
*/
public abstract String getTypeString(Class<?> type);

/**
* Returns the modulo string, appropriate for the language.
*
* @return modulo string, or empty string if none or not implemented
*/
public String getModuloString() {
return "";
}
}
43 changes: 40 additions & 3 deletions src/net/fornwall/eclipsecoder/stats/ProblemStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import net.fornwall.eclipsecoder.util.Utilities;

Expand Down Expand Up @@ -138,6 +140,8 @@ public static Object parseType(Class<?> c, String text) {
private Class<?> returnType;

private List<TestCase> testCases = new ArrayList<TestCase>();

private String modulo;

public String getHtmlDescription() {
return htmlDescription;
Expand Down Expand Up @@ -173,6 +177,7 @@ public boolean isInContest() {

public void setHtmlDescription(String htmlDescription) {
this.htmlDescription = htmlDescription;
modulo = extractModulo(htmlDescription);
}

public void setInContest(boolean inContest) {
Expand Down Expand Up @@ -218,11 +223,43 @@ public String getMethodName() {
public void setMethodName(String methodName) {
this.methodName = methodName;
}

@Override

public String getModulo() {
return modulo;
}

/**
* Borrowed from Greed plugin.
*
* @param intro problem description
*
* @return extracted modulo or null if none
*/
private String extractModulo(String intro)
{
/* d, modulo 1,000,000,007.</ */
String pattern = "mod(ulo)? (\\d[\\d,\\.]*\\d)";
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(intro);
String res = null;
// The modulo tends to be at the end of the statement. If there were
// multiple modulo 1,XXX,XXX,XXX statements, it is better to get the last.
while (m.find( )) {
try {
res = "" +
java.text.NumberFormat.
getNumberInstance(java.util.Locale.US).parse(m.group(2));
} catch (Exception e) {
}
}
return res;
}

@Override
public String toString() {
return "CLASS: " + getSolutionClassName() + "\n" + "METHOD: " + getSolutionMethodName() + "\n"
+ "RETURNVALUE: " + getReturnType() + "\n" + "PARAMETERS: " + getParameterTypes() + "\n";
+ "RETURNVALUE: " + getReturnType() + "\n" + "PARAMETERS: " + getParameterTypes() + "\n"
+ "MODULO: " + getModulo();
}

/**
Expand Down