Mercurial > hg > graal-compiler
changeset 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 | 867058575979 |
children | ac114ad31cdd |
files | graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/LineLocation.java |
diffstat | 1 files changed, 18 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/LineLocation.java Tue Jan 27 20:24:54 2015 -0800 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/LineLocation.java Tue Jan 27 20:25:26 2015 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,6 +24,8 @@ */ package com.oracle.truffle.api.source; +import java.util.*; + /** * A specification for a location in guest language source, expressed as a line number in a specific * instance of {@link Source}, suitable for hash table keys with equality defined in terms of @@ -40,4 +42,19 @@ String getShortDescription(); + /** + * Default comparator by (1) textual path name, (2) line number. + */ + Comparator<LineLocation> COMPARATOR = new Comparator<LineLocation>() { + + public int compare(LineLocation l1, LineLocation l2) { + final int sourceResult = l1.getSource().getPath().compareTo(l2.getSource().getPath()); + if (sourceResult != 0) { + return sourceResult; + } + return Integer.compare(l1.getLineNumber(), l2.getLineNumber()); + } + + }; + }