I got an error message
---------------------------
java.io.FileNotFoundException: (Result too large) at java.io.FileInputStream.open0(Native Method) at java.io.FileInputStream.open(Unknown Source) at java.io.FileInputStream.(Unknown Source) at java.util.Scanner.(Unknown Source) at listhomework.LinkedList.main(LinkedList.java:348)
--------------------------------------
package listhomework; //
public class Node { //Members with level access Tier1 category1; Tier2 category2; Tier3 category3; Nodeleft = null; Noderight = null; Nodedown = null; /** * Constructor to initialize the category member variables by using the arguments * @param t1 value for category1 * @param t2 value for category2 * @param t3 value for category3 */ public Node(Tier1 t1,Tier2 t2,Tier3 t3){ // this.category1=t1; // this.category2=t2; // this.category3=t3; category1=t1; category2=t2; category3=t3; }
// cate1 // cate2 // cate3 public Tier1 getCategory1(){ //1 return category1; }
public void setCategory1(Tier1 category1){//1 this.category1 = category1; }
public Tier2 getCategory2(){//2 return category2; }
public void setCategory2(Tier2 category2){//2 this.category2 = category2; }
public Tier3 getCategory3(){//3 return category3; }
public void setCategory3(Tier3 category3){//3 this.category3 = category3; }
//testing // //public String toString(){ // return "["+category1+","+category2+","+category3+"]"; //} ........... }
--------------------------------------
package listhomework;
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner;
public class LinkedList{
protected Node head; // the head of linked lists protected int size; // total number of element in the main and sublists protected int groupingCategory; protected String category1Label, category2Label, category3Label; // labels for 3 cates
public LinkedList(){ groupingCategory = 1; // set default } public LinkedList(int category){ groupingCategory=category; } public LinkedList(File file, int category)throws FileNotFoundException{ groupingCategory=category; } public void add(Tier1 value1, Tier2 value2, Tier3 value3){ Nodenode = new Node (value1, value2, value3); if( head == null){ // empty list head = node; } else{ Node p = head; // from beginnnnnnng boolean inserted = false; while(!inserted){ if( // if groupingCategory == 1 and node's category also matches or // if groupingCategory == 2 and node's category also matches or // .......................3.................................. (groupingCategory==1 && p.getCategory1().equals(node.getCategory1())) || // ??? change static? fixed (groupingCategory==2 && p.getCategory2().equals(node.getCategory2())) || // node != Node (groupingCategory==3 && p.getCategory3().equals(node.getCategory3()))) // // found the correct one (sublist) { // go down the sublist to end and add while(p.down!= null) // stop at last node of sublist { p = p.down; } p.down = node; inserted = true; } else{ if(p.right != null){ // move to next mainlist p = p.right; } else{ p.right = node; // last.left to new node node.left = p; // node.right = last node (mainlist) inserted = true; } } } } size ++; } public void clear(){ head = null; size = 0; } //delete first node public void deleteFirst(){ delete(0,0); // mainlyindex, subindex }
public void deleteLast(){ int mainIndex=0; Node p=head; //get the last index in main list while(p.right!=null) { p=p.right; mainIndex++; } //reuse the function to delete a node given mainindex and subindex delete(mainIndex,0); }
public void delete(int mainIndex, int subIndex){ if(mainIndex < 0 || head == null){ throw new IndexOutOfBoundsException(" the mainly index out of bound " + mainIndex); } if(subIndex< 0 || head == null){ throw new IndexOutOfBoundsException(" the sub index out of bound " + subIndex); } // ------------------------------ int mi=0; //mainindex int si=0; //subindex Node p=head,prev=null; while(mi newnode=p.down,left=p.left,right=p.right; if(subIndex>0) //not the 1st node in sublist { prev.down=newnode; //simply link the previous top node to the next bottom node ignoring the current node } else // its the first node in the sublist { if(left==null) //there is no left node and its 1st in sublist, so its the head node { head=newnode; //update head } else left.right=newnode; // set up all links from leftside and rightside of mainlist to this newnode from sublist moving up if(newnode!=null) { newnode.left=left; newnode.right=right; } if(right!=null) right.left=newnode; } size--; } public String get(int mainIndex, int subIndex, int category){ if(mainIndex<0 || head==null) throw new indexoutofboundsexception("index out of bound : "+mainindex); if(subindex<0 ) indexoutofboundsexception("sub index "+subindex); int mi =0; > p=head; while(mi 3 || groupingCategoryNumber < 0){ throw new IndexOutOfBoundsException(" Category out of bound: " + groupingCategoryNumber); } if(head==null) return; Node newhead=null,mainnode,subnode,p,right,down; boolean inserted=false; groupingCategory=groupingCategoryNumber; //set the new grouping category for(mainnode=head;mainnode!=null;mainnode=right) //for each node in mainlist { right=mainnode.right; for(subnode=mainnode;subnode!=null;subnode=down) //for each node in sublist { down=subnode.down; subnode.left=subnode.right=subnode.down=null; //clear old values if(newhead==null) { newhead=subnode; continue; } else { p=newhead; inserted=false; } while(!inserted) { //if grouping is by category 1 and both node's category1 values matches or //if grouping is by category 2 and both node's category2 values match or //if grouping is by category 3 and both node's category3 values match if( (groupingCategory==1 && p.getCategory1().equals(subnode.getCategory1())) || (groupingCategory==2 && p.getCategory2().equals(subnode.getCategory2())) || (groupingCategory==3 && p.getCategory3().equals(subnode.getCategory3()))) //found the correct sublist { //go down the sublist to end and add while(p.down!=null) //stop at the last node of sublist { p=p.down; } p.down=subnode; inserted=true; } else { if(p.right!=null) //move to next item in mainlist p=p.right; else //reached the end of main list { p.right=subnode; //link the last nodes right to new node subnode.left=p; //link the new nodes right to last node in mainlist inserted=true; } } } } } } // return size public int size(){ return size; } // int size ********** not finished public int size(int index){ if(index<0 || head==null) throw new indexoutofboundsexception("index out of bound : "+index); int mi=0,count=0; node p=head; while(mi list = new LinkedList(); // empty list try{ scanner = new Scanner(file); // read a file list.category1Label = scanner.nextLine(); list.category2Label = scanner.nextLine(); list.category3Label = scanner.nextLine(); scanner.nextLine(); // blank line Scanner linescanner; while(scanner.hasNext()){ // read date linescanner = new Scanner(scanner.nextLine()); linescanner.useDelimiter(","); // , separate list.add(new Integer(linescanner.nextInt()), linescanner.next(), linescanner.next()); // integer , string , string linescanner.close(); } scanner.close(); // // test test // }catch(FileNotFoundException e){ e.printStackTrace(); } } }