01: /*
02: * xtc - The eXTensible Compiler
03: * Copyright (C) 2006-2007 New York University
04: *
05: * This program is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU General Public License
07: * version 2 as published by the Free Software Foundation.
08: *
09: * This program is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License
15: * along with this program; if not, write to the Free Software
16: * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17: * USA.
18: */
19: package xtc.xform;
20:
21: import java.util.List;
22: import java.util.Iterator;
23:
24: import xtc.tree.GNode;
25:
26: /**
27: * EmptyFunction external method class.
28: *
29: * @author Laune Harris
30: * @version $Revision: 1.8 $
31: */
32: class EmptyFunction implements Function {
33: /**
34: * Get the name of the function.
35: *
36: * @return The name of the function.
37: */
38: public String getName() {
39: return "empty";
40: }
41:
42: /**
43: * returns an the sequence of items that have no children
44: */
45: public Object apply(List<Object> args) {
46: Engine.Sequence<?> arg = (Engine.Sequence<?>) args.get(0);
47: Engine.Sequence<Item> noChildren = new Engine.Sequence<Item>();
48: for (Iterator<?> arg_iterator = arg.flatIterator(); arg_iterator
49: .hasNext();) {
50: Item item = (Item) arg_iterator.next();
51: GNode n = (GNode) item.object;
52:
53: if (n.size() == 0) {
54: noChildren.add(item);
55: } else {
56: continue;
57: }
58: }
59: return noChildren;
60: }
61: }
|