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

📄 phonelist.java

📁 ssd3 java编程 exam3 绝对可以
💻 JAVA
字号:
import java.util.*;

/**
 * Maintains an phone list.
 *
 * @author  iCarnegie
 * @version  1.0.0
 * @see PhoneEntry
 */
public class PhoneList implements Iterable<PhoneEntry> {

	/* Collection of {@link PhoneEntry} objects. */
	private ArrayList<PhoneEntry>  entries;

	/**
	 * Constructs an empty phone list.
	 */
	public PhoneList()  {

		this.entries = new ArrayList<PhoneEntry>();
	}

	/**
	 * Adds the specified entry to this phone list.
	 *
	 * @param entry  the entry to be added.
	 */
	public void  addEntry(PhoneEntry entry)  {

		this.entries.add(entry);
	}

	/**
	 * Removes the specified entry from this phone list.
	 *
	 * @param entry  the entry to be removed.
	 */
	public void  removeEntry(PhoneEntry entry)  {

		this.entries.remove(entry);
	}

	/**
	 * Removes all the this.entries from this phone list.
	 */
	public void  removeAllEntries()  {

		this.entries.clear();
	}

	/**
	 * Returns the first entry with the specified <code>name</code> in this
	 * phone list.
	 *
	 * @param name  the name of the entry.
	 * @return  The object in the phone list with the specified name.
	 *          Returns <code>null</code> if the object with the
	 *          specified name is not found.
	 */
	public PhoneEntry  getEntry(String name)  {

		for (PhoneEntry entry : this.entries) {

			if (entry.getName().equals(name)) {

				return entry;
			}
		}

		return null;
	}

	/**
	 * Returns an array with all the names in this phone list.
	 *
	 * @return  an array with all the names in this phone list.
	 */
	public String[]  getNames()  {

		String[] result = new String[getNumberOfEntries()];
		int index = 0;

		for (PhoneEntry entry : this.entries) {
			result[index++] = entry.getName();
		}

		return result;
	}

	/**
	 * Returns an iterator over the this.entries in this phone list.
	 *
	 * return  an {@link Iterator<PhoneEntry>}
	 */
	public Iterator<PhoneEntry>  iterator() {

		return this.entries.iterator();
	}

	/**
	 * Returns the number of this.entries in this phone list.
	 *
	 * @return  the number of this.entries in this phone list.
	 */
	public int  getNumberOfEntries()  {

		return this.entries.size();
	}
}

⌨️ 快捷键说明

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