001: /*
002: * $Id: Utils.java,v 1.2 2005/11/03 01:26:58 ahimanikya Exp $
003: * =======================================================================
004: * Copyright (c) 2003-2005 Axion Development Team. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above
011: * copyright notice, this list of conditions and the following
012: * disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * 3. The names "Tigris", "Axion", nor the names of its contributors may
020: * not be used to endorse or promote products derived from this
021: * software without specific prior written permission.
022: *
023: * 4. Products derived from this software may not be called "Axion", nor
024: * may "Tigris" or "Axion" appear in their names without specific prior
025: * written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
030: * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
032: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
033: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
034: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
035: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
036: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
037: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
038: * =======================================================================
039: */
040: package org.axiondb.util;
041:
042: import java.sql.Types;
043: import java.util.Collection;
044: import java.util.Iterator;
045:
046: public class Utils {
047:
048: /**
049: * Returns <code>true</code> iff at least one element is in both collections.
050: * <p>
051: * In other words, this method returns <code>true</code> iff the
052: * {@link #intersection} of <i>coll1</i> and <i>coll2</i> is not empty.
053: *
054: * @param coll1 the first collection, must not be null
055: * @param coll2 the first collection, must not be null
056: * @return <code>true</code> iff the intersection of the collections is non-empty
057: */
058: public static boolean containsAny(final Collection coll1,
059: final Collection coll2) {
060: if (coll1.size() < coll2.size()) {
061: for (Iterator it = coll1.iterator(); it.hasNext();) {
062: if (coll2.contains(it.next())) {
063: return true;
064: }
065: }
066: } else {
067: for (Iterator it = coll2.iterator(); it.hasNext();) {
068: if (coll1.contains(it.next())) {
069: return true;
070: }
071: }
072: }
073: return false;
074: }
075:
076: public static boolean isPrecisionRequired(int jdbcType) {
077: switch (jdbcType) {
078: case Types.BIT:
079: case Types.BIGINT:
080: case Types.BOOLEAN:
081: case Types.INTEGER:
082: case Types.SMALLINT:
083: case Types.TINYINT:
084: case Types.FLOAT:
085: case Types.REAL:
086: case Types.DOUBLE:
087: case Types.DATE:
088: case Types.TIMESTAMP:
089: case Types.JAVA_OBJECT:
090: case Types.LONGVARCHAR:
091: case Types.LONGVARBINARY:
092: case Types.BLOB:
093: case Types.CLOB:
094: case Types.ARRAY:
095: case Types.STRUCT:
096: case Types.DISTINCT:
097: case Types.REF:
098: case Types.DATALINK:
099: return false;
100:
101: default:
102: return true;
103: }
104: }
105:
106: public static boolean isScaleRequired(int type) {
107: switch (type) {
108: case java.sql.Types.DECIMAL:
109: case java.sql.Types.NUMERIC:
110: return true;
111: default:
112: return false;
113: }
114: }
115:
116: public static boolean isBinary(int jdbcType) {
117: switch (jdbcType) {
118: case Types.BINARY:
119: case Types.VARBINARY:
120: case Types.LONGVARBINARY:
121: return true;
122: default:
123: return false;
124: }
125: }
126:
127: }
|