Calculate the first prime number greater than the input.
- User sends a request to our compute server containing
- Delimiters chosen
- File path (Assume that the computation server has access to this location and can obtain a file handle
- Result Destination (Either to a file, stdout, null, etc.)
- User subscribes to the result if opted (Futures potentially as an implementation)
- Computation Coordinator starts its work, and will potentially notify our user when complete.
- DataStorage has access to our storage infrastructure, and will handle reading and writing. This process will live on the same server as the computation, because sending information over the wire to then write locally makes little sense.
- Navigate to your project directory
- Run
.\gradlew eclipseto update .classpath and .project - Add both to your .gitignore
- Navigate to your project directory
- Run
.\gradlew generatePrototo generate protocol buffers - If this fails on account of inability to delete, delete the
build/generateddirectory manually, then re-run.
We have a very short list of expectations for code around here.
- Function names, parameters, and any local variables should aim to be self-explanatory without being too verbose.
- Make Javadoc comments for methods (Type
/**+Enter and Eclipse will auto-insert the formatting.)
Important
For the sake of readable code, please hit Ctrl + Shift + F in Eclipse before saving a file. It reformats the file in a Checkstyles-friendly way. If Checkstyles still declines your commit, check the reason: Click into the Action, under Checkstyles, click into Print Results in the main column.
- It should never be the case that code cannot compile when trying to make a Pull-Request, as that strictly violates any semblance of quality.
- Try to run the code locally. If it doesn't want to run, debug it.
- Eclipse is very good about why errors happen.
- See the Problems tab on the bottom of the main window (If using the default layout).
Caution
Do not add more than a single top-level object per file. Gradle will be angry. The file name has the same name as the class.
ClassA.java → ClassAThis is Case-Sensitive
Fibonacci.java
/**
* @author cameron
* Handles generating the nth Fibonacci number
*/
public class Fibonacci {
public static void main(String[] args) {
int nthFib = Integer.parseInt(args[0]);
System.out.println(new Fibonacci().findNthFib(nthFib));
}
/**
* Generates the nth Fibonacci number given an index.
* @param nthFib The index of the Fibonacci number to generate.
* @return an integer containing the nth Fibonacci number.
*/
private int findNthFib(int nthFib) {
int currentFib = 1;
int prevFib = 0;
for (int i = 0; i < nthFib; i++) {
int nextFib = currentFib + prevFib;
prevFib = currentFib;
currentFib = nextFib;
}
return currentFib;
}
}Checkstyles.java (Could use some more javadoc comments)
package checkstyles;
import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
public class Checkstyles {
public static void main(String[] args) {
if (args != null) {
try {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = dbFactory.newDocumentBuilder();
File inputFile = new File(args[0]);
Document doc = docBuilder.parse(inputFile);
NodeList list = doc.getElementsByTagName("file");
String curFile;
NodeList detailList;
int line, col;
String sev, msg, src;
System.out.println("");
System.out.println("| Severity | File | Error |");
System.out.println("| --- | --- | :--- |");
for (int i = 0; i < list.getLength(); i++) {
curFile = ((Element) list.item(i)).getAttribute("name").split("/./")[1];
// If the file has any checkstyles entries
if (list.item(i).hasChildNodes()) {
detailList = list.item(i).getChildNodes();
for (int j = 0; j < detailList.getLength(); j++) {
if (detailList.item(j).hasAttributes()) {
// We are in an error node or similar.
line = Integer.parseInt(((Element) detailList.item(j)).getAttribute("line"));
col = Integer.parseInt(((Element) detailList.item(j)).getAttribute("column"));
sev = ((Element) detailList.item(j)).getAttribute("severity");
msg = ((Element) detailList.item(j)).getAttribute("message");
src = ((Element) detailList.item(j)).getAttribute("source").split(
"\\.")[((Element) detailList.item(j)).getAttribute("source").split("\\.").length
- 1];
System.out.println(String.format("| %s | %s | [%d,%d] %s <%s> |", sev, curFile, line,
col, msg, src));
}
}
} else {
System.out.println("| | " + ((Element) list.item(i)).getAttribute("name").split("/./")[1]
+ " | No errors found.");
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}