001/* *********************************************************************** *
002 * project: org.matsim.*
003 *                                                                         *
004 * *********************************************************************** *
005 *                                                                         *
006 * copyright       : (C) 2013 by the members listed in the COPYING,     *
007 *                   LICENSE and WARRANTY file.                            *
008 * email           : info at matsim dot org                                *
009 *                                                                         *
010 * *********************************************************************** *
011 *                                                                         *
012 *   This program is free software; you can redistribute it and/or modify  *
013 *   it under the terms of the GNU General Public License as published by  *
014 *   the Free Software Foundation; either version 2 of the License, or     *
015 *   (at your option) any later version.                                   *
016 *   See also COPYING, LICENSE and WARRANTY file                           *
017 *                                                                         *
018 * *********************************************************************** */
019
020package org.matsim.core.network.algorithms.intersectionSimplifier.containers;
021
022import java.util.Comparator;
023import java.util.Map;
024
025import org.locationtech.jts.triangulate.quadedge.QuadEdge;
026
027public class QuadEdgeComparator implements Comparator<QuadEdge> {
028        
029        Map<QuadEdge,Double> map;
030        
031        /**
032         * Constructor.
033         * 
034         * @param map
035         *              map containing QuadEdge and Double
036         */
037        public QuadEdgeComparator(Map<QuadEdge,Double> map) {
038                this.map = map;
039        }
040
041        /**
042         * Method of comparison. Ranks the QuadEdge in descending order.
043         * 
044         * @param qeA
045         *              quad edge to compare
046         * @param qeB
047         *              quad edge to compare
048         * @return
049         *              1 if double value associated to qeA  < double
050         *              value associated to qeB,
051         *              0 if values are equals,
052         *              -1 otherwise
053         */
054        @Override
055        public int compare(QuadEdge qeA, QuadEdge qeB) {
056                Double valA = this.map.get(qeA);
057                Double valB = this.map.get(qeB);
058                return valB.compareTo(valA);
059        }
060
061}