01: /*
02: * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2006.
03: *
04: * Licensed under the Aduna BSD-style license.
05: */
06: package org.openrdf.query.algebra;
07:
08: /**
09: * A tuple operator that groups tuples that have a specific set of equivalent
10: * variable bindings, and that can apply aggregate functions on the grouped
11: * results.
12: *
13: * @author David Huynh
14: * @author Arjohn Kampman
15: */
16: public class GroupElem extends QueryModelNodeBase {
17:
18: /*-----------*
19: * Variables *
20: *-----------*/
21:
22: private String name;
23:
24: private AggregateOperator operator;
25:
26: /*--------------*
27: * Constructors *
28: *--------------*/
29:
30: public GroupElem(String name, AggregateOperator operator) {
31: setName(name);
32: setOperator(operator);
33: }
34:
35: /*---------*
36: * Methods *
37: *---------*/
38:
39: public String getName() {
40: return name;
41: }
42:
43: public void setName(String name) {
44: assert name != null : "name must not be null";
45: this .name = name;
46: }
47:
48: public AggregateOperator getOperator() {
49: return operator;
50: }
51:
52: public void setOperator(AggregateOperator operator) {
53: assert operator != null : "operator must not be null";
54: this .operator = operator;
55: operator.setParentNode(this );
56: }
57:
58: public <X extends Exception> void visit(QueryModelVisitor<X> visitor)
59: throws X {
60: visitor.meet(this );
61: }
62:
63: @Override
64: public <X extends Exception> void visitChildren(
65: QueryModelVisitor<X> visitor) throws X {
66: operator.visit(visitor);
67: }
68:
69: @Override
70: public void replaceChildNode(QueryModelNode current,
71: QueryModelNode replacement) {
72: if (operator == current) {
73: setOperator((AggregateOperator) replacement);
74: } else {
75: super .replaceChildNode(current, replacement);
76: }
77: }
78:
79: @Override
80: public GroupElem clone() {
81: GroupElem clone = (GroupElem) super.clone();
82: clone.setOperator(getOperator().clone());
83: return clone;
84: }
85: }
|