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

📄 massignmentslot.java

📁 Java写的ERP系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

	/**
	 * 	Set Y position
	 * 	@param yStart zero based Y start index
	 * 	@param yEnd zero based Y end index
	 */
	public void setY (int yStart, int yEnd)
	{
		m_yStart = yStart;
		m_yEnd = yEnd;
	}	//	setY

	/**
	 * 	Get Y start position
	 * 	@return zero based Y start index
	 */
	public int getYStart ()
	{
		return m_yStart;
	}	//	getYStart

	/**
	 * 	Get Y end position
	 * 	@return zero based Y end index
	 */
	public int getYEnd ()
	{
		return m_yEnd;
	}	//	setYEnd

	/**
	 * 	Set X position
	 * 	@param xPos zero based X position index
	 * 	@param xMax number of parallel columns
	 */
	public void setX (int xPos, int xMax)
	{
		m_xPos = xPos;
		if (xMax > m_xMax)
			m_xMax = xMax;
	}	//	setX

	/**
	 * 	Get X position
	 * 	@return zero based X position index
	 */
	public int getXPos()
	{
		return m_xPos;
	}	//	setXPos

	/**
	 * 	Get X columns
	 * 	@return number of parallel columns
	 */
	public int getXMax()
	{
		return m_xMax;
	}	//	setXMax

	/*************************************************************************/

	/**
	 * 	Set Language
	 * 	@param language language
	 */
	public void setLanguage (Language language)
	{
		m_language = language;
	}	//	setLanguage

	/**
	 * 	Set Display Mode of toString()
	 * 	@param displayMode DISPLAY_
	 */
	public void setDisplay (int displayMode)
	{
		m_displayMode = displayMode;
	}	//	setDisplay


	/**
	 * 	String representation
	 *  @return info
	 */
	public String toString()
	{
		if (m_displayMode == DISPLAY_TIME_FROM)
			return getInfoTimeFrom();
		else if (m_displayMode == DISPLAY_TIME_FROM_TO)
			return getInfoTimeFromTo();
		else if (m_displayMode == DISPLAY_DATETIME_FROM_TO)
			return getInfoDateTimeFromTo();
		else if (m_displayMode == DISPLAY_NAME)
			return m_name;
		else if (m_displayMode == DISPLAY_NAME_DESCRIPTION)
			return getInfoNameDescription();
		else if (m_displayMode == DISPLAY_FULL)
			return getInfo();

		//	DISPLAY_ALL
		StringBuffer sb = new StringBuffer("MAssignmentSlot[");
		sb.append(m_startTime).append("-").append(m_endTime)
			.append("-Status=").append(m_status).append(",Name=")
			.append(m_name).append(",").append(m_description).append("]");
		return sb.toString();
	}	//	toString

	/**
	 * 	Get Info with Time From
	 *  @return info 00:00
	 */
	public String getInfoTimeFrom()
	{
		return m_language.getTimeFormat().format(m_startTime);
	}	//	getInfoTimeFrom

	/**
	 * 	Get Info with Time From-To
	 *  @return info 00:00 - 01:00
	 */
	public String getInfoTimeFromTo()
	{
		StringBuffer sb = new StringBuffer();
		sb.append(m_language.getTimeFormat().format(m_startTime))
			.append(" - ")
			.append(m_language.getTimeFormat().format(m_endTime));
		return sb.toString();
	}	//	getInfoTimeFromTo

	/**
	 * 	Get Info with Date & Time From-To
	 *  @return info 12/12/01 00:00 - 01:00 or 12/12/01 00:00 - 12/13/01 01:00
	 */
	public String getInfoDateTimeFromTo()
	{
		StringBuffer sb = new StringBuffer();
		sb.append(m_language.getDateTimeFormat().format(m_startTime))
			.append(" - ");
		if (TimeUtil.isSameDay(m_startTime, m_endTime))
			sb.append(m_language.getTimeFormat().format(m_endTime));
		else
			m_language.getDateTimeFormat().format(m_endTime);
		return sb.toString();
	}

	/**
	 * 	Get Info with Name and optional Description
	 * 	@return Name (Description)
	 */
	public String getInfoNameDescription()
	{
		StringBuffer sb = new StringBuffer(m_name);
		if (m_description.length() > 0)
			sb.append(" (").append(m_description).append(")");
		return sb.toString();
	}	//	getInfoNameDescription

	/**
	 *	Get Info with Date, Time From-To Name Description
	 * 	@return 12/12/01 00:00 - 01:00: Name (Description)
	 */
	public String getInfo()
	{
		StringBuffer sb = new StringBuffer(getInfoDateTimeFromTo());
		sb.append(": ").append(m_name);
		if (m_description.length() > 0)
			sb.append(" (").append(m_description).append(")");
		return sb.toString();
	}	//	getInfo

	/*************************************************************************/

	/**
	 * 	Returns true if time is between start and end Time.
	 *  Date part is ignored.
	 *  <pre>
	 *  Example:
	 *  - Slots: 0:00-9:00 - 9:00-10:00 - 10:00-11:00 - ...
	 *  - inSlot (9:00, false) -> 1		//	start time
	 *  - inSlot (10:00, true) -> 1		//	end time
	 *  </pre>
	 * 	@param time time of the day
	 *  @param endTime if true, the end time is included
	 * 	@return true if within slot
	 */
	public boolean inSlot (Timestamp time, boolean endTime)
	{
		//	Compare	--
		GregorianCalendar cal = new GregorianCalendar();
		cal.setTime(time);
		cal.set(Calendar.YEAR, 1970);
		cal.set(Calendar.DAY_OF_YEAR, 1);
		//	handle -00:00 (end time)
		if (endTime && cal.get(Calendar.HOUR_OF_DAY) == 0 && cal.get(Calendar.MINUTE) == 0)
		{
			cal.set(Calendar.HOUR_OF_DAY, 23);
			cal.set(Calendar.MINUTE, 59);
		}
		Time compare = new Time (cal.getTimeInMillis());
		//	Start Time --
		cal.setTime(m_startTime);
		cal.set(Calendar.YEAR, 1970);
		cal.set(Calendar.DAY_OF_YEAR, 1);
		Time start = new Time (cal.getTimeInMillis());
		//	End time --
		cal.setTime(m_endTime);
		cal.set(Calendar.YEAR, 1970);
		cal.set(Calendar.DAY_OF_YEAR, 1);
		if (cal.get(Calendar.HOUR_OF_DAY) == 0 && cal.get(Calendar.MINUTE) == 0)
		{
			cal.set(Calendar.HOUR_OF_DAY, 23);
			cal.set(Calendar.MINUTE, 59);
		}
		Time end = new Time (cal.getTimeInMillis());

		//	before start			x |---|
		if (compare.before(start))
		{
		//	System.out.println("InSlot-false Compare=" + compare + " before start " + start);
			return false;
		}
		//	after end				|---| x
		if (compare.after(end))
		{
		//	System.out.println("InSlot-false Compare=" + compare + " after end " + end);
			return false;
		}

		//	start					x---|
		if (!endTime && compare.equals(start))
		{
		//	System.out.println("InSlot-true Compare=" + compare + " = Start=" + start);
			return true;
		}

		//
		//	end						|---x
		if (endTime && compare.equals(end))
		{
		//	System.out.println("InSlot-true Compare=" + compare + " = End=" + end);
			return true;
		}
		//	between start/end		|-x-|
		if (compare.before(end))
		{
		//	System.out.println("InSlot-true Compare=" + compare + " before end " + end);
			return true;
		}
		return false;
	}	//	inSlot

	/*************************************************************************/

	/**
	 * Compares its two arguments for order.  Returns a negative integer,
	 * zero, or a positive integer as the first argument is less than, equal
	 * to, or greater than the second.
	 *
	 * @param o1 the first object to be compared.
	 * @param o2 the second object to be compared.
	 * @return a negative integer, zero, or a positive integer as the
	 * 	       first argument is less than, equal to, or greater than the
	 *	       second.
	 * @throws ClassCastException if the arguments' types prevent them from
	 * 	       being compared by this Comparator.
	 */
	public int compare(Object o1, Object o2)
	{
		if (!(o1 instanceof MAssignmentSlot && o2 instanceof MAssignmentSlot))
			throw new ClassCastException ("MAssignmentSlot.compare arguments not MAssignmentSlot");

		MAssignmentSlot s1 = (MAssignmentSlot)o1;
		MAssignmentSlot s2 = (MAssignmentSlot)o2;

		//	Start Date
		int result = s1.getStartTime().compareTo(s2.getStartTime());
		if (result != 0)
			return result;
		//	Status
		result = s2.getStatus() - s1.getStatus();
		if (result != 0)
			return result;
		//	End Date
		result = s1.getEndTime().compareTo(s2.getEndTime());
		if (result != 0)
			return result;
		//	Name
		result = s1.getName().compareTo(s2.getName());
		if (result != 0)
			return result;
		//	Description
		return s1.getDescription().compareTo(s2.getDescription());
	}	//	compare

	/**
	 * Indicates whether some other object is &quot;equal to&quot; this
	 * Comparator.
	 * @param   obj   the reference object with which to compare.
	 * @return  <code>true</code> only if the specified object is also
	 *		a comparator and it imposes the same ordering as this
	 *		comparator.
	 * @see     java.lang.Object#equals(java.lang.Object)
	 * @see java.lang.Object#hashCode()
	 */
	public boolean equals(Object obj)
	{
		if (obj instanceof MAssignmentSlot)
		{
			MAssignmentSlot cmp = (MAssignmentSlot)obj;
			if (m_startTime.equals(cmp.getStartTime())
				&& m_endTime.equals(cmp.getEndTime())
				&& m_status == cmp.getStatus()
				&& m_name.equals(cmp.getName())
				&& m_description.equals(cmp.getDescription()))
				return true;
		}
		return false;
	}	//	equals

	/**
	 * 	HashCode of MAssignmentSlot
	 * 	@return has code
	 */
	public int hashCode()
	{
		return m_startTime.hashCode() + m_endTime.hashCode() + m_status
			+ m_name.hashCode() + m_description.hashCode();
	}	//	hashCode

}	//	MAssignmentSlot

⌨️ 快捷键说明

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