diff --git a/src/net/fornwall/eclipsecoder/stats/CodeGenerator.java b/src/net/fornwall/eclipsecoder/stats/CodeGenerator.java index e08b20e..f3fa619 100644 --- a/src/net/fornwall/eclipsecoder/stats/CodeGenerator.java +++ b/src/net/fornwall/eclipsecoder/stats/CodeGenerator.java @@ -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; @@ -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()); } /** @@ -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 ""; + } } diff --git a/src/net/fornwall/eclipsecoder/stats/ProblemStatement.java b/src/net/fornwall/eclipsecoder/stats/ProblemStatement.java index 59be975..97c86bc 100644 --- a/src/net/fornwall/eclipsecoder/stats/ProblemStatement.java +++ b/src/net/fornwall/eclipsecoder/stats/ProblemStatement.java @@ -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; @@ -138,6 +140,8 @@ public static Object parseType(Class c, String text) { private Class returnType; private List testCases = new ArrayList(); + + private String modulo; public String getHtmlDescription() { return htmlDescription; @@ -173,6 +177,7 @@ public boolean isInContest() { public void setHtmlDescription(String htmlDescription) { this.htmlDescription = htmlDescription; + modulo = extractModulo(htmlDescription); } public void setInContest(boolean inContest) { @@ -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.