KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > jmi > javamodel > usages > FindUtils


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * FindUtils.java
21  *
22  * Created on 30. leden 2004, 13:28
23  */

24
25 package org.netbeans.jmi.javamodel.usages;
26
27 import java.io.*;
28 import java.util.*;
29 import junit.framework.AssertionFailedError;
30 import org.netbeans.jmi.javamodel.MultipartId;
31 import org.netbeans.junit.AssertionFailedErrorException;
32
33 /**
34  *
35  * @author Jan Becicka
36  */

37 public class FindUtils {
38
39     public static Collection getImmediateComposites(Collection col) {
40         List l = new ArrayList();
41
42         Iterator i = col.iterator();
43
44         while (i.hasNext()) {
45             l.add(((MultipartId)i.next()).refImmediateComposite());
46         }
47         return l;
48     }
49     
50     public static void compare(Collection col, String JavaDoc[] classNames, PrintStream log) {
51         
52         col = getImmediateComposites(col);
53         
54         Collections.sort((List) col, new Comparator() {
55             public int compare(Object JavaDoc o1, Object JavaDoc o2) {
56                 return ((Comparable JavaDoc) o1.getClass().getName()).compareTo(o2.getClass().getName());
57             }
58         });
59         
60         log.println("Expected number of usages: " + classNames.length);
61         log.println("Total usages found: " + col.size());
62         log.println("\nExpected usage \tFound usage");
63         log.println("======================================================");
64         boolean passed=true;
65         int i=0;
66         try {
67             for (Iterator it = col.iterator(); it.hasNext() && i<classNames.length; i++) {
68                 Object JavaDoc o = it.next();
69                 if (! Class.forName("org.netbeans.jmi.javamodel." + classNames[i]).isInstance(o)) {
70                     passed = false;
71                 }
72                 log.println("MultipartId in " + classNames[i] + "\t Multipartid in " + o.getClass().getName());
73             }
74             if (i != classNames.length) {
75                 passed = false;
76             }
77         } catch (ClassNotFoundException JavaDoc ex) {
78             throw new AssertionFailedErrorException(ex);
79         }
80         if (!passed) {
81             throw new AssertionFailedError("Test failed, see log file for details");
82         }
83     }
84 }
85     
86
87
Popular Tags