Linked list,。
Goals
The goals of this assignment are to:
- Understand, implement, and use linked chains of nodes.
- Write classes that implement Java interfaces.
- Gain experience working with Java references.
- Implement exceptions and understand the difference between checked and unchecked exception.
Description
In this assignment, your goal is to build an image viewer application with cache (i.e. CacheImageApp).
Computer networks are integral to all aspects of our lives. We routinely use these networks without giving a second thought to how a web of interconnected machines successfully conveys our information and that of millions of others. For this assignment, we’ll explore how computer networks ensure successful data transmission. Specifically, this program will simulate the transmission of an image over a computer network. You’ll be coding the receiver (i.e. SingleImageReceiver) that gets information packets from a simulated network and reconstructs an image file. We’ve already coded the image file’s sender and network simulator.
To transmit an image file, it is divided into numerous small data packets that are sent across the network. The reality is that networks are complicated and not very reliable. Packets might be lost or duplicated (to make life easier, packets are not corrupted in this assignment), and if that wasn’t enough, they arrive at the receiver out of order! To address this, a sequence number is given to each packet. This simple approach can be used to determine if there are any missing or duplicate packets, and also to arrange the received packets in the correct order to properly reconstruct the file.
As the receiver, your job is to collect all these packets, remove duplicates, request any that are missing, and put them in order by sequence number so that the image can be opened without errors. For missing packets, you’ll need to request re-transmission. The packets are stored in a singly-linked list with a header node but without a tail node. The data item for each node is one packet. If you’ve done your job well, you will have reconstructed the entire file as a complete and properly sequenced chain of packets so that it can be opened by our image viewer for you to see the picture. The following figure illustrates this process.
But sometimes an image file may be very large or the network may be very slow. And you may wish to request the same image many times. As it is really time-consuming to receive and reconstruct an image in this way again and again, your program will address this issue by using a cache. In computing, a cache is hardware or software that stores data so future requests for that data can be served faster.
What you need to do is first check whether the image is already in the cache when you want to receive an image file. If the image’s linked list is already in the cache, you don’t need to receive and reconstruct it again. If the image chain is not in the cache of image linked lists, you will receive it, and store its name and linked list in the cache. The following is the structure of the cache.
Specifications
Important Classes
PacketLinkedListClass
This class stores a sequence of packets and and is used to reconstruct the image file. It implements the methods defined in ListADT interface. Note: The ListADT interface in this program extends Iterable, so your list classes must also implement methods in Java’s java.lang.Iterable interface.
Iterating over lists is done with a PacketLinkedListIterator object (See next class description). The data structure used to create its iterator is a singly-linked chain of Listnode objects, where the Listnode sent to create the Iterator is the header node. There is no tail reference.
PacketLinkedListIteratorClass
Instances of this class are used to iterate through a PacketLinkedList object. The iterator has direct access to the PacketLinkedList’s chain of nodes.
It’s constructor accepts a Listnode (that is a header node). It implements the methods defined in Java’s java.lang.Iterator interface, but it does not support the remove() operation.
SingleImageReceiver Class
Instances of the class simulate a receiver for a single image by maintaining an image buffer, which is a linked list of packets of the transmitted image file. It collects packets from our InputDriver and reconstructs and stores the image file pack ⁆䍣䙯䵴⡥⁵⤮†††⁸⁴†⁵†⁷
ⱆ⁴†♲㭲†‼††㰠⽡㹤ഠ㱤㌠⁴㵭∠䕴ⴠⵦ≮㹹䔠ⵤ㰠⽤㌠㹮൯ੴ㰠㹥†⁹†⁴♥㭴䕩ⴠ♩㭮⸬††⁴††‼†䥫⁴⁴†䕉䙰⁵⡴䕄ⴠ䙣⥢‱†䤠⽔㱳⼠㹥ൡ੮㱳㹹䙯Ⱐ†⁰⁴㍨㉯⁷䅱ⱳ†′☠㬠⁴⁸⁴⁰‱⸬††⁵⁴‱⁉ⱥ†⁰†⁴⁵⁴†⸦䙳ⱴ※䕴ⴵⵧ†⁵†⁴†㍯㉮
††⁶†ⁱ䥫Ⱪ⁸⁴†⁴⁰ⁱ䙶ⱹ⁌⁴⁵†ㅴ†㍢づⰠ♥㭩⁷⁴㱰⽡㹥ഠ㱦㹥䕣ⵣ⁴†⁷䤠䥯䐠†⁶䘠⡥⤠⁹⁹䤠†⁹䕮ⵯⴠ⁵♢㭧 ‼†⁃䙥䵡⠾⥡⁰″ぬ††䕴ⴠ⁸䉥⁶⁰†ⵡ††䥩†ⵡ†⁵ⱬ䕯⁰ ⸠㱲⽥㹲൩㱶㉉㵥∠䥭ⵤ∠㹣䥨⼠㱲⼠㉨㹥ഠ੩㱭㹧䅥䤠Ᵽ†ⵤ䤠ⱥ†⡮⁴†⥥⁌†♭㭣⁌⁌†♷㭹†䤠䑮†♥㬠⁴⁴⁴⸾⁹♬㭹⁵♯㭬⁹†Ⱐ⁴⁹†♗㭧⸠☦㬻⁴⠠⁰㵩でⰠ⁴ㅨⱥ†ⱡ㡥⤠䔠ⱱ⁵⁴䍭䤠䅴††⁉†㈠†㱥⽮㹭ൡ੧㱥㹭䅥⁹ⱥ†♥㭥䥭䑭⁴†††⁶⡥䱰䱧⥥⁴䱯䱮䥯⁴⁴††⁹ ⸽•䥃䑥⁒⁵䍮䥯䅬♦㭮⁴䥩⡨⤲‾㱤⼽㹄൵ੰ㱬㹣⁄䥫⼯⁰㩮㱲⽭㹬ഠੴ㱲㹭㱩㹮䔠っ⁴㩰ば⁴䥥†㴨ぴ䱭⁵
⸠䕥†ね††⁰㩡㠯‼†䤼㵣㡥䰠⸠䕮び†⁴㨍 㡩⸾䤠㵫㡴⸠䱯†⁴†䕯ち㨾《‼䕥⁶㱥⽲㹤㱳⼠㹲ਠ㱡㹥⁰⁴⁴⁰†㱶⽥㹡൮㰠㹩⁴䤬䐠䑰 ⁍⸠㱐⽡㹫ੴ㱳㹨ളਾ ‼⁰㰾㹣っㅯ㩮㱨⽲㹧൨ਠ†㱴㹲⁴㉨†㍡㩳⁴※†⁷㱴⽨㹥ഠ†㱮㹭†㑰ⵣ㙥㩴†††㱓⽴㹡൭੩†⁎㱯㹦㜠⁐ⵡ㡫㩥⁴⁴Ᵽ⁰⁵⸀㰀⼀㸀ഀ㰀⼀㸀ഀ㰀㈀ 㴀∀ⴀ䘀∀㸀 䘀㰀⼀㈀㸀ഀ㰀㸀 䌀䤀䄀 ☀㬀 ⸀㰀⼀㸀ഀ㰀㸀ഀ 㰀㸀䤀 ☀㬀 ☀㬀Ⰰ ⸀㰀⼀㸀ഀ 㰀㸀䤀 Ⰰ ഀ 㰀㸀ഀ 㰀㸀 䤀 ⸀ 䤀 Ⰰ 䰀䰀 ⸀ Ⰰ 䤀 ⸀㰀⼀㸀ഀ 㰀㸀 䤀 㬀 Ⰰ Ⰰ ⸀ ⠀ ⸀⤀㌀⸀ 㰀⼀㸀ഀ 㰀㸀䤀 Ⰰ 㰀⼀㸀ഀ 㰀⼀㸀ഀ 㰀⼀㸀ഀ 㰀㸀 ⠀ ⤀㰀⼀㸀ഀ 㰀㸀 ⸀㰀⼀㸀ഀ㰀⼀㸀