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.ArrayList;
23: import java.util.Iterator;
24:
25: /**
26: * isNull external method class.
27: *
28: * @author Joe Pamer
29: * @version $Revision: 1.9 $
30: */
31:
32: class IsNullFunction implements Function {
33:
34: /**
35: * Get the name of the function.
36: *
37: * @return The name of the function.
38: */
39: public String getName() {
40: return "isNull";
41: }
42:
43: /**
44: * Test to see if the list in args is composed soley of null items.
45: *
46: * @param args A list of one argument - a sequence of items.
47: * @return A non-empty sequence if arg contains only null items, otherwise
48: * an empty sequence.
49: */
50: public Object apply(List<Object> args) {
51: Engine.Sequence<?> arg = (Engine.Sequence<?>) args.get(0);
52:
53: for (Iterator<?> arg_iterator = arg.flatIterator(); arg_iterator
54: .hasNext();) {
55:
56: Item item = (Item) arg_iterator.next();
57: if (null != item.object) {
58: return new ArrayList<Item>();
59: } else {
60: continue;
61: }
62: }
63:
64: return arg;
65: }
66: }
|