All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nl.tudelft.simulation.dsol.animation.d2.Renderable2dComparator Maven / Gradle / Ivy

package nl.tudelft.simulation.dsol.animation.d2;

import java.util.Comparator;

/**
 * A comparator for two Renderable2d objects. 
 * 

* Copyright (c) 2002-2024 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See * for project information https://simulation.tudelft.nl. The DSOL * project is distributed under a three-clause BSD-style license, which can be found at * * https://https://simulation.tudelft.nl/dsol/docs/latest/license.html. *

* @author Peter Jacobs * @since 1.5 */ public class Renderable2dComparator implements Comparator> { /** * constructs a new Renderable2dComparator. */ public Renderable2dComparator() { super(); } /** {@inheritDoc} */ @Override public int compare(final Renderable2dInterface r1, final Renderable2dInterface r2) { try { double z1 = r1.getSource().getZ(); double z2 = r2.getSource().getZ(); if (z1 > z2) { return 1; } if (z1 < z2) { return -1; } } catch (Exception exception) { // ignore as this can happen when the source is in the process of deletion // and therefore it cannot return a proper location. } return Long.compare(r1.getId(), r2.getId()); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy