import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.net.*;
import java.util.Random;
// Example program for the FavoriteList and FavoriteListMTF classes
public class FavoriteTester {
public static void main(String[] args) {
String[] urlArray = { "http://wiley.com",
"http://datastructures.net", "http://algorithmdesign.net",
"http://www.brown.edu", "http://uci.edu" };
FavoriteList L1 = new FavoriteList();
FavoriteListMTF L2 = new FavoriteListMTF();
int n = 20;
// Simulation scenario: access n times a random URL
Random rand = new Random();
for (int k=0; k<n; k++) {
int i = rand.nextInt(urlArray.length);
String url = urlArray[i];
System.out.println(url);
L1.access(url);
System.out.println("L1 = " + L1);
L2.access(url);
System.out.println("L2 = " + L2);
}
int t = L1.size()/2;
System.out.println("Top " + t + " in L1 = " + L1.top(t));
System.out.println("Top " + t + " in L2 = " + L2.top(t));
// Pop up a window of the most popular Web site in L1
try {
String popular = (String) L1.top(1).first().element();
JEditorPane jep = new JEditorPane(popular);
jep.setEditable(false);
JFrame frame = new JFrame(popular);
frame.getContentPane().add(new JScrollPane(jep), BorderLayout.CENTER);
frame.setSize(640, 480);
frame.setVisible(true);
} catch (IOException e) { // ignore I/O exceptions
}
}
}