EKEdgeEntry.java

  1. /*
  2.  *  Licensed to GraphHopper GmbH under one or more contributor
  3.  *  license agreements. See the NOTICE file distributed with this work for
  4.  *  additional information regarding copyright ownership.
  5.  *
  6.  *  GraphHopper GmbH licenses this file to you under the Apache License,
  7.  *  Version 2.0 (the "License"); you may not use this file except in
  8.  *  compliance with the License. You may obtain a copy of the License at
  9.  *
  10.  *       http://www.apache.org/licenses/LICENSE-2.0
  11.  *
  12.  *  Unless required by applicable law or agreed to in writing, software
  13.  *  distributed under the License is distributed on an "AS IS" BASIS,
  14.  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15.  *  See the License for the specific language governing permissions and
  16.  *  limitations under the License.
  17.  */
  18. package org.heigit.ors.fastisochrones.partitioning;

  19. /**
  20.  * Lightweight entry object for ordering nodes in a queue/deque based on weight.
  21.  *
  22.  * @author Hendrik Leuschner
  23.  */
  24. public class EKEdgeEntry implements Comparable<EKEdgeEntry> {
  25.     private final int node;
  26.     private final int weight;

  27.     public EKEdgeEntry(int node, int weight) {
  28.         this.node = node;
  29.         this.weight = weight;
  30.     }

  31.     public int getNode() {
  32.         return node;
  33.     }

  34.     public int getWeight() {
  35.         return weight;
  36.     }

  37.     @Override
  38.     public int compareTo(EKEdgeEntry o) {
  39.         if (node == o.node && weight == o.weight)
  40.             return 0;

  41.         if (weight < o.weight)
  42.             return -1;
  43.         if (weight > o.weight)
  44.             return 1;
  45.         //Same weight case
  46.         return node < o.node ? -1 : 1;
  47.     }

  48.     @Override
  49.     public boolean equals(Object obj) {
  50.         if (this == obj)
  51.             return true;
  52.         if (obj == null)
  53.             return false;
  54.         if (getClass() != obj.getClass())
  55.             return false;
  56.         EKEdgeEntry other = (EKEdgeEntry) obj;
  57.         return (node == other.node && weight == other.weight);
  58.     }

  59.     @Override
  60.     public int hashCode() {
  61.         return node * 31 + weight;
  62.     }
  63. }