Question: need help for FileDict class public class MyFile{ private String fileName; private int priority; // higher value means higher priority /** * @return the fileName
need help for FileDict class
public class MyFile{ private String fileName; private int priority; // higher value means higher priority /** * @return the fileName */ public String getFileName() { return fileName; } /** * @param fileName the fileName to set */ public void setFileName(String fileName) { this.fileName = fileName; } /** * @return the priority */ public int getPriority() { return priority; } /** * @param priority the priority to set */ public void setPriority(int priority) { this.priority = priority; } /** * @param fileName * @param priority */ /* * Please don't change this implementation */ public MyFile(String fileName, int priority) { this.fileName = fileName; this.priority = priority; } /* (non-Javadoc) * @see java.lang.Object#toString() * Please don't change this implementation */ @Override public String toString() { return fileName + "|" + priority; } } //This is TestFileDict class import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; /** * * */ public class TestFileDict { FileDict dt; @Before public void setUp() { dt = new FileDict(); dt.add(new MyFile("Abe", 5)); dt.add(new MyFile("Sample", 1)); dt.add(new MyFile("Dock", 3)); dt.add(new MyFile("Book", 5)); dt.add(new MyFile("Note", 3)); } @Test(timeout = 100) public void testdisplay() { String ret = "[Note|3, Book|5, Dock|3, Sample|1, Abe|5]"; assertEquals(ret, dt.display()); } @Test(timeout = 100) public void testlruFile1() { assertEquals("Abe", dt.lruFile().getFileName()); } @Test(timeout = 100) public void testremove() { String ret = "[Note|3, Book|5, Dock|3, Sample|1]"; dt.remove(); dt.display(); assertEquals(ret, dt.display()); } @Test(timeout = 100) public void testaccess1() { String ret = "[Abe|5, Note|3, Book|5, Dock|3, Sample|1]"; dt.access("Abe"); dt.display(); assertEquals(ret, dt.display()); } @Test(timeout = 100) public void testaccess2() { String ret = "[Book|5, Note|3, Dock|3, Sample|1, Abe|5]"; dt.access("Book"); dt.display(); assertEquals(ret, dt.display()); } @Test(timeout = 100) public void testaccess3() { String ret = "[Sample|1, Note|3, Book|5, Dock|3, Abe|5]"; dt.access("Sample"); dt.display(); assertEquals(ret, dt.display()); ret = "[Dock|3, Sample|1, Note|3, Book|5, Abe|5]"; dt.access("Dock"); dt.display(); assertEquals(ret, dt.display()); } /* @Test(timeout = 100) public void testreorder() { String ret = "[Book|5, Abe|5, Note|3, Dock|3, Sample|1]"; dt.reoderFiles(); dt.display(); assertEquals(ret, dt.display()); } */ } (need code for this class) import java.util.LinkedList; import java.util.ListIterator; /** * * Using linkedlist to implement FileDict to keep track of LRU (least recenlty used) and MRU (most recenlty used) files. In the implementation, the LRU file is placed at the end of the list and MRU is at the beginning. * */ public class FileDict { LinkedList filelst = new LinkedList(); /** * Add the file to the beginning of the list * @param file - the file to be added * @return false - if the file with the same name is already existed; true - the file added successfully * */ public boolean add(MyFile file) { // TO-DO return true; // remove this line after your implementation } /** * Remove the least recently added or accessed file, i.e. the LRU file (hint: the end of the list) * @param - the given file name * */ public MyFile remove() { // TO DO return null; // remove this line after your implementation } /** * Access a file with given filename, (Once accessed, the file become most recently used (MRU) ) * @param filename - the name of the file to access * @return the file accessed, or null if no such file exists */ public MyFile access(String filename) { // TO DO [hint: you need to move the access the file to the beginning of the list] return null; // remove this line after your implementation } /** * This method return the least recently used file, i.e. the file has not been accessed/used for the longest time * Should be done in O(1) time cost * * @return the least recently used file; or null if empty list */ public MyFile lruFile() { // TO DO return null; // remove this line after your implementation } public String display() { return filelst.toString(); } * Re-oder the files based on priorities, higher priority file placed first; ties are broken by * filename in alphabetical order * Hint: You may need to add CompareTo function in MyFile Class */ public void reoderFiles() { // TO-DO } }
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
