KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > launching > RuntimeClasspathEntryListComparator


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.launching;
12
13
14 import java.util.Comparator JavaDoc;
15 import java.util.List JavaDoc;
16
17 /**
18  * Compares lists of runtime classpath entry mementos
19  */

20 public class RuntimeClasspathEntryListComparator implements Comparator JavaDoc {
21
22     /**
23      * @see Comparator#compare(Object, Object)
24      */

25     public int compare(Object JavaDoc o1, Object JavaDoc o2) {
26         List JavaDoc list1 = (List JavaDoc)o1;
27         List JavaDoc list2 = (List JavaDoc)o2;
28         
29         if (list1.size() == list2.size()) {
30             for (int i = 0; i < list1.size(); i++) {
31                 String JavaDoc memento1 = (String JavaDoc)list1.get(i);
32                 String JavaDoc memento2 = (String JavaDoc)list2.get(i);
33                 if (!equalsIgnoreWhitespace(memento1, memento2)) {
34                     return -1;
35                 }
36             }
37             return 0;
38         }
39         return -1;
40     }
41     
42     protected boolean equalsIgnoreWhitespace(String JavaDoc one, String JavaDoc two) {
43         int i1 = 0;
44         int i2 = 0;
45         int l1 = one.length();
46         int l2 = two.length();
47         char ch1 = ' ';
48         char ch2 = ' ';
49         while (i1 < l1 && i2 < l2) {
50             while (i1 < l1 && Character.isWhitespace(ch1 = one.charAt(i1))) {
51                 i1++;
52             }
53             while (i2 < l2 && Character.isWhitespace(ch2 = two.charAt(i2))) {
54                 i2++;
55             }
56             if (i1 == l1 && i2 == l2) {
57                 return true;
58             }
59             if (ch1 != ch2) {
60                 return false;
61             }
62             i1++;
63             i2++;
64         }
65         return true;
66     }
67
68 }
69
Popular Tags