KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdo > query > AndNode


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.jdo.query;
13
14 /**
15  * An 'and' node. These may participate in joins.
16  */

17 public class AndNode extends Node {
18
19     public AndNode() {
20     }
21
22
23
24     public Object JavaDoc accept(NodeVisitor visitor, Object JavaDoc[] results) {
25       return visitor.visitAndNode(this, results);
26     }
27
28     /**
29      * Create a new instance of us.
30      */

31     protected AndNode createInstance() {
32         return new AndNode();
33     }
34
35     /**
36      * Simplify this node tree as much as possible.
37      */

38     protected void normalizeImp() {
39         if (getClass() != AndNode.class) {
40             super.normalizeImp();
41             return;
42         }
43         // merge children of nested AndNode's into our child list
44
Node prev = null;
45         for (Node n = childList; n != null;) {
46             n.normalizeImp();
47             if (n.getClass() == AndNode.class) {
48                 if (n.childList == null) {
49                     // no children?? remove it from the list
50
n = n.next;
51                     if (prev == null) {
52                         childList = n;
53                     } else {
54                         prev.next = n;
55                     }
56                 } else {
57                     // walk to the end of n's childList and splice that into ours
58
// in place of n
59
Node pos;
60                     for (pos = n.childList; pos.next != null; pos = pos.next) {
61                         pos.parent = this;
62                     }
63                     pos.parent = this;
64                     pos.next = n.next;
65                     if (prev == null) {
66                         childList = n.childList;
67                     } else {
68                         prev.next = n.childList;
69                     }
70                     prev = pos;
71                     n = n.next;
72                 }
73             } else {
74                 prev = n;
75                 n = n.next;
76             }
77         }
78     }
79
80     public Field visit(MemVisitor visitor, Object JavaDoc obj) {
81         return visitor.visitAndNode(this, obj);
82     }
83
84     public Object JavaDoc arrive(NodeVisitor v, Object JavaDoc msg) {
85         return v.arriveAndNode(this, msg);
86     }
87
88 }
89
Popular Tags