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:
20: package xtc.xform;
21:
22: import java.util.List;
23:
24: /**
25: * Subsequence external method class.
26: *
27: * @version $Revision: 1.8 $
28: */
29: class SubsequenceFunction implements Function {
30:
31: /**
32: * Get the name of the function.
33: * @return The function name
34: */
35: public String getName() {
36: return "subsequence";
37: }
38:
39: /**
40: * return items in the range specified by arg(1) and args(2)
41: * @param args The sequence and the start and end index
42: * @return The items in the index range specifed
43: */
44: public Object apply(List<Object> args) {
45: Integer s = (Integer) args.get(1);
46: Integer e = (Integer) args.get(2);
47: int start = s.intValue();
48: int end = e.intValue();
49: Engine.Sequence<?> arg1 = ((Engine.Sequence<?>) args.get(0));
50: Engine.Sequence<Item> result = new Engine.Sequence<Item>();
51:
52: for (int i = start - 1; i < end; i++) {
53: result.add((Item) arg1.get(i));
54: }
55: return result;
56: }
57: }
|