KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mockobjects > constraint > IsEqual


1 /* Copyright (c) 2002 Nat Pryce. All rights reserved.
2  *
3  * Created on February 10, 2002, 11:35 PM
4  */

5 package com.mockobjects.constraint;
6
7 import java.util.Arrays JavaDoc;
8
9 import com.mockobjects.dynamic.DynamicUtil;
10
11 /** Is the value equal to another value, as tested by the
12  * {@link java.lang.Object#equals} method?
13  */

14 public class IsEqual implements Constraint
15 {
16     private Object JavaDoc _object;
17     
18     public IsEqual( Object JavaDoc equalArg) {
19         if(equalArg instanceof Object JavaDoc[]) {
20             _object = Arrays.asList((Object JavaDoc[])equalArg);
21         } else {
22             _object = equalArg;
23         }
24     }
25     
26     public boolean eval( Object JavaDoc arg ) {
27         if(arg instanceof Object JavaDoc[]) {
28             arg = Arrays.asList((Object JavaDoc[])arg);
29         }
30         return arg.equals(_object);
31     }
32     
33     public String JavaDoc toString() {
34         return " = " + DynamicUtil.proxyToString(_object);
35     }
36     
37     public boolean equals(Object JavaDoc anObject) {
38         return eval(anObject);
39     }
40 }
41
Popular Tags