id stringlengths 36 36 | text stringlengths 1 1.25M |
|---|---|
43fb4984-c61e-4bbe-a493-3e8b245c422d | @Test
public void testMultipleTags() {
ArrayList<String> comments = new ArrayList<String>();
comments.add("first");
comments.add("one");
comments.add("@author me");
comments.add("@description second");
comments.add("one");
comments.add("@author you");
Model m = new Model("", comments);
assertEquals("author", "me you", m.getAuthor());
assertEquals("description", "first one second one", m.getDescription());
} |
6d9eaf31-81b9-4e5d-b3a2-2067034602e5 | @Test
public void testEmptyPreTag() {
ArrayList<String> comments = new ArrayList<String>();
comments.add("before");
comments.add("<pre>");
comments.add("</pre>");
comments.add("after");
Model m = new Model("", comments);
assertEquals("description", "before <pre>\n</pre> after", m.getDescription());
} |
60ac1ca1-0072-4202-af88-c5b20d4139e4 | @Test
public void testNonEmptyPreTag() {
ArrayList<String> comments = new ArrayList<String>();
comments.add("<pre>");
comments.add("* // a sample class");
comments.add(" void foo() { ");
comments.add(" return;");
comments.add(" }");
comments.add("</pre>");
Model m = new Model("", comments);
assertEquals("description", "<pre>\n // a sample class\nvoid foo() {\nreturn;\n}\n</pre>", m.getDescription());
} |
a3d16c5b-4dd9-41ac-971d-d7ad46a2bd29 | private void assertBlankComment(Model m) {
assertEquals("blank description", "", m.getDescription());
assertEquals("blank author", "", m.getAuthor());
assertEquals("blank date", "", m.getDate());
assertEquals("blank returns", "", m.getReturns());
assertEquals("blank see", "", m.getSee());
assertEquals("blank params", 0, m.getParams().size());
assertEquals("blank throws", 0, m.getThrows().size());
} |
4879304d-e798-45d5-a916-a4e04f84b9db | public void testNullPath() {
new FileManager(null);
} |
933e6768-a029-4da9-824e-54675bf0edfa | @Test
public void testValidPath() {
assertEquals("current folder", ".", new FileManager("").path);
assertEquals("current folder", ".", new FileManager(" \t").path);
assertEquals("current folder", ".", new FileManager(".").path);
assertEquals("current folder", "..", new FileManager(" .. ").path);
assertEquals("current folder", "junk", new FileManager("junk").path);
} |
93f8c54e-8957-4e81-b1a2-0b6a29b081b9 | @Test (expected = NullPointerException.class)
public void testCreateDocsWithNullModels() {
new FileManager("").createDocs(null, "", "");
} |
d9e0a0b4-70d0-48db-90f7-b1b5940533f1 | @Test (expected = NullPointerException.class)
public void testCreateDocsWithNullDetail() {
new FileManager("").createDocs(new ArrayList<ClassModel>(), null, "");
} |
5c78e28c-c647-4d88-8ea5-d75c997a6b60 | @Test (expected = NullPointerException.class)
public void testCreateDocsWithNullContents() {
new FileManager("").createDocs(new ArrayList<ClassModel>(), "", null);
} |
88152b38-8f0a-4614-9ee3-6b5748c9823a | @Test
public void testGetName() {
ArrayList<String> comments = new ArrayList<String>();
PropertyModel m = new PropertyModel("", comments);
assertEquals("", m.getName());
m = new PropertyModel(" ", comments);
assertEquals("", m.getName());
m = new PropertyModel("\t", comments);
assertEquals("", m.getName());
m = new PropertyModel(" private static int whatever junk a", comments);
assertEquals("a", m.getName());
m = new PropertyModel(" enum b", comments);
assertEquals("b", m.getName());
m = new PropertyModel("String[] c", comments);
assertEquals("c", m.getName());
m = new PropertyModel("int d", comments);
assertEquals("d", m.getName());
m = new PropertyModel(" int e ", comments);
assertEquals("e", m.getName());
m = new PropertyModel("f", comments);
assertEquals("f", m.getName());
m = new PropertyModel(" g", comments);
assertEquals("g", m.getName());
m = new PropertyModel("h ", comments);
assertEquals("h", m.getName());
} |
75eb02cb-a462-49ce-9d90-16dc7282cdd3 | @Test
public void testGetName() {
ArrayList<String> comments = new ArrayList<String>();
assertEquals("", new MethodModel("", comments).getName());
assertEquals("", new MethodModel(" ", comments).getName());
assertEquals("", new MethodModel("\t", comments).getName());
assertEquals("a", new MethodModel(" private static int whatever junk a() {", comments).getName());
assertEquals("b", new MethodModel(" void b ( params... )", comments).getName());
assertEquals("c", new MethodModel("String[] c(", comments).getName());
assertEquals("d", new MethodModel("int d ", comments).getName());
assertEquals("e", new MethodModel(" int e", comments).getName());
assertEquals("f", new MethodModel("f", comments).getName());
assertEquals("g_2", new MethodModel(" g_2 ", comments).getName());
} |
6802d2b3-890d-45d2-846e-af1006d800a4 | public int compare(Model o1, Model o2) {
return o1.getName().compareToIgnoreCase(o2.getName());
} |
56dce878-49c8-4626-80a8-463fcc013d93 | protected Model(String nameLine, ArrayList<String> comments) {
SfApexDoc.assertPrecondition(null != comments);
setNameLine(nameLine);
parseComments(comments);
} |
bfc8d203-64d1-438a-a934-9d1fc2edbf41 | public String getName() {
SfApexDoc.assertPrecondition(false);
return null;
} |
ad702c00-d26d-418d-86a5-cee380d11612 | public String getNameLine() {
return nameLine;
} |
77d06fa7-88d6-4052-bd51-f16c41b346b6 | public void setNameLine(String nameLine) {
SfApexDoc.assertPrecondition(null != nameLine);
SfApexDoc.assertPrecondition(nameLine.isEmpty() ||
(!Character.isWhitespace(nameLine.charAt(0)) &&
!Character.isWhitespace(nameLine.charAt(nameLine.length()-1))));
this.nameLine = nameLine;
} |
c1ddca57-e92b-477d-a952-af4bc929286e | public String getDescription() {
return description;
} |
305e5871-4c4f-4f00-887b-06735780daa6 | public String getAuthor() {
return author;
} |
09222211-7ef4-4cb1-95f9-a43679af0541 | public String getDate() {
return date;
} |
ec7be499-311c-4e82-8c37-9dec42b2998c | public String getReturns() {
return returns;
} |
073e9fa5-f79c-47d4-93ea-4a5338dba96a | public String getSee() {
return see;
} |
1d8a8e49-68ad-4578-bffc-49120072b540 | public String getSince() {
return since;
} |
6b72cc17-6c64-4919-84eb-da919c11e115 | public String getVersion() {
return version;
} |
bfad1d68-a8ee-48d3-9d06-445d31b50d69 | public String getHistory() {
return history;
} |
bea314fe-9b0c-4e2d-866e-bfd7bc88e7e8 | public ArrayList<String> getParams() {
return params;
} |
26cb5aea-c3d0-4fc9-ade3-1571fcbe2e7b | public ArrayList<String> getThrows() {
return except;
} |
7424bc62-aed1-4f23-8f96-fa44b4b5901f | public String getThrowsAsString() {
String result = "";
for (String x : except) {
result += "<br/>throws " + x;
}
return result;
} |
290c87d7-19b5-4b78-91b8-2da770e51150 | public void addLinks() {
SfApexDoc.assertPrecondition(!linksAdded);
setNameLine(addLinks(nameLine));
see = addLinks(see);
for (Integer i = 0; i < except.size(); ++i) {
except.set(i, addLinks(except.get(i)));
}
linksAdded = true;
} |
d641ec24-4c99-464f-8efd-2b3707628ff4 | protected void addType(String name, String link) {
typeLinks.put(name.toLowerCase(), link.toLowerCase());
} |
86d95432-23de-49f0-9e75-222df89d5b9c | private String addLinks(String text) {
String result = text;
if (!result.isEmpty()) {
// HTML-encode the string
result = result.replace("<", "<").replace(">", ">");
// replace words with their links, if we know them.
// splitting into words breaks on '.', so replace them temporarily, so that
// we can process class.nestedClass names
for (String w : result.replace(".","___").split("[^\\w]")) {
w = w.replace("___",".");
String link = typeLinks.get(w.toLowerCase());
if (null != link) {
link = "<a href='" + link + "'>" + w + "</a>";
result = result.replaceAll("\\b" + w + "\\b", link);
}
}
}
return result;
} |
96510341-4e65-43bd-b47c-37f18f84802a | private void parseComments(ArrayList<String> comments) {
String curBlock=null, block=null;
boolean inPre=false;
for (String comment : comments) {
boolean newBlock = false;
String lowerComment = comment.toLowerCase();
int i;
// if we find a tag, start a new block
if (((i = lowerComment.indexOf(block = DESC)) >= 0) ||
((i = lowerComment.indexOf(block = AUTH)) >= 0) ||
((i = lowerComment.indexOf(block = DATE)) >= 0) ||
((i = lowerComment.indexOf(block = SEE)) >= 0) ||
((i = lowerComment.indexOf(block = SINCE)) >= 0) ||
((i = lowerComment.indexOf(block = VERSION)) >= 0) ||
((i = lowerComment.indexOf(block = RET)) >= 0) ||
((i = lowerComment.indexOf(block = PARM)) >= 0) ||
((i = lowerComment.indexOf(block = HISTORY)) >= 0) ||
((i = lowerComment.indexOf(block = THROWS)) >= 0)) {
comment = comment.substring(i + block.length());
curBlock = block;
newBlock = true;
}
String line = "";
comment = comment.trim();
for (int j = 0; j < comment.length(); ++j) {
char ch = comment.charAt(j);
if (ch != '*') {
line = comment.substring(j);
break;
}
}
if (!line.trim().isEmpty()) {
if (AUTH == curBlock) {
author += (!author.isEmpty() ? " " : "") + line.trim();
} else if (DATE == curBlock) {
date += (!date.isEmpty() ? " " : "") + line.trim();
} else if (SEE == curBlock) {
see += (!see.isEmpty() ? " " : "") + line.trim();
} else if (SINCE == curBlock) {
since += (!since.isEmpty() ? " " : "") + line.trim();
} else if (VERSION == curBlock) {
version += (!version.isEmpty() ? " " : "") + line.trim();
} else if (RET == curBlock) {
returns += (!returns.isEmpty() ? " " : "") + line.trim();
} else if (PARM == curBlock) {
String p = (newBlock ? "" : params.remove(params.size()-1));
params.add(p + (!p.isEmpty() ? " " : "") + line.trim());
} else if (THROWS == curBlock) {
String p = (newBlock ? "" : except.remove(except.size()-1));
except.add(p + (!p.isEmpty() ? " " : "") + line.trim());
} else if (HISTORY == curBlock) {
history += (!history.isEmpty() ? "\n" : "") + line.trim();
} else {
// not in a recognized tag - assume it's the description
curBlock = block = DESC;
// are we in a <pre> or <code> tag?
if (inPre) {
description += "\n" + line;
} else {
inPre = ((line.indexOf("<pre") >= 0) || (line.indexOf("<code") >= 0));
description += (!description.isEmpty() ? " " : "") +
(inPre ? line : line.trim());
}
if (inPre) {
inPre = !((line.indexOf("</pre>") >= 0) || (line.indexOf("</code>") >= 0));
}
}
}
}
} |
9814d5e1-1464-42c4-9e00-503cbabae4f2 | public SfApexDoc() {
instance = this;
} |
155422da-2061-4c13-aa64-0cbefb50f509 | public static void main(String[] args) {
SfApexDoc.args = new ArrayList<String>(Arrays.asList(args));
new SfApexDoc().doIt();
} |
ed7304b3-d9c5-454e-907c-92867f963001 | public void doIt() {
log("SfApexDoc version " + VERSION + "\n");
SfApexDoc.assertPrecondition(null != args);
// create a log file
try {
logFile = new PrintStream(new FileOutputStream(new File(LOG_FILE_NAME)));
} catch (Exception e) {
System.err.println("Failed to create log file: " + e.getMessage());
}
// parse command line parameters
String sourceDir="", destDir="", homeFile="", authorFile="", ext=DEFAULT_EXT;
try {
ArrayList<String> scope = new ArrayList<String>();
for (String s : SCOPES.keySet()) {
if (SCOPES.get(s)) {
scope.add(s);
}
}
for (int i = 0; i < args.size(); ++i) {
String argKey = args.get(i).substring(0, 2).toLowerCase();
if (SRC_ARG.equals(argKey)) sourceDir = args.get(++i);
else if (TARG_ARG.equals(argKey)) destDir = args.get(++i);
else if (HOME_ARG.equals(argKey)) homeFile = args.get(++i);
else if (AUTH_ARG.equals(argKey)) authorFile = args.get(++i);
else if (SCOPE_ARG.equals(argKey)) scope = new ArrayList<String>(Arrays.asList(args.get(++i).toLowerCase().split(SCOPE_SEP)));
else if (EXT_ARG.equals(argKey)) ext = args.get(++i);
else if (DEBUG_ARG.equals(argKey)) debugOutput = true;
else if (VERS_ARG.equals(argKey)) bail(null);
else syntaxError("Invalid option: " + argKey);
}
// make sure the source folder is valid
File sourceFolder = new File(sourceDir);
if (!sourceFolder.exists() || !sourceFolder.isDirectory()) {
bail("Invalid source folder: " + sourceDir);
}
File[] files = sourceFolder.listFiles();
initProgress(files.length * 2);
// get the list of files to process
ArrayList<ClassModel> models = new ArrayList<ClassModel>();
for (File f : files) {
if (f.isFile() && f.getAbsolutePath().toLowerCase().endsWith("." + ext)) {
ClassModel m = parse(getFileContents(f.getAbsolutePath()), scope);
if (null != m) {
models.add(m);
} else {
showProgress(); // we won't be creating docs for this
}
} else {
showProgress(); // we won't be creating docs for this
}
showProgress();
}
new FileManager(destDir).createDocs(models, authorFile, homeFile);
} catch (Exception e) {
log(e);
syntaxError(null);
}
} |
06a8568a-0418-4595-8cc6-92a506cefab7 | public static void log(Exception e) {
e.printStackTrace();
log(e.getMessage());
} |
1e904234-47d4-412a-a721-7b971ef5155f | public static void log(String message) {
if (null != message) {
System.out.println(" " + message);
if (null != logFile) {
logFile.println(message);
}
}
} |
42fb2f87-cf22-4009-9b1d-3f8d0eb0de26 | public static void assertPrecondition(boolean condition) {
if (!condition) {
throw new NullPointerException();
}
} |
d6600685-1fb8-4b69-8cee-7a545f05a393 | public void initProgress(int units) {} |
85fa1439-eff3-4857-9c1e-7d381b2549a3 | public void showProgress() {} |
eb1549bb-4b3c-4c0a-bd60-3ebace9921de | private static String getFileContents(String filePath) {
String result = "", line = "";
try {
BufferedReader reader = new BufferedReader(new FileReader(filePath));
while (null != (line = reader.readLine())) {
result += line + '\n';
}
reader.close();
} catch (Exception e) {
log("Exception loading file: " + filePath);
}
return result;
} |
c6079224-b7bb-4d71-ae05-cdef8cefa189 | public static ClassModel parse(String text, ArrayList<String> scope) {
if (scope.contains(SCOPE_GLOBAL)) {
scope.add(SCOPE_WEBSERVICE);
}
ClassModel parentClass = null, model = null;
String line = "", prevLine = null;
int lineIndex = 0, nestedCurlyBraceDepth = 0;
try {
boolean commentsStarted = false, inDocComment = false;
ArrayList<String> comments = new ArrayList<String>();
BufferedReader reader = new BufferedReader(new StringReader(text));
while (null != (line = reader.readLine())) {
++lineIndex;
int i = line.indexOf("//");
if (!commentsStarted) {
// ignore anything after // style comments. This allows hiding of tokens from ApexDoc
if (i > -1) {
// ignore segments that could be links (i.e. http://www...)
if ((0 == i) || (':' != line.charAt(i - 1))) {
line = line.substring(0, i);
}
}
}
line = line.replaceAll("\t", " ").trim();
if (line.length() > 0) {
// gather up our comments
if (line.startsWith(COMMENT_START)) {
inDocComment = line.startsWith(DOC_COMMENT_START);
comments.clear();
// check for single-line block comment
if (line.endsWith(COMMENT_END)) {
if (inDocComment) {
comments.add(line.substring(DOC_COMMENT_START.length(), line.length() - COMMENT_END.length()));
}
} else {
commentsStarted = true;
}
} else if (commentsStarted && line.endsWith(COMMENT_END)) {
commentsStarted = inDocComment = false;
} else if (commentsStarted) {
if (inDocComment) {
comments.add(line);
}
} else {
final int openCurlies = countChars(line, '{'), closeCurlies = countChars(line, '}');
nestedCurlyBraceDepth += openCurlies;
nestedCurlyBraceDepth -= closeCurlies;
if (null != prevLine) {
line = prevLine + ' ' + line;
prevLine = null;
}
boolean endOfSignature = false;
i = line.length();
for (int j = 0, iEnd; j < END_OF_SIGNATURE.length(); ++j) {
if ((iEnd = line.indexOf(END_OF_SIGNATURE.charAt(j))) >= 0) {
endOfSignature = true;
i = Math.min(i, iEnd);
}
}
if (endOfSignature) {
line = line.substring(0, i);
boolean hasScope = lineContainsScope(line, scope);
if (line.toLowerCase().matches("(^|.*\\s)(" + ClassModel.types + ")\\s+.*")) {
if (null == model) {
// top-level class
if (!hasScope) break; // must be a test class - skip it
model = new ClassModel(line, comments);
comments.clear();
} else {
// nested class
parentClass = model;
model = new ClassModel(parentClass, line, comments);
model.inScope = hasScope;
if (model.inScope) {
parentClass.children.add(model);
}
if ((openCurlies > 0) && (openCurlies == closeCurlies)) {
// this is a one-line class declaration; back to the parent
processCompleteModel(model);
model = parentClass;
parentClass = null;
}
comments.clear();
}
} else if ((null != model) && line.contains("(")) {
if (hasScope || model.isInterface) {
// method
model.methods.add(new MethodModel(line, comments));
}
comments.clear();
} else if (null != model) {
if (hasScope) {
// property, enum
model.properties.add(new PropertyModel(line, comments));
} else if ((null != parentClass) && (1 == nestedCurlyBraceDepth)) {
// this is the end of the nested class; back to the parent
processCompleteModel(model);
model = parentClass;
parentClass = null;
}
comments.clear();
}
} else {
// append the next line and try again
prevLine = line;
}
}
}
}
processCompleteModel(model);
} catch (Exception e) {
model = null;
log("Exception parsing line "+ lineIndex + ": " + line + "; " + e.getMessage());
}
return model;
} |
2db636cf-fdd4-41a9-b6e8-3285cec66d63 | private static void processCompleteModel(ClassModel model) {
if ((null != model) && model.inScope) {
Collections.sort(model.properties, new ModelComparer());
Collections.sort(model.methods, new ModelComparer());
debug(model);
}
} |
4aebda6a-8dcb-46b6-8719-4b22df1053b3 | private static boolean lineContainsScope(String line, ArrayList<String> scope) {
SfApexDoc.assertPrecondition(null != line);
SfApexDoc.assertPrecondition(null != scope);
String l = line.toLowerCase();
for (int i = 0; i < scope.size(); i++) {
if (l.matches("(^|.*\\s)" + scope.get(i) + "\\s+(?!get|set;|set\\s*\\{).*")) {
return true;
}
}
return false;
} |
2f638244-fd7d-44c8-997b-82cee17da458 | private static void debug(ClassModel model) {
if ((null != model) && debugOutput) {
log("Class: " + model.getName());
if (!model.properties.isEmpty()) {
String properties = "";
for (PropertyModel property : model.properties) {
properties += property.getName() + " ";
}
log(" properties: " + properties);
}
if (!model.methods.isEmpty()) {
String methods = "";
for (MethodModel method : model.methods) {
methods += method.getName() + " ";
}
log(" methods: " + methods);
}
}
} |
f3c7c390-1a5e-4c9f-a9de-13ec50e4c7fc | private static void syntaxError(String message) {
log(message);
// display usage
log("");
log("SfApexDoc is a tool for generating documentation from Salesforce Apex code class files.\n");
log("The syntax is:");
log(" SfApexDoc [-v] -s <source_folder> [-t <target_folder>] [-h <homefile>] [-a <authorfile>] [-p <scope>] [-x <file extension>]\n");
log(" (v)ersion - Displays the SfApexDoc version number");
log(" (s)ource_folder - The folder containing your apex .cls files");
log(" (t)arget_folder - The folder where HTML files will be created");
log(" (h)omefile - Contents for the home page right panel");
log(" (a)uthorfile - File containing project information for the header");
log(" sco(p)e - Comma-seperated list of scopes to document. Defaults to 'global,public'");
log(" e(x)tension - Extension of files to parse. Defaults to 'cls'");
bail(null);
} |
da22320d-a32c-4530-a365-a7a5d43f2c82 | private static void bail(String message) {
log(message);
log("");
System.exit(-1);
} |
bd63a8ca-c78a-4cc4-a513-9176d7f3267e | private static int countChars(String haystack, char needle) {
int count = 0;
for (int i = 0; i < haystack.length(); ++i) {
if (haystack.charAt(i) == needle) {
++count;
}
}
return count;
} |
334f2b60-9353-4a87-b44e-2edc2bdab353 | public MethodModel(String nameLine, ArrayList<String> comments) {
super("", comments);
// truncate to just the signature
int i = nameLine.indexOf('{');
setNameLine(((i >= 0) ? nameLine.substring(0, i) : nameLine).trim());
} |
3dd8bdbb-2728-4ff7-8735-8940880d31f0 | public String getName() {
// the word just before the '(' is the method name
final String line = getNameLine();
int end = line.indexOf('(');
String[] words = ((end < 0) ? line : line.substring(0, end)).split("\\s+");
return (words.length > 0) ? words[words.length - 1] : words[0];
} |
fa6ba520-7f91-4b56-8d37-5075b413a6b8 | public FileManager() {
this("");
} |
27344c59-0b8e-4e8f-a8e5-477d5446894c | public FileManager(String path) {
SfApexDoc.assertPrecondition(null != path);
this.path = path.trim();
if (this.path.isEmpty()) this.path = ".";
} |
1348361a-e17e-4204-9b16-cc48ee04cc23 | public void createDocs(ArrayList<ClassModel> models, String detailFile, String homeFile) {
SfApexDoc.assertPrecondition(null != models);
SfApexDoc.assertPrecondition(null != detailFile);
SfApexDoc.assertPrecondition(null != homeFile);
String projectDetail = parseProjectDetail(detailFile.trim());
if (projectDetail.isEmpty()) {
projectDetail = HtmlConstants.DEFAULT_PROJECT_DETAIL;
}
String homeContents = parseHtmlFile(homeFile.trim());
if (homeContents.isEmpty()) {
homeContents = HtmlConstants.DEFAULT_HOME_CONTENTS;
}
String links = "<table width='100%'><tr>" + getPageLinks(models);
homeContents = links + "<td><h2 class='section-title'>Home</h2>" + homeContents + "</td>";
homeContents = HtmlConstants.HEADER_OPEN + projectDetail + HtmlConstants.HEADER_CLOSE +
homeContents + HtmlConstants.FOOTER;
Hashtable<String, String> classHashTable = new Hashtable<String, String>();
classHashTable.put("index", homeContents);
String all = "<table width='100%'><tr>";
for (ClassModel model : models) {
String contents = links;
if (!model.getNameLine().isEmpty()) {
String children = "";
for (ClassModel child : model.children) {
children += "<tr>" + createClassDoc(child, child.getName()) + "</tr>";
}
final String fileName = model.getName();
final String classDoc = createClassDoc(model, fileName) + children + "</tr></table>";
contents += classDoc;
all += classDoc.replace(TOGGLE_ALL, "").replace(TOGGLE_ONE, "");
classHashTable.put(fileName.toLowerCase(), HtmlConstants.HEADER_OPEN + projectDetail +
HtmlConstants.HEADER_CLOSE + contents + HtmlConstants.FOOTER);
}
}
classHashTable.put("_all", HtmlConstants.HEADER_OPEN.replace(HtmlConstants.HEADER_TOGGLE, "") +
projectDetail + HtmlConstants.HEADER_CLOSE + all + HtmlConstants.FOOTER);
createDocFiles(classHashTable);
} |
67641539-7ce0-441c-872c-e3599cf9ba81 | private String formatHistory(String history) {
String[] lines = history.split("\\r?\\n");
String[] fields;
String result = "<table class=\"history\"><thead>";
for (Integer i=0; i<lines.length; i++) {
String line = lines[i].trim();
if (line.matches("(\\-+[\\s\\t]*\\|?[\\s\\t]*)+")) {
continue;
}
fields = line.split("\\|");
result += "<tr>";
for (Integer j=0; j<fields.length; j++) {
String field = fields[j].trim();
if (field.equals("Date") || field.equals("Author") || field.equals("Version")) {
result += ("<th>"+field+"</th>");
continue;
} else if (field.equals("Remarks")) {
result += ("<th class=\"remarks\">"+field+"</th>");
continue;
}
if (result.endsWith("</th>")) {
result += "</tr></thead><tbody>";
}
result += "<td>"+field+"</td>";
}
result += "</tr>";
}
result += "</tbody></table>";
return result;
} |
2c3163e7-67c3-4b06-86ae-e35236db0c99 | private String createClassDoc(ClassModel model, String fileName) {
model.addLinks();
String contents = "<td class='classCell'>";
contents +=
"<h2 class='section-title'>" + fileName + TOGGLE_ALL + "</h2>" +
"<div class='toggle_container_subtitle'>" + model.getNameLine() + "</div>" +
"<table class='details' rules='all' border='1' cellpadding='6'>" +
(model.getDescription().isEmpty() ? "" : "<tr><th>Description</th><td>" + model.getDescription() + "</td></tr>") +
(model.getAuthor().isEmpty() ? "" : "<tr><th>Author</th><td>" + model.getAuthor() + "</td></tr>") +
(model.getDate().isEmpty() ? "" : "<tr><th>Date</th><td>" + model.getDate() + "</td></tr>") +
(model.getVersion().isEmpty() ? "" : "<tr><th>Version</th><td>" + model.getVersion() + "</td></tr>") +
(model.getSee().isEmpty() ? "" : "<tr><th>See</th><td>" + model.getSee() + "</td></tr>") +
(model.getHistory().isEmpty() ? "" : "<tr><th>History</th><td>" + formatHistory(model.getHistory()) + "</td></tr>") +
"</table>";
if (!model.properties.isEmpty()) {
contents += "<p></p>" +
"<h2 class='trigger'>" + TOGGLE_ONE + " <a href='#'>Properties</a></h2>" +
"<div class='toggle_container'> " +
"<table class='properties' border='1' rules='all' cellpadding='6'> ";
for (PropertyModel prop : model.properties) {
String name = prop.getName();
prop.addLinks();
contents += "<tr><th class='clsPropertyName'>" + name + "</th>" +
"<td><div class='clsPropertyDeclaration'>" + prop.getNameLine() + "</div>" +
"<div class='clsPropertyDescription'>" + prop.getDescription() +
(prop.getAuthor().isEmpty() && prop.getDate().isEmpty()? "" : " (" + prop.getAuthor() + " " + prop.getDate() + ")") +
(prop.getSee().isEmpty() ? "" : ", see " + prop.getSee()) + prop.getThrowsAsString() +
"</div></tr>";
}
contents += "</table></div>";
}
if (!model.methods.isEmpty()) {
contents += "<h2 class='section-title methods'>Methods</h2>";
for (MethodModel method : model.methods) {
String name = method.getName();
method.addLinks();
contents += "<h2 class='trigger'>" + TOGGLE_ONE + " <a href='#'>" + name + "</a></h2>" +
"<div class='toggle_container'>" +
"<div class='toggle_container_subtitle'>" + method.getNameLine() + "</div>" +
"<table class='details' rules='all' border='1' cellpadding='6'>" +
(method.getDescription() != "" ? "<tr><th>Description</th><td>" + method.getDescription() + "</td></tr> " : "") +
(method.getAuthor() != "" ? "<tr><th>Author</th><td>" + method.getAuthor() + "</td></tr> " : "") +
(method.getDate() != "" ? "<tr><th>Date</th><td>" + method.getDate() + "</td></tr> " : "") +
(method.getVersion() != "" ? "<tr><th>Version</th><td>" + method.getVersion() + "</td></tr> " : "") +
(method.getSince() != "" ? "<tr><th>Since</th><td>" + method.getSince() + "</td></tr> " : "") +
(method.getReturns() != "" ? "<tr><th>Returns</th><td>" + method.getReturns() + "</td></tr> " : "") +
(method.getParams().size() > 0 ? "<tr><th colspan='2' class='paramHeader'>Parameters</th></tr> " : "");
for (String param : method.getParams()) {
if ((null != param) && !param.trim().isEmpty()) {
if (param.indexOf(' ') != -1) {
String list[] = param.split(" ");
if (list.length >= 1) {
contents += "<tr><th class='param'>" + list[0] + "</th>";
String val = "";
if (list.length >= 2) {
val = "";
for (int i = 1; i < list.length; i++) {
val += list[i] + " ";
}
}
contents += "<td>" + val + "</td></tr>";
}
}
}
}
contents += (method.getSee().isEmpty() ? "" : "<tr><th>See</th><td>" + method.getSee() + "</td></tr>");
if (!method.getThrows().isEmpty()) {
for (String t : method.getThrows()) {
contents += "<tr><th>Throws</th><td>" + t + "</td></tr>";
}
}
contents += "</table></div>";
}
}
return contents + "</td>";
} |
4a934ef7-f078-436e-971a-1649ab112042 | private String parseProjectDetail(String filePath) {
String contents = "";
try {
BufferedReader reader = new BufferedReader(new FileReader(filePath));
String line;
while ((line = reader.readLine()) != null) {
line = line.trim();
int equalsPos = line.indexOf("=");
String key = (equalsPos >= 0) ? line.substring(0, equalsPos).trim() : "";
String value = (equalsPos >= 0) ? line.substring(equalsPos + 1).trim() : "";
if (key.equalsIgnoreCase("projectname")) {
contents += "<h2>" + value + "</h2>";
} else if (!value.isEmpty()) {
contents += value + "<br>";
}
}
reader.close();
} catch (Exception e) {
SfApexDoc.log("parseProjectDetail(" + filePath + "): " + e.getMessage());
}
return contents.trim();
} |
ca60a127-ffc5-4e57-8e27-64e6ba6021e3 | private String parseHtmlFile(String filePath) {
String contents = "";
try {
BufferedReader reader = new BufferedReader(new FileReader(filePath));
String line;
while ((line = reader.readLine()) != null) {
contents += line.trim();
}
reader.close();
} catch (Exception e) {
SfApexDoc.log("parseHtmlFile(" + filePath + "): " + e.getMessage());
}
int bodyStart = contents.indexOf(BODY_START);
if (bodyStart >= 0) {
int bodyEnd = contents.indexOf(BODY_END);
if (bodyEnd >= 0) {
contents = contents.substring(bodyStart + BODY_START.length(), bodyEnd);
}
}
return contents.trim();
} |
393d49cc-4007-4db8-a9db-9c9b84cdd911 | private void copyFile(String source, String target) throws Exception {
target += "/" + source;
if (!(new File(target).exists())) {
InputStream is = getClass().getResourceAsStream(source);
FileOutputStream to = new FileOutputStream(target);
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = is.read(buffer)) >= 0) {
to.write(buffer, 0, bytesRead);
}
to.flush();
to.close();
is.close();
}
} |
dd0512c4-350c-4676-918b-99b662202d9f | private void createDocFiles(Hashtable<String, String> classHashTable) {
try {
// create required folders for documentation files
if (!path.endsWith("/") && !path.endsWith("\\")) {
path += '/';
}
path += ROOT_DIRECTORY;
(new File(path)).mkdirs();
for (String fileName : classHashTable.keySet()) {
SfApexDoc.log("Processing: " + fileName);
File file= new File(path + "/" + fileName + ".html");
FileOutputStream fos = new FileOutputStream(file);
DataOutputStream dos = new DataOutputStream(fos);
dos.writeBytes(classHashTable.get(fileName));
dos.close();
fos.close();
SfApexDoc.instance.showProgress();
}
copyResources(path);
} catch(Exception e) {
SfApexDoc.log(e);
}
} |
d676cc36-424d-4248-886c-28fae5da8be8 | private String getPageLinks(ArrayList<ClassModel> models){
String links = "<td class='leftmenus' rowspan='100'><div onclick=\"gotomenu('index.html');\">Home</div>";
for (ClassModel model : models) {
String name;
if (!(name = model.getName()).isEmpty()) {
links += "<div onclick=\"gotomenu('" + name.toLowerCase() + ".html');\">" + name + "</div>";
}
}
return links + "</td>";
} |
0b6d5aab-3c06-491c-9aaf-2141a82ac49a | private void copyResources(String toPath) throws IOException, Exception {
copyFile("logo.png", toPath);
copyFile("SfApexDoc.css", toPath);
copyFile("h2_trigger_a.gif", toPath);
copyFile("jquery-latest.js", toPath);
copyFile("toggle_block_btm.gif", toPath);
copyFile("toggle_block_stretch.gif", toPath);
} |
f0ef1e6f-c08f-4610-a326-b9567ba83034 | public ClassModel(ClassModel parent, String nameLine, ArrayList<String> comments) {
super(nameLine.trim(), comments);
isInterface = getNameLine().matches("(^|.*\\s)interface\\s+.*");
this.parent = parent;
final String name = getName();
// add this as a 'type' we can link to
addType(name, name.toLowerCase().split("\\.")[0] + ".html");
} |
de68ccfb-acf0-4e1f-bbe7-b348efce48a1 | public ClassModel(String nameLine, ArrayList<String> comments) {
this(null, nameLine, comments);
} |
64f3efa5-c27e-4665-ac9d-dae937470f30 | public String getName() {
// the name is the word after "class" or "interface"
final String typesToSearch = '|' + types + '|';
String[] words = getNameLine().split("\\s+");
for (int i = 0; i < words.length; ++i) {
if (((i + 1) < words.length) && (typesToSearch.contains('|' + words[i].toLowerCase() + '|'))) {
return (null != parent ? (parent.getName() + ".") : "") + words[i + 1].replaceAll("\\W", "");
}
}
SfApexDoc.assertPrecondition(false); // make sure nameLine contains one of the 'types' before calling this
return null;
} |
cb02d9bb-5b70-42ac-8fba-75c98dc4cf74 | public PropertyModel(String nameLine, ArrayList<String> comments) {
super(nameLine.trim(), comments);
} |
aada3f8e-5b97-4f6b-a532-6a5cd506b35c | public String getName() {
final String line = getNameLine();
int i = line.lastIndexOf(' ');
return (i >= 0) ? line.substring(i + 1) : line;
} |
f7a5b20c-4fa0-4183-8e2b-0a4f30a8f9a7 | public static int[] Sort(int[] data){
int[] sorted=data;
for(int i=1;i<data.length;i++){
int temp = sorted[i];
int position = i;
while(position>0 && temp<sorted[position-1]){
sorted[position]=sorted[position-1];
position--;
}
sorted[position]=temp;
}
return sorted;
} |
e8a9950c-ab8d-4b75-9c82-01ad8ed969c4 | public static int[] RandomArray(int min, int max){
return RandomArray(max-min+1, min, max);
} |
c142711e-b5a4-43d3-8ea3-6407822bccf7 | public static int[] RandomArray(int size, int min, int max){
Random rand = new Random();
int[] array = new int [size];
for(int i=0;i<size;i++){
array[i] = min+Math.abs(rand.nextInt()%(max-min+1));
}
return array;
} |
7f4f231c-24b5-4d6a-8e89-d52ad17fe1cb | public static int Max(int[] data){
int max=data[0];
for(int d : data){
if(max<d){
max = d;
}
}
return max;
} |
c9f73500-cfda-4c75-b22a-6f8d1100df96 | public static int Min(int[] data){
int min=data[0];
for(int d : data){
if(min>d){
min = d;
}
}
return min;
} |
188055ae-8113-47d5-b80b-acec3f2b9766 | public static int[] Sort(int[] data){
int min = Utils.Min(data); //also used for offset
int max = Utils.Max(data);
//step 1: initialize the buckets
ArrayList[] buckets = new ArrayList[max-min+1];
for(int i=0;i<buckets.length;i++) {
buckets[i] = new ArrayList();
}
//step 2: fill the buckets
for(int d:data){
buckets[d-min].add(d);
}
//step 3: consolidate the buckets
int[] sorted = new int[data.length];
int j = 0;
for(ArrayList bucket: buckets){
Iterator i = bucket.iterator();
while(i.hasNext()) {
sorted[j++]=(Integer)(i.next());
}
}
return sorted;
} |
aeb7f1d3-c6db-491b-91b1-79af70a9a98c | public static int[] Sort(int[] data){
int[] sorted = data;
for(int i=data.length-1;i>0;i--) {
for(int j=0;j<i;j++) {
if(sorted[j]>sorted[j+1]){
int temp = sorted[j];
sorted[j]=sorted[j+1];
sorted[j+1]=temp;
}
}
}
return sorted;
} |
abbf91ee-cf64-48da-ac36-92483ab04764 | public static void main(String[] args) {
// TODO code application logic here
int[] ar = Utils.RandomArray(100,-50,-20);
System.out.println("Unsorted...");
for(int i: ar)
System.out.print(i+" ");
ar = BucketSort.Sort(ar);
System.out.println("\nSorted...");
for(int i: ar)
System.out.print(i+" ");
ar = Utils.RandomArray(1, 15);
System.out.println("\nUnsorted...");
for(int i: ar)
System.out.print(i+" ");
System.out.println("\nSorting...");
ar= HeapSort.Sort(ar);
for(int i: ar)
System.out.print(i+" ");
System.out.println("\nPrepare for StupidSort!");
ar = new int[] {1,3,6,4,9,7,12,5,10,11,17};
ar = StupidSort.Sort(ar);
for(int i: ar)
System.out.print(i+ " ");
} |
63392365-e886-4b83-84ce-bc0998c328f6 | public static int[] Sort(int[] data){
int[] sorted = new int[data.length];
System.arraycopy( data, 0, sorted, 0, data.length );
boolean isSorted;
Random rand = new Random();
while (true){
isSorted = true;
for(int i=0;i<sorted.length-1;i++){
if(sorted[i]>sorted[i+1]){
isSorted = false;
break;
}
}
if(isSorted)
return sorted;
for(int i=0;i<sorted.length;i++){
int temp = sorted[i];
int swap = rand.nextInt(sorted.length);
sorted[i] = sorted[swap];
sorted[swap] = temp;
}
}
} |
aab8fd7d-635f-4702-9a2c-36621268c9d2 | public static void main(String[] args){
System.out.println("\nPrepare for StupidSort!");
int size = 11;
int min = 0;
int max = 100;
int[] ar;
ar = Utils.RandomArray(size, min, max);
//ar = new int[] {1,3,6,4,9,7,12,5,10,11,17};
ar = StupidSort.Sort(ar);
for(int i: ar)
System.out.print(i+ " ");
} |
65f94dc0-473f-4e82-ae38-5a7fb4d22c1b | public static int[] Sort(int[] data){
int[] sorted=new int[data.length];
Heap heap = new Heap(data.length);
for(int d:data){
heap.insert(d);
}
while(heap.getSize()>0){
sorted[heap.getSize()-1] = heap.remove();
}
return sorted;
} |
ae72275b-7cc5-4f84-a9e2-26dcb514c3a3 | public EnvironmentReader(String location, int lineCount, int lineLength) throws IOException {
_location = location;
_lineCount = lineCount;
_lineLength = lineLength;
readEnvironment();
} |
aae15bd5-1c2f-40bc-aa7f-284d92b3c0a4 | private void readEnvironment() throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(_location));
char[][] environment = new char[_lineCount][_lineLength];
for (int currentLine = 0; currentLine < _lineCount; ++currentLine) {
String line = reader.readLine();
for (int linePos = 0; linePos < line.length(); ++linePos) {
char currentChar = line.charAt(linePos);
if (currentChar == START_CHAR) {
_startPos = new int[2];
_startPos[0] = currentLine;
_startPos[1] = linePos;
}
if (currentChar == GOAL_CHAR) {
_goalPos = new int[2];
_goalPos[0] = currentLine;
_goalPos[1] = linePos;
}
if (currentChar == PORTAL_CHAR1) {
if (_portalPos1Eingang == null) {
_portalPos1Eingang = new int[2];
_portalPos1Eingang[0] = currentLine;
_portalPos1Eingang[1] = linePos;
} else {
_porta1Pos1Ausgang = new int[2];
_porta1Pos1Ausgang[0] = currentLine;
_porta1Pos1Ausgang[1] = linePos;
}
if (currentChar == PORTAL_CHAR2) {
if (_portalPos2Eingang == null) {
_portalPos2Eingang = new int[2];
_portalPos2Eingang[0] = currentLine;
_portalPos2Eingang[1] = linePos;
} else {
_portalPos2Ausgang = new int[2];
_portalPos2Ausgang[0] = currentLine;
_portalPos2Ausgang[1] = linePos;
}
}
environment[currentLine][linePos] = currentChar;
}
}
reader.close();
_environment = environment;
}
} |
9fb5f3c9-9767-4d78-a4d4-68363685b290 | public char[][] getEnvironment() {
return _environment;
} |
f9877760-9ecd-4857-833c-ba8a2176d33e | public int[] getStartPos() {
return _startPos;
} |
2f9ad483-6859-4c0a-ae44-5c8e2244019d | public int getStartPosX() {
return _startPos[1];
} |
766fff3d-02fe-432e-868d-0384abc59a6a | public int getStartPosY() {
return _startPos[0];
} |
3deaedae-87f7-40e8-9548-9b54487866b9 | public int getGoalPosX() {
return _goalPos[1];
} |
6a899745-4bc2-4d24-8041-4a3a491854c2 | public int getGoalPosY() {
return _goalPos[0];
} |
9a5d7112-8e64-4dfd-b655-4a4600dd97ff | public char getGoalChar() {
return GOAL_CHAR;
} |
5b9960c4-16d0-462d-b146-093803bbc4eb | public Path(Node s) {
nodelist.add(s);
} |
a7fe1074-fc6b-41de-b5a6-2937177976b7 | public Path() {
} |
e696cceb-b08b-4467-a2bb-a0370a50c9a0 | public void addNode(Node node) {
nodelist.add(node);
} |
41187622-ae97-4c66-bcf3-a4af3d78f705 | public Node getLastNode() {
int lastIndex = nodelist.size() - 1;
if (lastIndex >= 0) {
return nodelist.get(lastIndex);
} else {
return null;
}
} |
9362f9bc-1694-416d-9657-a034bf41be5e | public List<Character> getCharPath() {
List<Character> charList = new ArrayList<Character>();
for (Node node : nodelist) {
charList.add(node.getDirection());
}
return charList;
} |
e481bb00-6d31-4434-8d70-a7d9b4f10b37 | public Path expandPath(Node newNode) {
Path newPath = new Path();
newPath.nodelist.addAll(this.nodelist);
newPath.addNode(newNode);
return newPath;
} |
5e2103ba-f632-48e0-82ae-ffee590b5d49 | public Node(int x, int y, char Direction) {
this.x = x;
this.y = y;
this.Direction = Direction;
} |
47eab872-c4e0-4762-8637-f9b38dca5cde | public Node(int x, int y, int Schrittkosten, int heuristik, Node vorgaenger) {
this.x = x;
this.y = y;
this.kosten = Schrittkosten;
this.heuristik = heuristik;
this.vorgaenger = vorgaenger;
this.Direction='1';
} |
9d252c70-e482-4a32-85af-d4ab8bd2c2fb | public int getKostenSum() {
return this.getKostenBisher() + this.kosten + this.heuristik;
} |
7c0d6f2f-8154-4af7-990a-c277500b5013 | public int getKostenBisher() {
if (this.vorgaenger == null) {
return 0;
}
return this.vorgaenger.getKostenBisher() + this.kosten;
} |
ef430d1a-1e33-4020-b91a-529844e5a9dc | public void setVorgaenger(Node neuer) {
this.vorgaenger = neuer;
} |
c9b35dd6-df6d-49d0-a565-2798daa2a38a | public int getX() {
return x;
} |
93c99b0b-b280-440f-93ca-0b7bff84cc93 | public int getY() {
return y;
} |
c9a86071-0972-40e0-8ff0-51070b663558 | public char getDirection() {
return Direction;
} |
f9d19dad-9733-45b0-825c-6c81fda6073e | @Override
public int hashCode() {
int hash = 5;
hash = 59 * hash + this.x;
hash = 59 * hash + this.y;
hash = 59 * hash + this.Direction;
return hash;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.