KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mockobjects > eziba > sql > ArgumentArray


1 /*
2  * Copyright (C) 2001 eZiba.com, Inc.
3  * All Rights Reserved
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * Redistributions in binary form must reproduce the above
12  * copyright notice, this list of conditions and the following
13  * disclaimer in the documentation and/or other materials provided
14  * with the distribution. Neither the name of eZiba.com nor the
15  * names of its contributors may be used to endorse or promote
16  * products derived from this software without specific prior
17  * written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23  * eZiba.com OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
30  * OF THE POSSIBILITY OF SUCH DAMAGE.
31  */

32
33
34 package com.mockobjects.eziba.sql;class ArgumentArray
35 {
36
37     ArgumentArray(Object JavaDoc [] p_args)
38     {
39         m_args = p_args;
40     }
41
42     public boolean equals(Object JavaDoc p_other)
43     {
44         if (! (p_other instanceof ArgumentArray) )
45         {
46             return false;
47         }
48         return arraysEqual(m_args, ((ArgumentArray)p_other).m_args);
49     }
50
51     public int hashCode()
52     {
53         return m_args.length;
54     }
55
56     public String JavaDoc toString()
57     {
58         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
59         sb.append("[");
60         for (int i = 0; i < m_args.length; ++i)
61         {
62             if (i > 0) { sb.append(','); }
63             sb.append(m_args[i]);
64         }
65         sb.append(']');
66         return sb.toString();
67     }
68
69     private static boolean objectsEqual(final Object JavaDoc p_first,
70                                         final Object JavaDoc p_second)
71     {
72         if (p_first == null && p_second == null)
73         {
74             return true;
75         }
76         else if ( p_first == Wildcard.WILDCARD
77                   || p_second == Wildcard.WILDCARD)
78         {
79             return true;
80         }
81         else if (p_first == null || p_second == null)
82         {
83             return false;
84         }
85         else
86         {
87             return p_first.equals(p_second);
88         }
89     }
90
91     /**
92      * compares two arrays; elements of an array match if both are
93      * null, one is a wildcard, or they equal
94      *@param p_first the first array
95      *@param p_second the second array
96      *@return boolean true if all elements match, false otherwise
97      */

98
99     private static boolean arraysEqual(final Object JavaDoc[] p_first,
100                                        final Object JavaDoc[] p_second)
101     {
102         //if the number of elements differs, the arrays don't match by
103
//definition.
104
if ( p_first.length != p_second.length )
105         {
106             return false;
107         }
108         for (int i = 0; i < p_first.length; i++)
109         {
110             if ( ! objectsEqual(p_first[i],p_second[i]) )
111             {
112                 return false;
113             }
114         }
115         return true;
116     }
117
118
119     private final Object JavaDoc [] m_args;
120 }
Popular Tags