001 /* 002 Copyright (c) 2009 Olivier Chafik, All Rights Reserved 003 004 This file is part of JNAerator (http://jnaerator.googlecode.com/). 005 006 JNAerator is free software: you can redistribute it and/or modify 007 it under the terms of the GNU General Public License as published by 008 the Free Software Foundation, either version 3 of the License, or 009 (at your option) any later version. 010 011 JNAerator is distributed in the hope that it will be useful, 012 but WITHOUT ANY WARRANTY; without even the implied warranty of 013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 GNU General Public License for more details. 015 016 You should have received a copy of the GNU General Public License 017 along with JNAerator. If not, see <http://www.gnu.org/licenses/>. 018 */ 019 package com.ochafik.lang; 020 021 import java.lang.reflect.Field; 022 import java.util.Collection; 023 import java.util.Iterator; 024 025 import com.ochafik.lang.reflect.DebugUtils; 026 027 public class AssertUtils { 028 public static final <T> boolean unorderedEqual(Collection<T> c1, Collection<T> c2) { 029 if (c1.size() != c2.size()) return false; 030 031 return c1.containsAll(c2) && c2.containsAll(c1); 032 } 033 034 public static final <T> boolean orderedEqual(Collection<T> c1, Collection<T> c2) { 035 if (c1.size() != c2.size()) return false; 036 Iterator<T> i1 = c1.iterator(), i2 = c2.iterator(); 037 while (i1.hasNext() && i2.hasNext()) { 038 T t1 = i1.next(), t2 = i2.next(); 039 if ((t1 == null) != (t2 == null)) return false; 040 if (t1 != null) { 041 if (!(t1.equals(t2) && t2.equals(t1))) return false; 042 } 043 } 044 return (i1.hasNext() == i2.hasNext()); 045 } 046 047 public static class Test { 048 int value; 049 String strr = "This is\nA test..."; 050 051 public String getStrr() { 052 return strr; 053 } 054 } 055 056 057 public static void main(String[] args) { 058 //print(new int[] { 1, 2, 3, 4}); 059 DebugUtils.println(new Object[] { new Test(), }, new DebugUtils.FieldAccessor() { 060 public Object access(Field f, Object target) throws IllegalArgumentException, IllegalAccessException { 061 return f.get(target); 062 } 063 }); 064 } 065 }