001/* 002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * Nuxeo - initial API and implementation 011 * 012 * $Id$ 013 */ 014 015package org.nuxeo.ecm.core.query.sql.model; 016 017/** 018 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 019 */ 020public class Function implements Operand { 021 022 private static final long serialVersionUID = -6107133982072616209L; 023 024 public final String name; 025 026 public final OperandList args; 027 028 public Function(String name) { 029 this(name, null); 030 } 031 032 public Function(String name, OperandList args) { 033 this.name = name; 034 this.args = args; 035 } 036 037 @Override 038 public String toString() { 039 return args == null ? name + "()" : name + '(' + args + ')'; 040 } 041 042 @Override 043 public boolean equals(Object obj) { 044 if (this == obj) { 045 return true; 046 } 047 if (obj instanceof Function) { 048 Function func = (Function) obj; 049 if (args == null) { 050 return func.args == null; 051 } 052 return name.equals(func.name) && args.equals(func.args); 053 } 054 return false; 055 } 056 057 @Override 058 public int hashCode() { 059 int result = name.hashCode(); 060 result = 31 * result + (args != null ? args.hashCode() : 0); 061 return result; 062 } 063 064 @Override 065 public void accept(IVisitor visitor) { 066 visitor.visitFunction(this); 067 } 068 069}