Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. public boolean equals(Object f){
  2. ArrayList<Object> a = this.list; //This.list as a variable a and the object f as a new Arraylist
  3. ArrayList<Object> b = ((FIFO) f).list; //Used to make the code neater.
  4.  
  5. if(f.getClass() != this.getClass()) { //if f is not of the same type as this class, throw error.
  6. throw new ClassCastException();
  7. }
  8.  
  9. if (a.size() != b.size()) {
  10. return false;
  11. }
  12.  
  13. for (int i=0; i < this.list.size(); i++) {
  14.  
  15. if (a.get(i) == null && b.get(i) != null ||
  16. a.get(i) != null && b.get(i) == null){ //If the element i in a is null, b must also be null.
  17. return false;
  18. }
  19.  
  20. if (a.get(i) != null){ //element i in a is a reference to obj1, then i is a reference to obj2 in f
  21. if (!a.get(i).equals(b.get(i))){ //compares the OBJECT a and b, not similiar to "==".
  22. return false; //evaluates to the comparison of values in the objects
  23. }
  24. }
  25. } return true;
  26. }
  27.  
  28.  
  29.  
  30. public String toString() {
  31. String queueString = "Queue: ";
  32. for(int i = 0; i < list.size(); i++) {
  33. queueString = queueString + "(" + String.valueOf(list.get(i)) + ") ";
  34.  
  35. } return queueString;
  36.  
  37. }
  38. }
  39.  
  40.  
  41. public class GraphIO {
  42.  
  43. public static void readFile(Graph g, String filename) throws IOException {
  44. try {
  45. File filip = new File(filename); //Filename specified in main somewhere.
  46. Scanner scania = new Scanner(filip); //Scanner to read the file.
  47. int n = scania.nextInt(); //Scans the next token of the input as an int
  48. for(int i = 0; i < n; i++){
  49. g.addNode(scania.nextInt(), scania.nextInt(), scania.nextInt()); //adds the first line as nodes.
  50. }
  51. while(scania.hasNextLine()){
  52. g.addEdge(scania.nextInt(), scania.nextInt(), scania.nextInt()); //Adds the remaining as edges.
  53. }
  54. scania.close();
  55. } catch(IOException e){
  56. throw new IOException();
  57. }
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement