⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 htmlborrowersformatter.java

📁 ssd3的教程 是我们老师给我们的 纯英文 有兴趣的可以
💻 JAVA
字号:
/*!Begin Snippet:file*/
import java.util.*;

/**
 * This class implements a method that obtains an HTML
 * representation of a {@link BorrowerDatabase} object.
 *
 * @author author name
 * @version  1.0.0
 * @see BorrowersFormatter
 * @see BorrowerDatabase
 * @see Borrower
 * @see BorrowedItems
 * @see CatalogItem
 */
public class HTMLBorrowersFormatter
	implements BorrowersFormatter  {

	/* Line separator*/
	private final static String NEW_LINE = System.getProperty("line.separator");

	/* single instance of this class */
	static private HTMLBorrowersFormatter singletonInstance = null;

	/**
	 * Obtains the single instance of class
	 * <code>HTMLBorrowersFormatter</code>
	 *
	 * @return the single instance  of class
	 *         <code>HTMLBorrowersFormatter</code>
	 */
	static public HTMLBorrowersFormatter getSingletonInstance() {

		if (singletonInstance == null) {
			singletonInstance = new HTMLBorrowersFormatter();
		}

		return singletonInstance;
	}

	/*
	 * The constructor is declared private so other classes cannot
	 * create an instance of this class.
	 */
	private HTMLBorrowersFormatter() {

	}

	/**
	 * Obtains an HTML representation of the specified borrower
	 * database.
	 *
	 * @param borrowerDB  the borrower database.
	 * @return  an HTML representation of the specified
	 *          {@link BorrowerDatabase} object.
	 */
	public String formatBorrowers (BorrowerDatabase borrowerDB) {

		String out = "<html>"
				+ NEW_LINE
				+ "  <body>"
				+ NEW_LINE + ""
				+ "    <center><h2>Borrower Database</h2></center>"
				+ NEW_LINE;

		for (Iterator i = borrowerDB.getBorrowersIterator();
			i.hasNext();) {

			Borrower borrower = (Borrower) i.next();

			out += "    <hr>"
					+ NEW_LINE
					+ "    <h4>"
					+ borrower.getId()
					+ " "
					+ borrower.getName()
					+ "</h4>"
					+ NEW_LINE;

			BorrowedItems items = borrower.getBorrowedItems();

			if (items.getNumberOfItems() > 0) {
				out += "      <blockquote>" + NEW_LINE;

				for (Iterator j = items.getItemsIterator(); j.hasNext();) {

					CatalogItem item = (CatalogItem) j.next();

					out += "         "
							+ item.getCode()
							+ " "
							+ item.getTitle()
							+ "<br>"
							+ NEW_LINE;
				}
				out += "      </blockquote>" + NEW_LINE;
			}
		}
		out += "  </body>" + NEW_LINE + "</html>";

		return out;
	}
}
/*!End Snippet:file*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -