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

📄 corbalist.java

📁 Exercise 5 of SSD 8 -- JAVA 一个基于CORBA远程调用方法的日程管理系统。100 points!!!
💻 JAVA
字号:
import java.util.*;
import ListFile.*;

/**
 * The item list for each client.
 * 
 * @author Jinjiang
 * 
 */
public class CorbaList extends ListPOA {

	/* a hash table to store the user informations */
	private String username, password;

	/* a vector to store the items */
	private Vector<CorbaItem> items;

	/* count how many items added as the id of items */
	private static int counter = 1;

	/* count how many items deleted */
	private static int deleted = 0;

	/**
	 * The default construstor.
	 * 
	 */
	public CorbaList(String username, String password) {

		this.username = username;
		this.password = password;
		items = new Vector<CorbaItem>();
	}

	/**
	 * Do the login operation.
	 */
	public boolean login(String username, String password) {

		if (username.equals(this.username) && password.equals(this.password))
			return true;
		return false;
	}

	/**
	 * Do the add operation.
	 */
	public boolean add(String username, String password, String start,
			String end, String label) {

		Date s = toDate(start);
		Date e = toDate(end);

		if (!login(username, password))
			return false;

		if (s == null || e == null)
			return false;

		if (s.after(e))
			return false;

		CorbaItem item = new CorbaItem(username, counter, s, e, label);
		items.add(item);
		counter++;

		return true;
	}

	/**
	 * Do the query operation.
	 */
	public String query(String username, String password, String start,
			String end) {

		Date s = toDate(start);
		Date e = toDate(end);

		if (!login(username, password))
			return "Failed!";

		if (s == null || e == null)
			return "Failed!";

		if (s.after(e))
			return "Failed!";

		CorbaItem item;
		Vector<CorbaItem> v = new Vector<CorbaItem>();
		for (Iterator it = items.iterator(); it.hasNext();) {

			item = (CorbaItem) it.next();

			if (e.before(item.getStart()) || s.after(item.getEnd()))
				continue;

			v.add(item);
		}

		if (v.isEmpty())
			return "[No items here.]";

		return v.toString();
	}

	/**
	 * Do the delete operation.
	 */
	public boolean delete(String username, String password, int id) {

		if (!login(username, password))
			return false;

		CorbaItem item;
		for (int i = 0; i < items.size(); i++) {

			item = items.get(i);
			if (id == item.getId()) {
				items.remove(i);
				i--;
				deleted++;
				return true;
			}
		}

		return false;
	}

	/**
	 * Do the clear operation.
	 */
	public boolean clear(String username, String password) {
		if (!login(username, password))
			return false;

		items.clear();

		return true;
	}

	/**
	 * Translate a string to date.
	 */
	public static Date toDate(String date) {

		StringTokenizer token = new StringTokenizer(date, "_");

		if (token.countTokens() != 6)
			return null;

		int year = Integer.parseInt(token.nextToken());
		int month = Integer.parseInt(token.nextToken());
		int day = Integer.parseInt(token.nextToken());
		int hour = Integer.parseInt(token.nextToken());
		int minute = Integer.parseInt(token.nextToken());
		int second = Integer.parseInt(token.nextToken());
		Date d = new Date(year, month, day, hour, minute, second);
		return d;
	}
}

⌨️ 快捷键说明

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