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

📄 meeting.java

📁 简单的会议议程系统,展示了Command 模式的应用
💻 JAVA
字号:
/*
 * @(#)Meeting.java        2006/11/13
 *
 * Copyright (c) ZhiYang.
 * All rights reserved.
*/

package agenda;

import java.util.*;
import java.text.*;

/**
 * 会议记录
 * @version 1.0
 * @author 杨智 (MSE2006B-06250145)
 *
 */

public class Meeting implements Comparable {
	
	/*
	 * title of this meeting
	*/
	public String title;
	
	/*
	 * user who registered this meeting record
	*/
	public String operatorUser;
	
	/*
	 * other user who will take part in this meeting
	*/
	public String scheduledUser;
	
	/* 
	 * start time of this meeting
	*/
	public Date startTime;
	
	/*
	 * end time of this meeting
	*/
	public Date endTime;

	/*
	 * comparing two records
	*/
	public int compareTo(Object o) {
		Meeting mt = (Meeting)o;
		return title.compareTo(  mt.title );
	}

	private static DateFormat df = DateFormat.getDateTimeInstance();
	//private static DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT,DateFormat.SHORT);
	
	/*
	 * get DateFormat object
	*/
	public static DateFormat getDateFormat() {
		return df;
	}
	
	/*
	 * get the description text of Date Format: use default format accroding to the locale 
	*/
	public static String getDateFormatDesc() {
		return df.format( new Date() );
	}
	
	/*
	 * get date format string
	*/
	public static String getDateString(Date dt) {
		return df.format(dt); 
	}
	
	
	/*
	 * constructor
	*/
	public Meeting(){
	}
	public Meeting ( String title, String operatorUser, String scheduledUser, Date startTime, Date endTime ) {
		this.title = new String( title );
		this.operatorUser = new String ( operatorUser );
		this.scheduledUser = new String ( scheduledUser );
		this.startTime = (Date)startTime.clone();
		this.endTime = (Date)endTime.clone();
	}
	public Meeting ( String title, String operatorUser, String scheduledUser, String startTime, String endTime ) throws ParseException {
		this.title = new String( title );
		this.operatorUser = new String ( operatorUser );
		this.scheduledUser = new String ( scheduledUser );
		this.startTime = df.parse(startTime);
		this.endTime = df.parse(endTime) ;
	}
	public Meeting( Meeting mt ) {
		this ( mt.title, mt.operatorUser, mt.scheduledUser, mt.startTime, mt.endTime );
	}

	/*
	 * clone method
	*/
	public Object clone() {
		return new Meeting (title,operatorUser,scheduledUser,startTime,endTime);
	}
	
	/*
	 * check this record
	*/
	public boolean isValid() {
		if( title.length()<1 || operatorUser.length()<1 || scheduledUser.length()<1 )
			return false;
		return endTime.after( startTime );
	}	
	
	/*
	 * test this record to see whether it is located at the given time or not
	*/
	public boolean isTimeOverlapped (Date startTime, Date endTime ) {
		return !(startTime.after(this.endTime) || endTime.before(this.startTime) );
	}
	public boolean isTimeOverlapped ( Meeting mt ) {
		return isTimeOverlapped(mt.startTime,mt.endTime);
	}

	/*
	 * wheather the user in this record or not 
	*/	
	public boolean isUserOverlapped( String strUser ) {
		return ( strUser.compareTo( operatorUser) == 0 || 
			strUser.compareTo( scheduledUser) == 0 );
	}
	public boolean isUserOverlapped( Meeting mt ) {
		return (isUserOverlapped(mt.operatorUser) || isUserOverlapped(mt.scheduledUser));
	}

	/*
	 * test if user overlapped first, then check the time.
	*/
	public boolean isOverlapped ( Meeting mt ) {
		return (isUserOverlapped(mt) && isTimeOverlapped( mt.startTime, mt.endTime ) );
	}

	public String toString() {
		return title + '<' + operatorUser + ',' + scheduledUser + ',' + getDateString(startTime) + " to " + getDateString(endTime) + '>';
	}
	
	// uit test method
	public static void main( String argv[] ) {
		System.out.println( "Meeting date format:< " + Meeting.getDateFormatDesc() + " >" );
		try {
		Meeting mt1 = new Meeting ( "test1", "op1", "sch1", "06-10-21 10:12:00", "06-10-21 10:32:00" );
		System.out.println( mt1 );
		Meeting mt2 = new Meeting ( "test2", "op1", "sch2", "06-10-21 13:16:00", "06-10-21 14:30:00" );
		System.out.println( mt2 );
		Meeting mt3 = new Meeting ( "test3", "op2", "sch2", "06-10-21 14:30:00", "06-10-21 15:39:00" );
		System.out.println( mt3 );
		Meeting mt4 = new Meeting ( "test2", "op1", "sch2", "06-10-21 10:12:00", "06-10-21 16:30:00" );
		System.out.println( mt4 );
		if( !mt4.isOverlapped (mt1) )
			System.out.println("overlapped test failed with mt4 and mt1!");
		if( !mt4.isOverlapped (mt2) ) 
			System.out.println("overlapped test failed with mt4 and mt2!");
		if( !mt4.isOverlapped (mt3) )			
			System.out.println("overlapped test failed with mt4 and mt3!");
		if( mt1.isUserOverlapped(mt3) || mt1.isTimeOverlapped(mt3) )
			System.out.println("overlapped test failed with mt1 and mt3!");
		}
		catch ( ParseException e ) {
			System.out.println(e.getMessage());
		}
	}

}
 

⌨️ 快捷键说明

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