KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > core > util > TwoObjectStruct


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: TwoObjectStruct.java,v 1.5 2007/01/07 06:14:00 bastafidli Exp $
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
11  *
12  * This program 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
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21
22 package org.opensubsystems.core.util;
23
24 /**
25  * Class which can hold two objects. This is useful if I want to create array of
26  * two objects to pass as argument to some function.
27  *
28  * @version $Id: TwoObjectStruct.java,v 1.5 2007/01/07 06:14:00 bastafidli Exp $
29  * @author Julo Legeny
30  * @code.reviewer Miro Halas
31  * @code.reviewed 1.3 2005/07/29 07:36:25 bastafidli
32  */

33 public class TwoObjectStruct
34 {
35    // Attributes ///////////////////////////////////////////////////////////////
36

37    /**
38     * First object
39     */

40    protected Object JavaDoc m_objFirst;
41
42    /**
43     * Second object
44     */

45    protected Object JavaDoc m_objSecond;
46
47    // Constructors /////////////////////////////////////////////////////////////
48

49    /**
50     * Public constructor.
51     *
52     * @param objFirst - first object
53     * @param objSecond - second object
54     */

55    public TwoObjectStruct(
56       Object JavaDoc objFirst,
57       Object JavaDoc objSecond
58    )
59    {
60       m_objFirst = objFirst;
61       m_objSecond = objSecond;
62    }
63
64    /**
65     * Public constructor.
66     *
67     * @param input - TwoObjectStruct to copy into
68     */

69    public TwoObjectStruct(
70       TwoObjectStruct input
71    )
72    {
73       assert input != null : "Can't create empty TwoObjectStruct";
74
75       m_objFirst = input.getFirst();
76       m_objSecond = input.getSecond();
77    }
78
79    // Logic ////////////////////////////////////////////////////////////////////
80

81    /**
82     * @return object
83     */

84    public Object JavaDoc getFirst()
85    {
86       return m_objFirst;
87    }
88
89    /**
90     * @return object
91     */

92    public Object JavaDoc getSecond()
93    {
94       return m_objSecond;
95    }
96    
97    /**
98     * {@inheritDoc}
99     */

100    public boolean equals(
101       Object JavaDoc oObject
102    )
103    {
104       boolean bRetval = false;
105
106       if (oObject == this)
107       {
108          return true;
109       }
110       else if (oObject != null)
111       {
112          if (oObject instanceof TwoObjectStruct)
113          {
114             TwoObjectStruct input = (TwoObjectStruct) oObject;
115             
116             return (((m_objFirst == null) && (input.m_objFirst == null))
117                       || ((m_objFirst != null)
118                          && (m_objFirst.equals(input.m_objFirst))))
119                    && (((m_objSecond == null) && (input.m_objSecond == null))
120                       || ((m_objSecond != null)
121                          && (m_objSecond.equals(input.m_objSecond))));
122          }
123       }
124
125       return bRetval;
126    }
127
128    /**
129     * {@inheritDoc}
130     */

131    public int hashCode()
132    {
133       int iResult = HashCodeUtils.SEED;
134       iResult = HashCodeUtils.hash(iResult, m_objFirst);
135       iResult = HashCodeUtils.hash(iResult, m_objSecond);
136       return iResult;
137    }
138 }
139
Popular Tags