KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: TwoIntStruct.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 integers. This is useful if I want to create array of
26  * two integers to pass as argument to some function.
27  *
28  * @version $Id: TwoIntStruct.java,v 1.5 2007/01/07 06:14:00 bastafidli Exp $
29  * @author Miro Halas
30  * @code.reviewer Miro Halas
31  * @code.reviewed 1.3 2005/07/29 07:36:24 bastafidli
32  */

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

37    /**
38     * First integer
39     */

40    protected int m_iFirst;
41
42    /**
43     * Second integer
44     */

45    protected int m_iSecond;
46
47    // Constructors /////////////////////////////////////////////////////////////
48

49    /**
50     * Public constructor.
51     *
52     * @param iFirst - first integer
53     * @param iSecond - second integer
54     */

55    public TwoIntStruct(int iFirst, int iSecond)
56    {
57       m_iFirst = iFirst;
58       m_iSecond = iSecond;
59    }
60
61    /**
62     * Public constructor.
63     *
64     * @param input - TwoIntStruct to copy into
65     */

66    public TwoIntStruct(TwoIntStruct input)
67    {
68       assert input != null : "Can't create empty TwoIntStruct";
69
70       m_iFirst = input.getFirst();
71       m_iSecond = input.getSecond();
72    }
73
74    // Logic ////////////////////////////////////////////////////////////////////
75

76    /**
77     * @return int
78     */

79    public int getFirst()
80    {
81       return m_iFirst;
82    }
83
84    /**
85     * @return int
86     */

87    public int getSecond()
88    {
89       return m_iSecond;
90    }
91    
92    /**
93     * {@inheritDoc}
94     */

95    public boolean equals(
96       Object JavaDoc oObject
97    )
98    {
99       boolean bRetval = false;
100       if (oObject == this)
101       {
102          return true;
103       }
104       else if (oObject != null)
105       {
106          if (oObject instanceof TwoIntStruct)
107          {
108             TwoIntStruct input = (TwoIntStruct) oObject;
109             return (m_iFirst == input.m_iFirst)
110                    && (m_iSecond == input.m_iSecond);
111          }
112       }
113       return bRetval;
114    }
115
116    /**
117     * {@inheritDoc}
118     */

119    public int hashCode()
120    {
121       int iResult = HashCodeUtils.SEED;
122       iResult = HashCodeUtils.hash(iResult, m_iFirst);
123       iResult = HashCodeUtils.hash(iResult, m_iSecond);
124       return iResult;
125    }
126 }
127
Popular Tags