1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
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 }