id
stringlengths
36
36
text
stringlengths
1
1.25M
b8bf6675-0422-4b82-8732-536c363dc475
@Test public void gridSquareShouldReturnTypeOfEmpty() { replayAll(); assertEquals(square0.getSquareType(), GridSquare.EMPTY); }
5c47e1c6-3fb8-4533-8989-cbae53b9ba27
@Test public void gridSquareShouldBeInitializedToCovered() { replayAll(); assertTrue(square0.isCovered()); }
c7174569-1e17-4ca3-a91e-28bf3b5298ae
@Test public void gridSquareShouldBeInitializedToUnFlagged() { replayAll(); assertFalse(square0.isFlagged()); }
89055721-b14a-47ea-a55a-af37a94a87eb
@Test public void rightClickingAGridSquareShouldToggleIsFlagged() { replayAll(); assertFalse(square0.isFlagged()); square0.rightClick(); assertTrue(square0.isFlagged()); square0.rightClick(); assertFalse(square0.isFlagged()); }
fa0331a9-6427-498a-b066-59b41348f906
@Test public void rightClickingAGridSquareShouldToggleColorsOfSquare() { replayAll(); assertEquals(GridSquare.NON_ACTIVE_COLOR, square0.getBackground()); square0.rightClick(); assertEquals(GridSquare.FLAGGED_COLOR, square0.getBackground()); square0.rightClick(); asse...
74ad514c-a2fc-4c1c-b7d6-1923115aa1a4
@SuppressWarnings("static-access") /**Main menu, installing algorithms, and backupping.*/ public static void main(String[] args) throws Exception { m.print("EBG Installation Assistant for EBG V1.3 (1.4.7) by Florilu", 1); System.out.println("Options: "); System.out.println("Install: [1]"); System.out...
c60da5ea-c369-4ab0-a64a-5fe16cc10edf
public static void install(File folder){ try{ folder.mkdir(); }catch(EBGInstallException e){ throw new EBGInstallException("Something went wrong due the installation of the mod."); } }
a6db5fda-c981-4a72-86ca-10442c2bfd4c
public static void write() throws IOException { String text = "The Backupfunction is still WIP, be sure you'll backup your jar by yourself!"; String dateiName = mainFolder + "EBGBackup/README.txt"; FileOutputStream schreibeStrom = new FileOutputStream(dateiName); for (int i = 0; i < text.length(); i++) { sc...
1ebe541c-44ce-4474-9bc5-d47e34a13974
public void extractArchive(File archive, File destDir) throws Exception { if (!destDir.exists()) { destDir.mkdir(); } minecraft.delete(); ZipFile zipFile = new ZipFile(archive); Enumeration entries = zipFile.entries(); byte[] buffer = new byte[16384]; while (entries.hasMoreElements()) { ZipEntry...
cdd7ab70-9a77-4a1b-9bb3-856b0965c15a
public static boolean del(File dir){ if(dir.isDirectory()){ File[] files = dir.listFiles(); for(File aktFile : files){ del(aktFile); } } return dir.delete(); }
1b9cf522-182e-427e-8379-5ac4f04f5657
public static void print(String text, int option){ if(option == 1){ System.out.println(text); } if(option == 2){ System.out.print(text); } if(option == 3){ System.err.println(text); } if(option == 4){ System.err.print(text); } }
14a3d2a4-a9c7-4f47-8300-a02e58018200
public static int calc(int first, int second, int result){ return result = (first + second); }
8da7f906-f8a5-4d2e-9162-e824642af649
public EBGInstallException(String error){ super(error); }
4355f7bd-92cc-469c-901a-386ee828a6a2
public static boolean zip(File directory, String outputDirectory) { boolean result = false; byte[] buffer = new byte[8192]; try { LinkedList<String> fileList = getAllFiles(directory); //String outFil...
6a40d14d-f730-4d26-8629-23fc04322b9d
public static LinkedList<String> getAllFiles(File directory) { File[] files = directory.listFiles(); LinkedList<String> allFiles = new LinkedList<String>(); for (File file : files) { if (file.isDirectory()) { LinkedList<String> ...
66ef9547-7501-4940-8783-43b2240cd6c3
public static File file(String path) { return new File(path); }
6b84ad34-d5e6-4b86-8c6e-9cf3246118c1
public static void copy(File source, File destination) { try { FileInputStream fileInputStream = new FileInputStream(source); FileOutputStream fileOutputStream = new FileOutputStream( destination); FileChannel inputChannel = fileInputStream.getChannel(); FileChannel outputChannel = ...
eb963012-9a8c-4600-92b2-2463b3d9f4d4
public static void transfer(FileChannel fileChannel, ByteChannel byteChannel, long lengthInBytes, long chunckSizeInBytes, boolean verbose, boolean fromFile) throws IOException { long overallBytesTransfered = 0L; long time = -System.currentTimeMillis(); while (overallBytesTransfered < lengthInBytes) ...
a703b1da-654b-452e-b3d4-c6d2f9e1c3e3
public User(String name, String school){ this.name = name; this.school = school; }
9b90a8e7-246a-493c-85ae-449089234a63
public boolean equals(User u){ return u.name.equals(this.name); }
ae3304dd-61bb-4a74-aedb-00eb80e0cb1e
static char getOption() { System.out.print("\tChoose action: "); System.out.print("(1) students at a school, "); System.out.print("(2) shortest intro chain, "); System.out.print("(3) cliques at school, "); System.out.print("(4) connectors, "); System.out.print("(q)uit? =>...
a3a21560-dcb8-4f4b-939b-9cb015e05c67
public static void main(String[] args) throws FileNotFoundException{ System.out.print("Enter the input file name => "); String graphFile = stdin.next(); Graph graph = new Graph(new Scanner(new File(graphFile))); graph.buildGraph(); char option; while ((option = ge...
03b4e677-2cd3-4bd8-9e1a-1155ecbab30c
public Node(User data, Node next) { this.data = data; this.next = next; }
f46d25ba-9be9-4dc5-8fa1-b9635e57c3fd
public boolean equals(Node n){ return n.data.equals(this.data); }
fd8771a1-7471-428e-a0bf-5d7b21410a85
public Graph(Scanner sc){ this.sc = sc; }
f5685869-eea0-46ef-a27e-07e5d755b310
public void buildGraph(){ int numPeople = Integer.parseInt(sc.nextLine()); graph = new HashMap<String, Node>(); while(graph.size() < numPeople && sc.hasNextLine()){ Node temp = new Node(makeUser(sc.nextLine()), null); graph.put(temp.data.name, ...
619511f4-102e-4554-89cf-6c6069d8487e
public HashMap<String,Node> subGraph(String school){ HashMap<String,Node> subGraph = new HashMap<String, Node>(); for (String name: graph.keySet()){ if(graph.get(name).data.school != null && graph.get(name).data.school.equals(school)){ subGraph.put...
f8f692f8-d11f-456f-a660-c9e375ca8475
public void buildCliques(HashMap<String,Node> subGraph){ int i = 1 ; HashMap<String, Node> resultMap = new HashMap<String, Node>(); for (String name: subGraph.keySet()){ if (!visited.contains(subGraph.get(na...
dd05b802-8c23-4370-8e26-072884dc8b80
public void dfs(HashMap<String,Node> subGraph, HashMap<String,Node> resultMap , Node person){ if (!visited.contains(person.data.name)){ Node keyFriend = new Node(person.data, person.next); resultMap.put(person.data.name, keyFriend); vi...
f988b1c8-b229-49f6-9dce-8880b96bc091
public void printSubGraph(HashMap<String, Node> subGraph){ Stack<ArrayList<String>> qf = new Stack<ArrayList<String>>(); System.out.println(subGraph.size()); for (String name: subGraph.keySet()){ char student; if (subGraph.get(name).data.school != null){ ...
05607b95-9777-44d1-b2ca-61f2a935680b
public Node scanFriends(String school, Node person){ if (person.next != null){ person.next = scanFriends(school, person.next); } if (person.data.school != null && person.data.school.equals(school)){ return pers...
500ca791-5cca-4e37-b616-cf92da21347d
private User makeUser(String line){ line.toLowerCase(); Scanner makeUserSc = new Scanner(line).useDelimiter("\\s*\\|\\s*"); User person = new User(null, null); person.name = makeUserSc.next(); if (makeUserSc.next().equals("y")){ person.scho...
cd1a8e0e-2897-4f54-99c9-d47bf661f772
private void makeFriendships(Node firstFriend, Node secondFriend) { if(firstFriend.next == null){ firstFriend.next = secondFriend; } else { makeFriendships(firstFriend.next, secondFriend); } }
2ab4151e-8ccc-4983-90e3-a7ef437845e5
public void printUser(User person) { System.out.println("Name: " + person.name); System.out.println("School: " + person.school); }
1b6259c9-64dc-4c11-b0be-92ce31180cae
void printGraph(HashMap<String, Node> graph){ for(String name: graph.keySet()){ System.out.println(graph.get(name).data.name); Node testFriend = graph.get(name); while( testFriend.next != null){ testFriend = testFriend.n...
7689d416-7692-4d5d-a0e0-474686d42c2c
private String printList(Node friend){ Node ptr; String answer = ""; for(ptr=friend; ptr!=null; ptr=ptr.next){ if(ptr==friend){ continue; } answer+=(ptr.data.name+" "); } return friend.data.name+" is friends with: "+answer; }
6873a07b-0caa-41e0-8f94-f458b72cf046
public String BFS(String source, String target){ Queue<ArrayList<String>> paths = new Queue<ArrayList<String>>(); ArrayList<String> path = new ArrayList<String>(); Queue<Node> q = new Queue<Node>(); Node start = graph.get(source); q.enqueue(start); ...
b4bcfd10-9315-41a0-b092-39fd0f5d07b6
public void connectors(){ //HashMap<String, Integer> dfsNum = new HashMap<String, Integer>(); //HashMap<String, Integer> backNum = new HashMap<String, Integer>(); connectors = new ArrayList<String>(); String result = ""; ArrayList<String> visited = new ArrayList<String>(); ...
6e0fad60-24db-4fd7-b111-27be6c5df88d
private void nodeDFS(Node v, ArrayList<String> visited){ visited.add(v.data.name); v.dfsnum = dfsnum++; v.backnum = v.dfsnum; //System.out.println(v.data.name); for(Node w = v.next; w!=null; w=w.next){ if(!visited.contains(w.data.name)){ nodeDFS(graph.get(w.data.name), visited); if...
5fcad66f-d323-4403-bf9a-a08f23106236
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); String candidate = request.getParameter("candidate"); String captcha = request.getParameter("captcha"); ...
8a60076b-af7f-45d9-8eb1-844d9bd59893
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); }
4cd3c3a8-0aa7-4d7d-b871-3c45fdc72fa9
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); }
3b2754f4-ef0c-4444-b144-7884737e6611
@Override public String getServletInfo() { return "Short description"; }// </editor-fold>
11d34975-d08e-4a06-8b84-7da45fc89441
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); Boolean injectionProtection = false; String writein = request.getParameter("writein"); ...
f833baf5-5928-4d4b-9c9a-726fa7ce53fb
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); }
915b713c-d21c-4d15-8ba1-72a8012f6238
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); }
0568c380-1cda-426e-ae81-4de9a7b57237
@Override public String getServletInfo() { return "Short description"; }// </editor-fold>
34af0564-9be0-43e3-93cc-8f3a0ceb64de
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); String user_id = request.getParameter("user_id"); String password = request.getParameter("password"); String ...
fdb396e6-1646-496b-aa98-0ceed5bd39fc
private void invalidUser(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { RequestDispatcher rd = getServletContext().getRequestDispatcher("/index.jsp"); PrintWriter out = response.getWriter(); out.println("<div class=\"container\" style=\"width:300...
422d9fa0-b7e2-42c2-a531-140e389f599f
public static void setupSession(HttpServletRequest request, HttpServletResponse response, Connection con, String user_id, Boolean injectionProtection) throws SQLException, IOException { HttpSession session = request.getSession(); PreparedStatement ps = null; ResultSet rs = null; if(inje...
295bedc2-2497-45af-8c90-b1a72648936a
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); }
07a773bf-8293-441c-b2d9-5e9ea719ce77
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); }
8965cc7b-af3c-407e-a0ee-5b5fb84ec6f0
@Override public String getServletInfo() { return "Short description"; }// </editor-fold>
de3395b9-c7a4-48a9-8ab0-34f210b3e966
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); String url; try { /* TODO output you...
810c6322-0ed1-4b81-a96c-5dd1021e9bc6
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); }
9a28cac7-4346-47c5-b16d-aff6a061e2ca
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); }
74c7984e-c714-4a08-aa74-38658a2b6fed
@Override public String getServletInfo() { return "Short description"; }// </editor-fold>
57506177-69a3-4ac3-b7ce-cd33ccfce049
public User() { }
1f92188c-53e4-410c-b1f4-84d34ceae0f5
public User(String name, Boolean voted) { this.name = name; this.voted = voted; }
a93f55f7-4810-4c93-ade0-f99ae6055fa5
public User(ResultSet rs) throws SQLException { this(rs.getString("name"), rs.getBoolean("voted")); }
fa71ee6d-17c8-4ad2-bb08-39b7477ea917
public String getName() { return name; }
7e97f7ee-8df7-416f-8bfc-22e7d971c540
public Boolean getVoted() { return voted; }
e5409ddf-2776-4d79-a7ff-2d2ac4d947fa
public void contextInitialized(ServletContextEvent servletContextEvent) { ServletContext ctx = servletContextEvent.getServletContext(); try { DatabaseManager dbManager = new DatabaseManager(); ctx.setAttribute("DBConnection", dbManager.getConnection()); ...
8ea5081f-0465-40a4-b4e1-b7b491a3b227
public void contextDestroyed(ServletContextEvent servletContextEvent) { Connection con = (Connection) servletContextEvent.getServletContext().getAttribute("DBConnection"); try { con.close(); } catch(SQLException e) { e.printStackTrace(); } }
d2c3ed6f-e1d7-40f9-a6b5-5b13b0ed9967
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Throwable throwable = (Throwable) request.getAttribute("javax.servlet.error.exception"); Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.sta...
c174d9bf-566a-45e3-a7ba-9771e2a4ec11
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); }
b29746fd-a1ff-42f0-b0f4-89dc5e2ed571
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); }
4c183023-7f91-4237-8076-cc7ca55ddec9
@Override public String getServletInfo() { return "Short description"; }// </editor-fold>
9b4689a5-705a-4a7e-8a51-68fe5d13bb98
public DatabaseManager() throws ClassNotFoundException, SQLException { Class.forName("com.mysql.jdbc.Driver"); this.connection = DriverManager.getConnection(url , user, pwd); }
ca68f75c-8434-4eff-b15c-e90949c0e954
public Connection getConnection() { return this.connection; }
8a6c3e16-fdcd-49b4-af2c-778995315904
public static void testConnection() throws ClassNotFoundException, SQLException { Statement stmt; Connection con; con = DriverManager.getConnection(url, user, pwd); stmt = con.createStatement(); stmt.execute("USE e_voting"); stmt.execute("Select * from User...
d5754ea9-2b64-4c6f-a0ac-d4853e4eda7d
public static void main(String a[]) { final ProcNumbers proc = new ProcNumbers(); Thread producerThread = new Thread(new Runnable() { @Override public void run() { try { proc.produce(); } catch (InterruptedException e) { e.printStackTrace(); } } }); Thread consumerThread =...
a360b6c4-e735-4c0b-8c83-d3d5fb73bc50
@Override public void run() { try { proc.produce(); } catch (InterruptedException e) { e.printStackTrace(); } }
757383ba-6d55-4477-8439-d91762d9bde0
@Override public void run() { try { proc.consume(); } catch (InterruptedException e) { e.printStackTrace(); } }
db28da32-403a-40dd-ad76-608c202a1955
public void produce() throws InterruptedException { while(true) { synchronized (lock) { while(list.size() == LIMIT) { lock.wait(); } list.add(value++); lock.notify(); } } }
4471fa6f-e0d3-475d-b1d3-5625fec48a4e
public void consume() throws InterruptedException { while(true) { synchronized (lock) { while(list.size() == 0) { lock.wait(); } System.out.print("List size was: " + list.size()); int val = list.removeFirst(); System.out.println("; Removed value is : " + val); lock.notify(); } T...
2005616f-c334-43f3-a48e-31ebe8e29c14
public static void main(String a[]) { final ProduceConsume pc = new ProduceConsume(); Thread t1 = new Thread(new Runnable() { @Override public void run() { pc.produce(); } }); Thread t2 = new Thread(new Runnable() { @Override public void run() { pc.consume(); } }); ...
2bc13b10-9cb9-4e8e-9c30-8695229dea4a
@Override public void run() { pc.produce(); }
04c3df5f-f91b-426a-a584-a7fc0cd18e82
@Override public void run() { pc.consume(); }
c6b952b7-d73f-4420-889b-ff759a3008db
private void produce() { Random random = new Random(); while(true) { try { queue.put(random.nextInt(500)); } catch (InterruptedException e) { e.printStackTrace(); } } }
68d815a9-d149-4bee-9297-d6792804c83f
private void consume() { Random random = new Random(); while(true) { try { Thread.sleep(100); } catch(Exception e) {} if(random.nextInt(20) == 11) { try { Integer value = queue.take(); System.out.println("Value is: " + value + " and queue size is: " + queue.size()); } catch...
d5d231e0-715d-42f5-9c88-9fcf0f1c866d
public void increment() { for (int i = 0; i < 20000; i++) ++cnt; }
466b8006-1e39-4f9d-b407-4b0ba1e26582
public void firstThread() throws InterruptedException { lock.lock(); System.out.println("First is waiting ... "); cond.await(); System.out.println("First is awaken!"); try { increment(); } finally { lock.unlock(); } }
96b2714f-7a1d-41b0-be59-0721f557bbaa
public void secondThread() throws InterruptedException { Thread.sleep(1000); lock.lock(); System.out.println("Press the return key!"); new Scanner(System.in).nextLine(); System.out.println("Got return key!"); cond.signal(); try { increment(); } finally { lock.unlock(); } }
ad13727e-0d34-409e-8ca5-9432f3463db9
public void done() { System.out.println("Count is: " + cnt); }
b8c886f5-b88e-4f6a-ac07-cc5dfc713b78
public static void main(String a[]) { final LockRunner lockRunner = new LockRunner(); Thread first = new Thread(new Runnable() { @Override public void run() { try { lockRunner.firstThread(); } catch (InterruptedException e) { e.printStackTrace(); } } }); Thread second = ne...
a60fcf36-dd24-47e7-bf97-c1646f8747e6
@Override public void run() { try { lockRunner.firstThread(); } catch (InterruptedException e) { e.printStackTrace(); } }
7fbae512-ca7d-429f-ba64-83149c637714
@Override public void run() { try { lockRunner.secondThread(); } catch (InterruptedException e) { e.printStackTrace(); } }
9a4571f9-014a-4d3f-9c71-cd02cd01c1ed
public static void main(String a[]) { new Processor().invodeProcess(); }
2d141015-6158-4ab6-a06d-d174e0f64cac
private void pingServerA() { synchronized (lock1) { // simulate pinging a server by sleeping for some time try { Thread.sleep(1); } catch (InterruptedException e) { e.printStackTrace(); } serverA.add(random.nextInt(500)); } }
9ea94864-ffd2-4bd0-9799-f0092ece1bd9
private void pingServerB() { synchronized (lock2) { // simulate pinging a server by sleeping for some time try { Thread.sleep(1); } catch (InterruptedException e) { e.printStackTrace(); } serverB.add(random.nextInt(500)); } }
36fdb987-681a-4029-a77a-1c9ae90b0ecd
private void processServers() { for(int i = 0; i < 1000; i++) { pingServerA(); pingServerB(); } }
8c9b1bc7-3cad-4982-abcd-ff8941044cec
public void invodeProcess() { System.out.println("Starting server check ... "); long start = System.currentTimeMillis(); Thread t1 = new Thread(new Runnable() { @Override public void run() { processServers(); } }); Thread t2 = new Thread(new Runnable() { @Override public void run() { ...
8d82aa34-0044-400e-a20b-7bf81b1c7cc4
@Override public void run() { processServers(); }
cde64bc0-b7b0-468d-8729-1fd43d172756
@Override public void run() { processServers(); }
32b65bfd-3f2a-41bf-b3f4-672135c6d196
public static void main(String a[]) { ExecutorService executor = Executors.newFixedThreadPool(2); for(int i = 1; i <= 5; i++) { executor.submit(new Processor(i)); } executor.shutdown(); System.out.println("All the tasks submitted ... "); try { executor.awaitTermination(3, TimeUnit.DAYS); ...
7504ef44-6094-4244-9935-79e0a5e4d23e
public void test() { }
e598fe66-502a-4dfd-942c-a5e0dd49789b
public static String toXML( Object object ) { return object == null ? null : xmlConverter.toXML( object ); }
adb07852-d534-4ed5-94fe-86afc662d8a6
public static Object fromXML( String xml ) { return xml == null ? null : xmlConverter.fromXML( xml ); }
b062fa0f-27c6-46f0-8fb6-d7b1cb078959
private static String read (InputStream is) throws IOException { String data = null; if (is != null) { // read into a buffer BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null...