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

📄 timeprocess.java

📁 一个基于RMI的分布式会议议程管理服务系统
💻 JAVA
字号:
package server.meeting;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import server.exception.TimeInvalidException;
public class TimeProcess {
	
	private Date startTime;//会议起始时间
	private Date endTime;//会议结束时间
	private DateFormat dateFormat;
	/**
	 * 构造函数, 用两个Date变量进行初始化
	 *
	 */
	public TimeProcess(Date startTime, Date endTime) throws TimeInvalidException {
		if(endTime.before(startTime)) {
			throw new TimeInvalidException("会议开始时间应该先于结束时间");
		}
		else {
			this.startTime = startTime;
			this.endTime = endTime;
			dateFormat = new SimpleDateFormat("MM-dd-yyyy,HH:mm",Locale.getDefault());
		}
	}
	
	
	/**
	 * 判断两个时间片段是否重叠, 重叠返回true,否则返回false
	 */
	public boolean isOverLaped(TimeProcess time)throws TimeInvalidException {
		if(this != null || time != null) {
			return !(this.endTime.before(time.startTime) || this.startTime.after(time.endTime));
			
		}
		else throw new TimeInvalidException("时间重叠");
			
	}
	/**
	 * 比较两个时间片段是否相等
	 */
	public boolean equals(TimeProcess time) throws TimeInvalidException {
		if(this != null || time != null) {
			return ((this.startTime == time.startTime) && (this.endTime == time.endTime));
		}
		else {
			throw new TimeInvalidException("时间不相等");
			
		}
	}
	
	/**
	 * 返回起始时间
	 * 
	 */
	public Date getStartTime(){
		return startTime;
	}
	/**
	 * 返回结束时间
	 * 
	 */
	
	public Date getEndTime(){
		return endTime;
	}
	/**
	 * 返回字符串格式的会议开始时间
	 * 
	 */
	public String getStartTimeOfString(){
		String startTime = dateFormat.format(this.startTime);
		return startTime;
	}
	/**
	 * 返回符串格式的会议结束时间
	 *
	 */
	public String getEndTimeOfString(){
		String endTime = dateFormat.format(this.endTime);
		return endTime;
	}
	/**
	 *把一个时间片段字符串化
	 *
	 */
	public String toString() {
		String startTime = dateFormat.format(this.startTime);
		String endTime = dateFormat.format(this.endTime);
		return "startTime = " + startTime + ";endTime = " + endTime; 
	}
	
}

⌨️ 快捷键说明

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