Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean equals(Object f){
- ArrayList<Object> a = this.list; //This.list as a variable a and the object f as a new Arraylist
- ArrayList<Object> b = ((FIFO) f).list; //Used to make the code neater.
- if(f.getClass() != this.getClass()) { //if f is not of the same type as this class, throw error.
- throw new ClassCastException();
- }
- if (a.size() != b.size()) {
- return false;
- }
- for (int i=0; i < this.list.size(); i++) {
- if (a.get(i) == null && b.get(i) != null ||
- a.get(i) != null && b.get(i) == null){ //If the element i in a is null, b must also be null.
- return false;
- }
- if (a.get(i) != null){ //element i in a is a reference to obj1, then i is a reference to obj2 in f
- if (!a.get(i).equals(b.get(i))){ //compares the OBJECT a and b, not similiar to "==".
- return false; //evaluates to the comparison of values in the objects
- }
- }
- } return true;
- }
- public String toString() {
- String queueString = "Queue: ";
- for(int i = 0; i < list.size(); i++) {
- queueString = queueString + "(" + String.valueOf(list.get(i)) + ") ";
- } return queueString;
- }
- }
- public class GraphIO {
- public static void readFile(Graph g, String filename) throws IOException {
- try {
- File filip = new File(filename); //Filename specified in main somewhere.
- Scanner scania = new Scanner(filip); //Scanner to read the file.
- int n = scania.nextInt(); //Scans the next token of the input as an int
- for(int i = 0; i < n; i++){
- g.addNode(scania.nextInt(), scania.nextInt(), scania.nextInt()); //adds the first line as nodes.
- }
- while(scania.hasNextLine()){
- g.addEdge(scania.nextInt(), scania.nextInt(), scania.nextInt()); //Adds the remaining as edges.
- }
- scania.close();
- } catch(IOException e){
- throw new IOException();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement