01: package org.ofbiz.rules.logikus;
02:
03: import java.util.*;
04: import org.ofbiz.rules.engine.*;
05: import org.ofbiz.rules.parse.*;
06: import org.ofbiz.rules.parse.tokens.*;
07:
08: /**
09: * <p><b>Title:</b> List With Tail Assembler
10: * <p><b>Description:</b> None
11: * <p>Copyright (c) 1999 Steven J. Metsker.
12: * <p>Copyright (c) 2001 The Open For Business Project - www.ofbiz.org
13: *
14: * <p>Permission is hereby granted, free of charge, to any person obtaining a
15: * copy of this software and associated documentation files (the "Software"),
16: * to deal in the Software without restriction, including without limitation
17: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18: * and/or sell copies of the Software, and to permit persons to whom the
19: * Software is furnished to do so, subject to the following conditions:
20: *
21: * <p>The above copyright notice and this permission notice shall be included
22: * in all copies or substantial portions of the Software.
23: *
24: * <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
27: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
28: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
29: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
30: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31: *
32: * <br>
33: * <p>Pops the tail and terms of a list from an assembly's stack,
34: * builds the list, and pushes it.
35: *
36: * @author Steven J. Metsker
37: * @version 1.0
38: */
39: public class ListWithTailAssembler extends Assembler {
40:
41: /**
42: * Pops the tail and terms of a list from an assembly's stack,
43: * builds the list, and pushes it.
44: *
45: * @param Assembly the assembly to work on
46: */
47: public void workOn(Assembly a) {
48: Term tail = (Term) a.pop();
49:
50: Token fence = new Token('[');
51:
52: List termVector = elementsAbove(a, fence);
53: Term[] termsToLast = StructureWithTermsAssembler
54: .vectorReversedIntoTerms(termVector);
55:
56: a.push(Structure.list(termsToLast, tail));
57: }
58: }
|