KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb > plugins > cmp > jdbc > RelationPair


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.ejb.plugins.cmp.jdbc;
23
24 import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge;
25
26 /**
27  * This class represents one pair of entities in a relation.
28  *
29  * @author <a HREF="mailto:dain@daingroup.com">Dain Sundstrom</a>
30  * @version $Revision: 37459 $
31  */

32 public final class RelationPair {
33    private final JDBCCMRFieldBridge leftCMRField;
34    private final JDBCCMRFieldBridge rightCMRField;
35
36    private final Object JavaDoc leftId;
37    private final Object JavaDoc rightId;
38    
39    public RelationPair(
40          JDBCCMRFieldBridge leftCMRField, Object JavaDoc leftId,
41          JDBCCMRFieldBridge rightCMRField, Object JavaDoc rightId) {
42
43       this.leftCMRField = leftCMRField;
44       this.leftId = leftId;
45       
46       this.rightCMRField = rightCMRField;
47       this.rightId = rightId;
48    }
49
50    public Object JavaDoc getLeftId() {
51       return leftId;
52    }
53    
54    public Object JavaDoc getRightId() {
55       return rightId;
56    }
57    
58    public boolean equals(Object JavaDoc obj) {
59       if(obj instanceof RelationPair) {
60          RelationPair pair = (RelationPair) obj;
61          
62          // check left==left and right==right
63
if(leftCMRField == pair.leftCMRField &&
64                rightCMRField == pair.rightCMRField &&
65                leftId.equals(pair.leftId) &&
66                rightId.equals(pair.rightId)) {
67             return true;
68          }
69          
70          // check left==right and right==left
71
if(leftCMRField == pair.rightCMRField &&
72                rightCMRField == pair.leftCMRField &&
73                leftId.equals(pair.rightId) &&
74                rightId.equals(pair.leftId)) {
75             return true;
76          }
77       }
78       return false;
79    }
80    
81    public int hashCode() {
82       return leftId.hashCode() ^ rightId.hashCode();
83    }
84 }
85
86
Popular Tags