/*
 * Created on Apr 19, 2005
 *
 */
package com.dragonsoft.tryapp.ejb.entity.interfaces;

/**
 * @author Greg
 *
 * 
 */
public class CourseKey {

		private String courseNum;
		private String section;
		private String term;
		
		/**
		 * Defines a general Course Key. Good for defining global courses.
		 * @param term the term to associate with
		 * @param courseNum the course number to associate with.
		 */
		public CourseKey(String term,String courseNum){
			this.term = term;
			this.courseNum = courseNum;
		}
		
		/**
		 * Defines a Specific course with a special section. The section
		 * allows more detailed information by allowing more seperation
		 * of detail from the global course and the small group of students.
		 * @param term the term to associate with.
		 * @param courseNum the course number to associate with. 
		 * @param section the section to associate with.
		 */
		public CourseKey(String term,String courseNum,String section){
			this.term = term;
			this.courseNum = courseNum;
			this.section = section;
		}
		
		/**
		 * Gets the Term Identifer that is associated with course.
		 * @return the term identifier.
		 */
		public String getTerm(){
			return term;
		}
		
		/**
		 * Gets the CoourseNumber Identifier for the course.
		 * @return the courseNumber
		 */
		public String getCourseNum(){
			return courseNum;
		}
		
		/**
		 * Gets the section to look up for the course. Remeber this is an
		 * appended field to a course, it is exists you talking about a
		 * specific section.
		 * @return the section Identifier
		 */
		public String getSection(){
			return section;
		}
		
		
		
		public boolean equals(Object o){
			boolean rtVal  = false;
			if(o instanceof CourseKey){
				CourseKey key = (CourseKey)o;
				// logically if the coursenumbers and the terms are the same then they might be equal
				if(key.courseNum.equals(courseNum) && key.term.equals(term)){
					// if the sections are null(same mem location) as well then it is the root course, 
					// if the sections are not null, then the sections much be lexicographicallly equivlent
					if((key.section!= null && section!=null && section.equals(key.section)) || key.section == section)
						rtVal = true;
				}	
			}
			return rtVal;
		}
		
		
		public int hashCode(){
			return toString().hashCode();
		}
		
		public String toString(){
			StringBuffer buffer = new StringBuffer(term);
			buffer.append(courseNum);
			if(section != null){
				buffer.append(section);
			}
			return buffer.toString();
		}
		
		public static void main(String args[]){
			CourseKey ke = new CourseKey("1001","12312","NAME");
			CourseKey key = new CourseKey("1001","12312","NAME");
			System.out.println(key.equals(ke));
		}
}
