Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/LineLocation.java @ 18986:50b22daf6d53
Truffle/Source: add default comparator for LineLocation
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Tue, 27 Jan 2015 20:25:26 -0800 |
parents | e3c95cbbb50c |
children |
comparison
equal
deleted
inserted
replaced
18985:867058575979 | 18986:50b22daf6d53 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this | 7 * published by the Free Software Foundation. Oracle designates this |
22 * or visit www.oracle.com if you need additional information or have any | 22 * or visit www.oracle.com if you need additional information or have any |
23 * questions. | 23 * questions. |
24 */ | 24 */ |
25 package com.oracle.truffle.api.source; | 25 package com.oracle.truffle.api.source; |
26 | 26 |
27 import java.util.*; | |
28 | |
27 /** | 29 /** |
28 * A specification for a location in guest language source, expressed as a line number in a specific | 30 * A specification for a location in guest language source, expressed as a line number in a specific |
29 * instance of {@link Source}, suitable for hash table keys with equality defined in terms of | 31 * instance of {@link Source}, suitable for hash table keys with equality defined in terms of |
30 * content. | 32 * content. |
31 */ | 33 */ |
38 */ | 40 */ |
39 int getLineNumber(); | 41 int getLineNumber(); |
40 | 42 |
41 String getShortDescription(); | 43 String getShortDescription(); |
42 | 44 |
45 /** | |
46 * Default comparator by (1) textual path name, (2) line number. | |
47 */ | |
48 Comparator<LineLocation> COMPARATOR = new Comparator<LineLocation>() { | |
49 | |
50 public int compare(LineLocation l1, LineLocation l2) { | |
51 final int sourceResult = l1.getSource().getPath().compareTo(l2.getSource().getPath()); | |
52 if (sourceResult != 0) { | |
53 return sourceResult; | |
54 } | |
55 return Integer.compare(l1.getLineNumber(), l2.getLineNumber()); | |
56 } | |
57 | |
58 }; | |
59 | |
43 } | 60 } |