1 /*********************************************************************
2 Copyright 2012, Ralph Ronnquist.
4 This file is part of GORITE.
6 GORITE is free software: you can redistribute it and/or modify it
7 under the terms of the Lesser GNU General Public License as published
8 by the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 GORITE is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the Lesser GNU General Public
17 License along with GORITE. If not, see <http://www.gnu.org/licenses/>.
18 **********************************************************************/
20 package com.intendico.data;
22 import java.util.Vector;
25 * The Equals class is a query to ensure that two or more given
26 * objects are equal, where any or both of the objects may be {@link
27 * Ref} objects. If a {@link Ref} object is null, it is set to the
30 public class Equals extends Condition {
33 * The distinct values concerned.
35 public Object [] values;
40 public Equals(Object/*...*/ [] v) {
45 * The {@link Query#copy} method implemented by creating a new
46 * Except object with a copy of the ref, but the same values
48 //@SuppressWarnings("unchecked")
49 public Query copy(Vector/*<Ref>*/ newrefs) throws Exception {
50 Object [] v = new Object [ values.length ];
51 for ( int i = 0; i < values.length; i++ ) {
52 if ( values[ i ] instanceof Ref ) {
53 v[ i ] = ((Ref)values[ i ]).find( newrefs );
58 return new Equals( v );
62 * The exception condition.
63 * @return <em>false</em> if the {@link Ref} object is equal to
64 * any value, otherwise <em>true</em>. Note that any Ref object as
65 * value is also dereferenced.
67 public boolean condition() {
69 for ( int i = 0; i < values.length; i++ ) {
70 Object value = values[ i ];
71 Object y = Ref.deref( value );
72 if ( x != null && ! x.equals( y ) )
80 * The {@link Query#getRefs} method implemented by adding and Ref
81 * not already contained in the vector.
83 public Vector/*<Ref>*/ getRefs(Vector/*<Ref>*/ v) {
84 for ( int i = 0; i < values.length; i++ ) {
85 Object x = values[ i ];
86 if ( x instanceof Ref && ! v.contains( x ) )
93 * Returns the textual representation of the query.
95 public String toString() {
96 StringBuilder s = new StringBuilder( "equals(" );
97 for ( int i = 0; i < values.length; i++ ) {
98 Object x = values[ i ];
100 if ( x instanceof Ref ) {
101 s.append( ((Ref) x).getName() );
104 s.append( x.toString() );