001: package org.mandarax.jdbc.server.sql;
002:
003: /*
004: * Copyright (C) 1999-2004 <a href="mailto:mandarax@jbdietrich.com">Jens Dietrich</a>
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: */
020:
021: /**
022: * Superclass for function with the arity 1 (one argument).
023: * @author <A HREF="mailto:mandarax@jbdietrich.com">Jens Dietrich</A>
024: * @version 3.3.2 <29 December 2004>
025: * @since 3.0
026: */
027: public class Function1 implements Function {
028: private String name = null;
029: private boolean isAggregationFunction = false;
030:
031: /**
032: * Constructor.
033: * @param name the function name
034: * @param isAggrFunct indicates whether this is an aggregation function
035: */
036: public Function1(String name, boolean isAggrFunct) {
037: super ();
038: this .name = name;
039: this .isAggregationFunction = isAggrFunct;
040: }
041:
042: /**
043: * Get the name of the function.
044: * @return the function name.
045: */
046: public String getName() {
047: return name;
048: }
049:
050: /**
051: * Print the term built from this function.
052: * @param out the print buffer used for printing
053: * @param children an array of string produces by printing the children
054: */
055: public void print(StringBuffer out, ColumnTerm[] children) {
056: out.append(name);
057: out.append('(');
058: children[0].print(out);
059: out.append(')');
060: }
061:
062: /**
063: * Indicates whether this is an aggregation function.
064: * @return a boolean
065: */
066: public boolean isAggregationFunction() {
067: return isAggregationFunction;
068: }
069:
070: /**
071: * Get the arity of the function (the number of parameters).
072: * @return an integer number
073: */
074: public int getArity() {
075: return 1;
076: }
077:
078: /**
079: * Compares objects.
080: * @param obj an object
081: * @return a boolean
082: */
083: public boolean equals(Object obj) {
084: if (obj == null)
085: return false;
086: if (obj instanceof Function1) {
087: Function1 f = (Function1) obj;
088: return name == null ? f.name == null : name.equals(f.name);
089: }
090: return false;
091: }
092:
093: /**
094: * Get the hash code of this object.
095: * @return the hash code
096: */
097: public int hashCode() {
098: return name == null ? 0 : name.hashCode();
099: }
100:
101: }
|