KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > example > cmp > map > GradeKey


1 package example.cmp.map;
2
3 import java.rmi.*;
4 import javax.ejb.*;
5
6 import java.util.*;
7
8 /**
9  * The composite grade key. The fields names match the primary key
10  * of the Grade object.
11  */

12 public class GradeKey {
13   public Student student;
14   public Course course;
15   
16   /**
17    * Null constructor for the GradeKey.
18    */

19   public GradeKey()
20   {
21   }
22   
23   /**
24    * Create a new GradeKey.
25    */

26   public GradeKey(Student student, Course course)
27   {
28     this.student = student;
29     this.course = course;
30   }
31
32   /**
33    * Overrides equals to return true when the key matches.
34    */

35   public boolean equals(Object obj)
36   {
37     if (! (obj instanceof GradeKey))
38       return false;
39
40     GradeKey key = (GradeKey) obj;
41
42     return student.equals(key.student) && course.equals(key.course);
43   }
44
45   /**
46    * Returns the key's hash code.
47    */

48   public int hashCode()
49   {
50     return 65521 * student.hashCode() + course.hashCode();
51   }
52 }
53
Popular Tags