AIBased Problem Solving
To conclude this book, we will examine a topic from an interesting discipline of programming artificial intelligence AI . As explained earlier, the goal of this book is to show the richness and power of the Java language. Perhaps nothing demonstrates that better than its application to the demanding realm of artificial intelligence. Java's powerful string-handling capabilities and Stack class streamline many types of AI-based code. Java's object model keeps the code clean, as does its garbage...
The stateChanged Method
In order for the Download Manager to display up-to-date information on each of the downloads it's managing, it has to know each time a download's information changes. To handle this, the Observer software design pattern is used. The Observer pattern is analogous to an announcement's mailing list where several people register to receive announcements. Each time there's a new announcement, each person on the list receives a message with the announcement. In the Observer pattern's case, there's an...
An Overview of the Download Manager
The Download Manager uses a simple yet effective GUI interface built with Java's Swing libraries. The Download Manager window is shown in Figure 4-1. The use of Swing gives the interface a crisp, modern look and feel. The GUI maintains a list of downloads that are currently being managed. Each download in the list reports its URL, size of the file in bytes, progress as a percentage toward completion, and current status. The downloads can each be in one of the following different states...
The getValueAt Method
The getValueAt method, shown next, is called to get the current value that should be displayed for each of the table's cells Get value for a specific row and column combination, public Object getValueAt int row, int col Download download Download downloadList.get row switch col case 0 URL return download.getUrl case 1 Size return size -1 Integer.toString size case 2 Progress return new Float download.getProgress case 3 Status return This method first looks up the Download corresponding to the...
The isRobotAllowed Method
The isRobotAllowed method fulfills the robot protocol. In order to fully explain this method, we'll review it line by line. The isRobotAllowed method starts with these lines of code String host urlToCheck.getHost .toLowerCase Retrieve host's disallow list from cache. ArrayList disallowList ArrayList disallowListCache.get host If list is not in the cache, download and cache it. if disallowList null In order to efficiently check whether or not robots are allowed to access a URL, Search Crawler...
The MessagesTableModel Class
The MessagesTableModel class houses E-mail Client s list of messages and is the backing data source for the Messages JTable instance. The MessagesTableModel class is shown here. Notice that it extends AbstractTableModel import java.util. import javax.mail. import javax.swing. import javax.swing.table. This class manages the e-mail table s data. public class MessagesTableModel extends AbstractTableModel These are the names for the table s columns. private static final String columnNames Sender,...

