001/*
002// This software is subject to the terms of the Eclipse Public License v1.0
003// Agreement, available at the following URL:
004// http://www.eclipse.org/legal/epl-v10.html.
005// You must accept the terms of that agreement to use this software.
006//
007// Copyright (C) 1999-2005 Julian Hyde
008// Copyright (C) 2005-2009 Pentaho and others
009// All Rights Reserved.
010*/
011package mondrian.olap;
012
013import mondrian.calc.Calc;
014import mondrian.calc.ExpCompiler;
015
016import java.io.PrintWriter;
017
018/**
019 * Skeleton implementation of {@link Exp} interface.
020 *
021 * @author jhyde, 20 January, 1999
022 */
023public abstract class ExpBase
024    extends QueryPart
025    implements Exp
026{
027
028    protected static Exp[] cloneArray(Exp[] a) {
029        Exp[] a2 = new Exp[a.length];
030        for (int i = 0; i < a.length; i++) {
031            a2[i] = a[i].clone();
032        }
033        return a2;
034    }
035
036    protected ExpBase() {
037    }
038
039    public abstract Exp clone();
040
041    public static void unparseList(
042        PrintWriter pw,
043        Exp[] exps,
044        String start,
045        String mid,
046        String end)
047    {
048        pw.print(start);
049        for (int i = 0; i < exps.length; i++) {
050            if (i > 0) {
051                pw.print(mid);
052            }
053            exps[i].unparse(pw);
054        }
055        pw.print(end);
056    }
057
058    public static int[] getTypes(Exp[] exps) {
059        int[] types = new int[exps.length];
060        for (int i = 0; i < exps.length; i++) {
061            types[i] = exps[i].getCategory();
062        }
063        return types;
064    }
065
066    public Calc accept(ExpCompiler compiler) {
067        throw new UnsupportedOperationException(this.toString());
068    }
069}
070
071// End ExpBase.java