1 package org.opentrafficsim.base;
2
3 import org.djunits.value.vdouble.scalar.Length;
4 import org.djutils.exceptions.Throw;
5
6 /**
7 * Wrapper for object and its distance.
8 * <p>
9 * Copyright (c) 2026-2026 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
10 * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
11 * </p>
12 * @author Wouter Schakel
13 * @param object underlying object
14 * @param distance distance to object
15 * @param <T> underlying object type
16 */
17 public record DistancedObject<T>(T object, Length distance) implements Comparable<DistancedObject<T>>
18 {
19
20 /**
21 * Constructor.
22 * @param object underlying object
23 * @param distance distance to object@param object underlying object
24 */
25 public DistancedObject
26 {
27 Throw.whenNull(object, "object");
28 Throw.whenNull(distance, "distance");
29 }
30
31 @Override
32 public int compareTo(final DistancedObject<T> o)
33 {
34 int out = this.distance.compareTo(o.distance);
35 if (out != 0)
36 {
37 return out;
38 }
39 return Integer.compare(this.object.hashCode(), o.object.hashCode());
40 }
41
42 }