# HG changeset patch # User Michael Van De Vanter # Date 1422419126 28800 # Node ID 50b22daf6d53dd9c0362abb8394f53d1b4a1dda5 # Parent 8670585759797e702604be0279b8d8b989a7112f Truffle/Source: add default comparator for LineLocation diff -r 867058575979 -r 50b22daf6d53 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/LineLocation.java --- 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 COMPARATOR = new Comparator() { + + 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()); + } + + }; + }