View Javadoc

1   /*
2   	Copyright (c) 2009 Olivier Chafik, All Rights Reserved
3   	
4   	This file is part of JNAerator (http://jnaerator.googlecode.com/).
5   	
6   	JNAerator is free software: you can redistribute it and/or modify
7   	it under the terms of the GNU General Public License as published by
8   	the Free Software Foundation, either version 3 of the License, or
9   	(at your option) any later version.
10  	
11  	JNAerator is distributed in the hope that it will be useful,
12  	but WITHOUT ANY WARRANTY; without even the implied warranty of
13  	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  	GNU General Public License for more details.
15  	
16  	You should have received a copy of the GNU General Public License
17  	along with JNAerator.  If not, see <http://www.gnu.org/licenses/>.
18  */
19  package com.ochafik.lang;
20  
21  import java.lang.reflect.Field;
22  import java.util.Collection;
23  import java.util.Iterator;
24  
25  import com.ochafik.lang.reflect.DebugUtils;
26  
27  public class AssertUtils {
28  	public static final <T> boolean unorderedEqual(Collection<T> c1, Collection<T> c2) {
29  		if (c1.size() != c2.size()) return false;
30  		
31  		return c1.containsAll(c2) && c2.containsAll(c1);
32  	}
33  	
34  	public static final <T> boolean orderedEqual(Collection<T> c1, Collection<T> c2) {
35  		if (c1.size() != c2.size()) return false;
36  		Iterator<T> i1 = c1.iterator(), i2 = c2.iterator();
37  		while (i1.hasNext() && i2.hasNext()) {
38  			T t1 = i1.next(), t2 = i2.next();
39  			if ((t1 == null) != (t2 == null)) return false;
40  			if (t1 != null) {
41  				if (!(t1.equals(t2) && t2.equals(t1))) return false;
42  			}
43  		}
44  		return (i1.hasNext() == i2.hasNext());
45  	}
46  	
47  	public static class Test {
48  		int value;
49  		String strr = "This is\nA test...";
50  		
51  		public String getStrr() {
52  			return strr;
53  		}
54  	}
55  	
56  
57  	public static void main(String[] args) {
58  		//print(new int[] { 1, 2, 3, 4});
59  		DebugUtils.println(new Object[] { new Test(), }, new DebugUtils.FieldAccessor() {
60  			public Object access(Field f, Object target) throws IllegalArgumentException, IllegalAccessException {
61  				return f.get(target);
62  			}
63  		});
64  	}
65  }