KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > externaltools > internal > launchConfigurations > IgnoreWhiteSpaceComparator


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.ui.externaltools.internal.launchConfigurations;
12
13 import java.util.Comparator JavaDoc;
14
15 public class IgnoreWhiteSpaceComparator implements Comparator JavaDoc {
16
17     /* (non-Javadoc)
18      * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
19      */

20     public int compare(Object JavaDoc o1, Object JavaDoc o2) {
21         String JavaDoc one= (String JavaDoc)o1;
22         String JavaDoc two= (String JavaDoc)o2;
23         int i1 = 0;
24         int i2 = 0;
25         int l1 = one.length();
26         int l2 = two.length();
27         char ch1 = ' ';
28         char ch2 = ' ';
29         while (i1 < l1 && i2 < l2) {
30             while (i1 < l1 && Character.isWhitespace(ch1 = one.charAt(i1))) {
31                 i1++;
32             }
33             while (i2 < l2 && Character.isWhitespace(ch2 = two.charAt(i2))) {
34                 i2++;
35             }
36             if (i1 == l1 && i2 == l2) {
37                 return 0;
38             }
39             if (ch1 != ch2) {
40                 return -1;
41             }
42             i1++;
43             i2++;
44         }
45         return 0;
46     }
47 }
48
Popular Tags