KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > inside > cluster > ClusterConstraint


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o.inside.cluster;
22
23 import com.db4o.cluster.*;
24 import com.db4o.foundation.*;
25 import com.db4o.query.*;
26
27 /**
28  * @exclude
29  */

30 public class ClusterConstraint implements Constraint{
31     
32     final Cluster _cluster;
33     final Constraint[] _constraints;
34     
35     public ClusterConstraint(Cluster cluster, Constraint[] constraints){
36         _cluster = cluster;
37         _constraints = constraints;
38     }
39     
40     private ClusterConstraint compatible (Constraint with){
41         if(! (with instanceof ClusterConstraint)){
42             throw new IllegalArgumentException JavaDoc();
43         }
44         ClusterConstraint other = (ClusterConstraint)with;
45         if(other._constraints.length != _constraints.length){
46             throw new IllegalArgumentException JavaDoc();
47         }
48         return other;
49     }
50
51     public Constraint and(Constraint with) {
52         return join(with, true);
53     }
54
55     public Constraint or(Constraint with) {
56         return join(with, false);
57     }
58     
59     private Constraint join(Constraint with, boolean isAnd){
60         synchronized(_cluster){
61             ClusterConstraint other = compatible(with);
62             Constraint[] newConstraints = new Constraint[_constraints.length];
63             for (int i = 0; i < _constraints.length; i++) {
64                 newConstraints[i] = isAnd ? _constraints[i].and(other._constraints[i]) : _constraints[i].or(other._constraints[i]);
65             }
66             return new ClusterConstraint(_cluster, newConstraints);
67         }
68     }
69     
70
71     public Constraint equal() {
72         synchronized(_cluster){
73             for (int i = 0; i < _constraints.length; i++) {
74                 _constraints[i].equal();
75             }
76             return this;
77         }
78     }
79
80     public Constraint greater() {
81         synchronized(_cluster){
82             for (int i = 0; i < _constraints.length; i++) {
83                 _constraints[i].greater();
84             }
85             return this;
86         }
87     }
88
89     public Constraint smaller() {
90         synchronized(_cluster){
91             for (int i = 0; i < _constraints.length; i++) {
92                 _constraints[i].smaller();
93             }
94             return this;
95         }
96     }
97
98     public Constraint identity() {
99         synchronized(_cluster){
100             for (int i = 0; i < _constraints.length; i++) {
101                 _constraints[i].identity();
102             }
103             return this;
104         }
105     }
106
107     public Constraint like() {
108         synchronized(_cluster){
109             for (int i = 0; i < _constraints.length; i++) {
110                 _constraints[i].like();
111             }
112             return this;
113         }
114     }
115
116     public Constraint startsWith(boolean caseSensitive) {
117         synchronized(_cluster){
118             for (int i = 0; i < _constraints.length; i++) {
119                 _constraints[i].startsWith(caseSensitive);
120             }
121             return this;
122         }
123     }
124
125     public Constraint endsWith(boolean caseSensitive) {
126         synchronized(_cluster){
127             for (int i = 0; i < _constraints.length; i++) {
128                 _constraints[i].endsWith(caseSensitive);
129             }
130             return this;
131         }
132     }
133
134     public Constraint contains() {
135         synchronized(_cluster){
136             for (int i = 0; i < _constraints.length; i++) {
137                 _constraints[i].contains();
138             }
139             return this;
140         }
141     }
142
143     public Constraint not() {
144         synchronized(_cluster){
145             for (int i = 0; i < _constraints.length; i++) {
146                 _constraints[i].not();
147             }
148             return this;
149         }
150     }
151
152     public Object JavaDoc getObject() {
153         throw new NotSupportedException();
154     }
155 }
156
Popular Tags