You will be completing the implementation of a program that I have started. Your
ID: 674341 • Letter: Y
Question
You will be completing the implementation of a program that I have started. Your job will be to provide correct implementations and unit tests for two classes: Cache and CacheList. Begin by running P6Demo.jar. Use the file chooser that pops up to navigate to and open the file caches.txt. The program will then open an application that lets you search through the contents of caches.txt. When you have completed this assignment, your program should behave just like the demo program you have just run. The three source files define three classes: Cache, CacheList, GeocacheBrowser, and CacheTests. You should not modify GeocacheBrowser. Unless you are curious, you do not need to understand it or even look at it. GeocacheBrowser contains a main method. Run it, and it will bring up the same application as the jar file. Most everything will be blank, however, until you complete Cache and CacheList. The application uses Cache objects (implemented by your Cache class) to represent individual caches. It uses a CacheList object (implemented by your CacheList class) to keep track of, filter, and sort all the Cache objects. Please read and follow the directions carefully. Cache The Cache class provides objects that represent information about a single geocache. The class file contains complete specifications as well as a completed implementation for the toString method. You should Read carefully through the entire class file. Create a complete set of unit tests for for the Cache class. I have created a test class called CacheTests that contains a sample test. We will spend some time in the next lecture and lab on testing classes. The TAs and I will not help you with your Cache class implementation until you have completed this step! Design a representation and then declare and comment member variables. Implement the constructor. Each line of the file caches.txt is an example of a string that the constructor should be able to take as a parameter. (Hint: Use the String split method.) Implement the methods (other than toString, which is already complete). Test/debug/modify your Cache and CacheTests classes until you are certain that the Cache class behaves according to its specifications. CacheList The CacheList class provides objects that represent collections of Caches as well as constraints on them. The class file contains complete specifications as well as a partial implementation. You should Read carefully through the entire class file. Create a complete set of unit tests for for the CacheList class. Call the test class CacheListTests. We will spend some time in the next lecture and lab on testing classes. The TAs and I will not help you with your CacheList class implementation until you have completed this step! Design a representation and then declare and comment member variables. Please note that I have already provided a key part of the representation. Complete the implementation of the constructor. The file caches.txt is an example of the kind of file that the constructor should be able to process. Please note that I have included code that shows how to sort a list of Cache objects. Implement the methods. Please note that the partial implementation of getOwners that I have provided shows how to sort a list of Strings. Test/debug/modify your CacheList and CacheListTests classes until you are certain that the CacheList class behaves according to its specifications. GeocacheBrowser If you have correctly implemented Cache and CacheList, your GeocacheBrowser should behave identically to the example implementation. If it doesn't, the problem is with either Cache or CacheList.
Explanation / Answer
mports System.Web
Public Class CacheManager
Private ListKey As String = "MyList"
Public Shared ReadOnly Property TypedList As List(Of Integer)
Dim cachedObject As Object
Dim myList As List (Of Integer)
Dim userCacheKey As String = ListKey & HttpContext.Current.User.Identity.Name
'First check to see if List is in the cache already
cachedObject = HttpRuntime.Cache.Get(userCacheKey)
If cachedObject Is Nothing Then
'If List isn't in the cache already then get it...
myList = Code to retrieve list members goes here
' ...and now we've got it put it in the cache
HttpRuntime.Cache..Add(key:=userCacheKey, value:=myList, absoluteExpiration:=HttpRuntime.Cache.NoAbsoluteExpiration, slidingExpiration:=New TimeSpan(0,5,0), dependencies:=Nothing, onRemoveCallback:=Nothing, priority:=CacheItemPriority.Default)
Else
'List is already in the cache but everything comes out of the cache as System.Object so cast it to List (Of Integer)
myList = DirectCast(cachedObject, List (Of Integer))
End If
'Now we have List, return it to the caller
Return myList
End Property
End Class
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.