KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > search > internal > ui > text > PathSorter


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

11 package org.eclipse.search.internal.ui.text;
12
13 import org.eclipse.core.resources.IResource;
14 import org.eclipse.core.runtime.IPath;
15
16 public class PathSorter extends NameSorter {
17     protected int compare(IResource left, IResource right) {
18         IPath path1= left.getFullPath();
19         IPath path2= right.getFullPath();
20         int segmentCount= Math.min(path1.segmentCount(), path2.segmentCount());
21         for (int i= 0; i < segmentCount; i++) {
22             int value= collator.compare(path1.segment(i), path2.segment(i));
23             if (value != 0)
24                 return value;
25         }
26         return path1.segmentCount() - path2.segmentCount();
27     }
28 }
29
Popular Tags