tracesrv/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/source/PositionArrayComparator.java
equal
deleted
inserted
replaced
|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 * Comparator for position arrays |
|
17 * |
|
18 */ |
|
19 package com.nokia.tracecompiler.source; |
|
20 |
|
21 import java.util.Comparator; |
|
22 |
|
23 /** |
|
24 * Comparator for position arrays |
|
25 * |
|
26 */ |
|
27 public final class PositionArrayComparator implements |
|
28 Comparator<SourceLocationBase> { |
|
29 |
|
30 /* |
|
31 * (non-Javadoc) |
|
32 * |
|
33 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) |
|
34 */ |
|
35 public int compare(SourceLocationBase arrayElement, SourceLocationBase key) { |
|
36 int retval; |
|
37 if (key.getOffset() < arrayElement.getOffset()) { |
|
38 // Start is inclusive |
|
39 retval = 1; |
|
40 } else if (key.getOffset() >= arrayElement.getOffset() |
|
41 + arrayElement.getLength()) { |
|
42 // End is exclusive |
|
43 retval = -1; |
|
44 } else { |
|
45 retval = 0; |
|
46 } |
|
47 return retval; |
|
48 } |
|
49 |
|
50 } |