id
stringlengths
36
36
text
stringlengths
1
1.25M
237431ff-e861-4611-9470-e809a9a6b376
public void cycle(long n) { for (long i = 1; i <= n; i++){ result = result * i; } System.out.println(result); //return result; }
96ea9c02-1cb0-4a13-b3d8-0a666a1f9600
public long recursion(long n) { if (n == 1){ return 1; } else result = recursion(n-1) * n; //System.out.println(result+"\n"); return result; }
77f41a99-dae2-4a23-bea7-a2ec92dd5b75
public BigInteger bigNumber(BigInteger n) { if (n.equals(BigInteger.ONE)){ return BigInteger.ONE; } else resultBig = bigNumber(n.subtract(BigInteger.ONE)).multiply(n); //System.out.println(resultBig.toString()+"\n"); return resultBig; }
b4c3257f-cdef-4571-8580-14188c711536
public static void main(String[] args) { LinkedList<Point> openList = new LinkedList<Point>(); LinkedList<Point> closedList = new LinkedList<Point>(); LinkedList<Point> tmpList = new LinkedList<Point>(); }
dbd607c0-a3ed-43b6-bf14-53c119a529b4
@Override public void printShortestPath(Point[][] map, Point start, Point end) { int leftX=start.getX()-1; int upY=start.getY()+1; int rightX=start.getX()+1; int downY=start.getY()-1; }
1f4c6690-bd49-43a3-aac4-4dac84c23f60
public void printShortestPath(Point[][] map, Point start, Point end);
f2f617ec-200a-4fcc-9a8b-c948447656e7
@Override public int getX() { return this.x; }
a1f3e4ed-023c-4e6d-9360-fa0d172828b3
@Override public int getY() { return this.y; }
23693d61-a537-4335-8de4-3b665ad68242
@Override public Point getParent() { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. }
a24d7ff2-e4e1-425b-adfd-171082d50769
@Override public void setParent(Point parent) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. }
8dc74ff8-c7c1-49c8-88bf-12c5eba3c908
public PointT(int x, int y, boolean blocked) { this.x = x; this.y = y; this.blocked = blocked; }
2ba08f7f-8179-4607-a1a3-26bf3834945e
public int mandist(PointT finish) { return 10 * (Math.abs(this.x - finish.x) + Math.abs(this.x - finish.x)); }
374044e6-7ec0-46f4-b7ba-2eded389d554
public int price(PointT finish) { if (this.x == finish.x || this.y == finish.y) { return 10; } else { return 14; } }
8c7ae68c-e0a4-4406-b75f-6839661d7fe4
public void setAsStart() { this.start = true; }
5accc72d-2976-4d7d-b796-e6ca99e82d4d
public void setAsFinish() { this.finish = true; }
cbf5bf09-a5a8-4430-b9a5-5bf207213cf0
public int getX();
e7125ee4-9472-4108-b005-3912f067578d
public int getY();
ece828c2-a3ed-4dd8-8a7b-e54cfd001c51
public Point getParent();
768e826e-8601-4773-9e94-f0a1b9c29e90
public void setParent(Point parent);
99ea8f6c-981b-4d8e-98fb-a6fde78d5233
private static int showMenu(){ System.out.println("\n1. Bubble sort."); System.out.println("2. Merge sort."); System.out.println("3. Count sort."); System.out.println("4. Tree sort."); System.out.println("0. Exit."); int userChoice = sc.nextInt(); return u...
ae246c1d-8af1-473f-bf6f-10903b1b6835
public static void main(String[] args) { System.out.print("Enter the array's length\n"); int userNumber = sc.nextInt(); int[] array = new int[userNumber]; for (int i = 0; i < userNumber; i++){ array[i] = r.nextInt(100); } Syst...
0183f6b2-3cbf-4c2e-aa70-e25768278f86
public void sort(int[] array);
c03c862e-edab-4174-9955-c48f06817a90
public void setDelegate(Sorter delegate) { this.delegate = delegate; }
e2cc8572-1116-4996-91fa-38e221c68832
public MegaSorter(Sorter delegate) { this.delegate = delegate; }
b72d1ff2-9dcb-489a-aef7-00cd3269b2b7
public void sort(int[] arr) { delegate.sort(arr); }
bb9cbc4d-4f89-4a86-92d0-3e50c2cc92a8
@Override public void sort(int[] array) { int i, j, b = 0; int[] c = new int[100]; for (i = 0; i < 100; i++) c[i] = 0; for (i = 0; i < array.length; i++) { c[array[i]] = c[array[i]] + 1; b = 0; } for (j = ...
4e346a1d-0d2a-4eb5-b185-6ce800ab0d49
@Override public void sort(int[] array) { }
7f683a67-9b22-4f00-ba42-a098715e17f6
private void swap(int[] arr, int i, int j) { int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; }
e83e8f85-022f-4d98-b525-1eabe3a523cb
@Override public void sort(int[] array) { for( int i = array.length-1; i > 0; i--){ for (int j = 0; j < i; j++) { if(array[j]>array[j+1]){ swap(array, j ,j+1); } } } }
9eef8974-d995-4b21-9a1b-0e1667f4bd3d
@Override public void sort(int[] array) { if (array.length > 1) { // split array into two halves int[] left = leftHalf(array); int[] right = rightHalf(array); // recursively sort the two halves ...
841c72b0-03e9-4709-b04d-717ff5576629
public static int[] leftHalf(int[] array) { int size1 = array.length / 2; int[] left = new int[size1]; for (int i = 0; i < size1; i++) { left[i] = array[i]; } return left; }
c2e1594f-1a80-4386-bb46-89afdb11fae7
public static int[] rightHalf(int[] array) { int size1 = array.length / 2; int size2 = array.length - size1; int[] right = new int[size2]; for (int i = 0; i < size2; i++) { right[i] = array[i + size1]; } ...
bc64d49a-7d0e-4ef4-89c0-db58506a3d35
public static void merge(int[] result, int[] left, int[] right) { int i1 = 0; // index into left array int i2 = 0; // index into right array for (int i = 0; i < result.length; i++) { if (i2 >= right.length || (i1 < left.length && ...
e0d823e9-106e-488a-9a0c-9a4b70eeabbe
private Normalise(final File theFile, NormaliseCLI cli) { file = theFile; tabSize = cli.getTabSize(); retainOddSpaces = cli.isKeepingOddSpaces(); retainBlankLines = !cli.isDiscardingBlankLines(); }
15627497-71b7-4f96-9711-934dfee6a3e2
private static void croak(final String s, final Exception e) { e.printStackTrace(); System.err.println("Internal error: " + s + ": " + e.getMessage()); System.exit(1); }
9c5bf7b3-a43a-4dfd-abe0-ca8630fb32b0
private CharArrayWriter process(final Reader in) throws IOException { final CharArrayWriter w = new CharArrayWriter(); final WhitespaceNormaliser norm = new WhitespaceNormaliser(retainOddSpaces, retainBlankLines, tabSize); norm.process(in, w); return w; }
0cbd6041-1ac0-41be-b711-2679291c68a7
public void run() { /* * Open the input file and then process it. */ CharArrayWriter w; try (InputStream is = new FileInputStream(file); Reader in = new BufferedReader(new InputStreamReader(is, "UTF-8"))) { /* * Run through the input fi...
be9f49a6-705a-40c4-a895-f0d94aa4672e
public static void main(final String[] args) { final String progName = "Normalise"; final NormaliseCLI cli = new NormaliseCLI(); final JCommander jc = new JCommander(cli); jc.setProgramName(progName); try { jc.parse(args); } catch (ParameterException ...
f02d43d0-b409-4317-ab2d-740844274ffe
public List<String> getParameters() { return parameters; }
39fd1436-0c93-4fdc-b1bb-6713c74b103c
public boolean isHelp() { return help; }
91088c1b-299e-4340-b0be-ba2e24a4e3ee
public int getTabSize() { return tabSize; }
04f451a6-f2e3-48f3-a1ad-40356097c525
public boolean isDiscardingBlankLines() { return discardingBlankLines; }
e925d8dd-c9fd-47f4-a3a0-9ec467d9a651
public boolean isKeepingOddSpaces() { return keepingOddSpaces; }
229c0f35-c409-476b-942b-2af2f2042005
public void validate(String name, String value) { try { int n = Integer.parseInt(value); if (n < 1 || n > 16) { throw new ParameterException("Parameter " + name + " must be in the range 1 to 16 (found " + value + ")"); } } catch...
6922ac82-5748-4aac-a272-65d5d04095f9
public WhitespaceNormaliser(final boolean retainOddSpaces, final boolean retainBlankLines, final int spacesPerTab) { retainingOddSpaces = retainOddSpaces; retainingBlankLines = retainBlankLines; tabSize = spacesPerTab; }
a320e17b-caf4-4ed5-a524-6ab6f335afd3
public void process(final Reader in, final Writer out) throws IOException { // Checkstyle:CyclomaticComplexity|MethodLength ON // amount of leading white space int lead = 0; // processing the start of the line boolean start = true; for (;;) { ...
2e4db2be-a468-4d24-8c83-ff03b5ee4379
private Reader acquireResource(String fileName) throws IOException { final String resourceName = "/" + fileName; final InputStream is = WhitespaceNormaliserTest.class.getResourceAsStream(resourceName); if (is == null) { throw new IOException("resource " + resourceName + " not found")...
33444f22-cb3e-4cd4-9cff-b2388589aa40
private String acquireString(String fileName) throws IOException { final Reader in = acquireResource(fileName); final StringBuilder sb = new StringBuilder(); for (;;) { final int c = in.read(); if (c == -1) { break; } sb.append((cha...
d57747db-818d-4172-b38b-a0a2d32ba791
@Test public void standardOptions() throws IOException { final Reader in = acquireResource("standardOptionsIn.txt"); final String expected = acquireString("standardOptionsOut.txt"); final Writer out = new StringWriter(); final WhitespaceNormaliser norm = new WhitespaceNormaliser(fals...
eb47b139-ca88-46ed-95ba-0f389a04c6b8
@Test public void noBlankLines() throws IOException { final Reader in = acquireResource("noBlankLinesIn.txt"); final String expected = acquireString("noBlankLinesOut.txt"); final Writer out = new StringWriter(); final WhitespaceNormaliser norm = new WhitespaceNormaliser(false, false,...
c3cea678-b8dc-4f27-a398-5f24a09cfca3
@Test public void tabSize() throws IOException { final Reader in = acquireResource("tabSizeIn.txt"); final String expected = acquireString("tabSizeOut.txt"); final Writer out = new StringWriter(); final WhitespaceNormaliser norm = new WhitespaceNormaliser(false, true, 3); nor...
1323a4ff-9575-4ea1-98c8-b312cdb24db9
@Test public void oddSpaces() throws IOException { final Reader in = acquireResource("oddSpacesIn.txt"); final String expected = acquireString("oddSpacesOut.txt"); final Writer out = new StringWriter(); final WhitespaceNormaliser norm = new WhitespaceNormaliser(true, true, 4); ...
17bfa268-559c-492c-b20a-ad3b32713e34
private void expectException(String[] args) { NormaliseCLI cli = new NormaliseCLI(); try { new JCommander(cli, args); } catch (ParameterException pe) { // this is expected return; } Assert.fail("expected a parameter exception"); }
4d0e6cb6-e9c3-49bb-8220-b04880b6d0e9
@Test public void tabSize() { NormaliseCLI cli = new NormaliseCLI(); new JCommander(cli, new String[]{"--tabSize=5"}); Assert.assertEquals(cli.getTabSize(), 5); // test some bad values expectException(new String[]{"--tabSize=bad"}); expectException(new String[]{"--ta...
c313123f-c5ef-4cb7-9793-6e7f5e652d9d
public String getPaises() { return paises; }
4a85edef-0e4e-43d5-b777-30c5915b521b
public void setPaises(String paises) { this.paises = paises; }
a77c72d9-5163-40a9-89a7-6bc82b252df4
public Paises() { }
f585dec8-fd12-4a35-a844-5cf6ca9c4d27
public String Paises(){ String paises = ""; return paises; }
00934c10-c985-4056-8fef-193d2ae2d15d
public Paises(String paises) { this.paises = paises; }
8c97fd53-8927-4636-8421-185081500fc7
public static void main(String[] args) { Controller c = new Controller(); Random r = new Random(); int num = r.nextInt(3); if(num==0) { for (int v=0; v<10; v++){ System.out.println(c.iniciarTimes()); } } else if (num==1) { for (int v=0; v<10; v++){ System.out.println(c.iniciarBandas...
9ff64a6f-2a73-4b6c-b015-25778214c5bd
public String getBandas() { return bandas; }
5d101c11-ba2a-40ae-8ef8-33af0b9dfc11
public void setBandas(String bandas) { this.bandas = bandas; }
8b6190bf-d6c1-45b3-a3c4-32301c09b727
public Bandas(String bandas) { this.bandas = bandas; }
17b9667f-8268-4bdf-89bb-8e150b731c76
public String getTimes() { return times; }
dbe53771-20ea-4ea3-a8a7-289b37057ed0
public void setTimes(String times) { this.times = times; }
d9af7f57-9745-4fdb-8a5f-d5198585d53c
public Times(String times) { this.times = times; }
0dafccc2-252a-4385-a437-89d9986c4924
public String iniciarTimes() { //inicia objetos --- ja com os valores , nomes dos times Times t0 = new Times("Sao Paulo"); Times t1 = new Times("Corinthians"); Times t2 = new Times("Palmeiras"); Times t3 = new Times("Santos"); Times t4 = new Times("Real Madrid"); Times t5 = new Times("Barcelona"); T...
586e0e20-5e4a-459d-82d3-430ed3c771fe
public String iniciarBandas() { //inicia objetos --- ja com os valores , nomes dos times Bandas t0 = new Bandas("Metallica"); Bandas t1 = new Bandas("Corinthians"); Bandas t2 = new Bandas("Palmeiras"); Bandas t3 = new Bandas("Santos"); Bandas t4 = new Bandas("Real Madrid"); Bandas t5 = new Bandas("Bar...
974c29a4-2e19-46e6-ad81-9200fc1fac5b
public String iniciarPaises() { //inicia objetos --- ja com os valores , nomes dos Paises Paises t0 = new Paises("Brasil"); Paises t1 = new Paises("Corinthians"); Paises t2 = new Paises("Palmeiras"); Paises t3 = new Paises("Santos"); Paises t4 = new Paises("Real Madrid"); Paises t5 = new Paises("Barce...
9786f93e-934e-4a59-938f-1e54329d98d7
public ControlUI(DataStore ds) { // initComponents(); // The GUI code, generated by NetBeans is not called this.ds = ds; initComponents(); setTitle("Styrsystem grupp 3"); }
2b0f5680-3196-49f8-b636-ba846d51da1f
public void appendStatus(String text) { jTextArea1.append(text + "\n"); jTextArea1.setCaretPosition(jTextArea1.getDocument().getLength()); }
e15fb333-7898-43e3-a0cb-4503782a73e3
public void showStatus() { jTextArea1.append("Nodes: " + ds.nodes + "\n"); jTextArea1.append("Arcs: " + ds.arcs + "\n"); jTextArea1.append("Shelves: " + ds.shelves + "\n"); // jTextArea1.append("\nGrupp 3\n"); }
c80e3900-ba09-4234-b3d6-db01c2ceca79
@SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { fileChooser = new javax.swing.JFileChooser(); jPanel1 = new javax.swing.JPanel(); jScrollPane1 = new javax.swing.JScrollPane(); ...
0a8f13a0-3fa8-4055-a852-a4a2edd768c3
public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); }
fd8d459a-1251-41db-b913-d0264fa86c3e
public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); }
9ce6dc5f-bce9-4bbf-9e06-d12d9244af21
@Override public boolean accept(File file) { // Allow only directories, or files with ".txt" extension return file.isDirectory() || file.getAbsolutePath().endsWith(".txt"); }
9851fb2b-07ff-4bbe-accc-f696b7c8b594
@Override public String getDescription() { // This description will be displayed in the dialog, // hard-coded = ugly, should be done via I18N return "Text documents (*.txt)"; }
d2f0ecd9-184b-4686-9401-e38a0c678e76
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed jTextArea1.append("\nStarta optimeringen\n"); ds.start = true; }//GEN-LAST:event_jButton1ActionPerformed
e88379c8-81a7-4a1e-881d-a735081dbf28
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed jTextArea1.append("\nStopp men kör klart ordern först\n"); ds.start = false; }//GEN-LAST:event_jButton3ActionPerformed
24e1ace7-3dfe-4df0-85bf-093b233ce0a7
public OptPlan(DataStore ds) { this.ds = ds; nodes = new ArrayList<Vertex>(); edges = new ArrayList<Edge>(); int diff; for (int i = 0; i < ds.nodes; i++) { Vertex lovation = new Vertex("" + (i + 1), "Nod #" + (i + 1)); //System.out.println("lovation.getId...
a8fd7286-be61-4dc6-81ee-3d4315e7e9bd
public LinkedList<Vertex> createPlan(int start, int stop, int color, boolean intekrock) { LinkedList<Vertex> path; Graph graph = new Graph(nodes, edges); DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(graph, ds); // Compute shortest path dijkstra.execute(nodes.get(start - 1))...
a121126b-7cee-4e6a-bc79-feab47ad7106
MapPanel(DataStore ds) { this.ds = ds; }
71afcab2-2d4e-431a-a6b5-6a5cea227522
protected void paintComponent(Graphics g) { super.paintComponent(g); final Color LIGHT_COLOR = new Color(150, 150, 150); final Color DARK_COLOR = new Color(0, 0, 0); final Color RED_COLOR = new Color(255, 0, 0); final Color BLUE_COLOR = new Color(0, 0, 200); final Color G...
2ca62beb-395e-4faf-9c2f-b69d747c40a3
public GuiUpdate(DataStore ds, ControlUI cui) { this.cui = cui; this.ds = ds; sleepTime = generator.nextInt(20000); }
d6620405-093b-4805-b4d8-4ad0774c68a8
@Override public void run() { try { while(!ds.updateUIflag){ Thread.sleep(100); } cui.appendStatus("GuiUpdate startar och kommer att köra i " + sleepTime + " millisekunder."); int i = 1; while (i <= 20) { ...
02465d5f-d9e7-40fa-be63-42938fe50726
public Edge(String id, Vertex source, Vertex destination, int weight) { this.id = id; this.source = source; this.destination = destination; this.weight = weight; }
2ce0082b-f624-452e-84c5-8e65a551864a
public String getId() { return id; }
7d3b7a4a-252b-4268-806d-2f135fd008b5
public Vertex getDestination() { return destination; }
1d819d4f-367c-4755-b16e-38305257b89c
public Vertex getSource() { return source; }
f310d910-c384-4f45-a54c-aa9900a315ed
public int getWeight() { return weight; }
363b0310-2c09-403d-aaa5-9c44c187e756
@Override public String toString() { return source + " " + destination; }
f8096cda-bbae-4118-b669-84b4b1e8bd79
public DataStore() { // Initialize the datastore with fixed size arrays for storing the network data nodes = 0; arcs = 0; shelves = 0; nodeX = new double[99]; nodeY = new double[99]; arcStart = new int[1000]; arcEnd = new int[1000]; /* ...
c34f56f7-73d5-4452-ae0f-651a1c9df70b
public void setFileName(String newFileName) { this.fileName = newFileName; }
149a9572-44a3-4cca-b657-dc35ef8d568e
public String getFileName() { return fileName; }
ba939bec-03a0-44bd-8a36-6587ec5becdb
public void readNet() { final Color BLUE_COLOR = new Color(0, 0, 200); String line; if (fileName == null) { System.err.println("No file name set. Data read aborted."); return; } try { File file = new File(fileName); Scanner scanner...
522218b9-0d35-452b-ac3b-ef4936c35be9
public void readOrders() { String line; if (fileName == null) { System.err.println("No file name set for order list. Data read aborted."); return; } try { File file = new File(fileName); Scanner scanner = new Scanner(file, "iso-8859-1"); ...
b135f28a-79f3-462d-bbd4-7038298d82c1
public Vertex(String id, String name) { this.id = id; this.name = name; }
c1d8f4fc-4ee9-4062-bc1e-ad1eb4b3569c
public String getId() { return id; }
5eab19e7-10f3-4a05-a21e-3ca39a69233e
public String getName() { return name; }
84e6ab63-bc9a-44fc-907c-4eb93581eeed
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((id == null) ? 0 : id.hashCode()); return result; }