001 /*
002 // $Id: //open/mondrian-release/3.2/src/main/mondrian/calc/impl/IterableMemberListCalc.java#1 $
003 // This software is subject to the terms of the Eclipse Public License v1.0
004 // Agreement, available at the following URL:
005 // http://www.eclipse.org/legal/epl-v10.html.
006 // Copyright (C) 2008-2009 Julian Hyde
007 // All Rights Reserved.
008 // You must accept the terms of that agreement to use this software.
009 */
010 package mondrian.calc.impl;
011
012 import mondrian.olap.*;
013 import mondrian.calc.DummyExp;
014 import mondrian.calc.Calc;
015 import mondrian.calc.MemberIterCalc;
016
017 import java.util.List;
018 import java.util.ArrayList;
019
020 /**
021 * Adapter that converts a {@link mondrian.calc.MemberIterCalc} to a
022 * {@link mondrian.calc.MemberListCalc}.
023 *
024 * @author jhyde
025 * @version $Id: //open/mondrian-release/3.2/src/main/mondrian/calc/impl/IterableMemberListCalc.java#1 $
026 * @since Oct 23, 2008
027 */
028 public class IterableMemberListCalc extends AbstractMemberListCalc {
029 private final MemberIterCalc iterCalc;
030
031 /**
032 * Creates a IterableMemberListCalc.
033 *
034 * @param iterCalc Calculation that returns an iterable over members.
035 */
036 public IterableMemberListCalc(MemberIterCalc iterCalc) {
037 super(new DummyExp(iterCalc.getType()), new Calc[] {iterCalc});
038 this.iterCalc = iterCalc;
039 }
040
041 public List<Member> evaluateMemberList(Evaluator evaluator) {
042 // A MemberIterCalc is allowed to return a list. If so, save the copy.
043 final Iterable<Member> iterable =
044 iterCalc.evaluateMemberIterable(evaluator);
045 if (iterable instanceof List) {
046 return Util.cast((List) iterable);
047 }
048
049 final List<Member> list = new ArrayList<Member>();
050 for (Member o : iterable) {
051 list.add(o);
052 }
053 return list;
054 }
055 }
056
057 // End IterableMemberListCalc.java