MATSIM
NetworkChangeEvent.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * NetworkChangeEvent.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2007 by the members listed in the COPYING, *
8  * LICENSE and WARRANTY file. *
9  * email : info at matsim dot org *
10  * *
11  * *********************************************************************** *
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * See also COPYING, LICENSE and WARRANTY file *
18  * *
19  * *********************************************************************** */
20 
21 package org.matsim.core.network;
22 
25 
26 import java.io.Serializable;
27 import java.util.*;
28 
36 public final class NetworkChangeEvent {
37 
38  public enum ChangeType {
39  ABSOLUTE_IN_SI_UNITS, FACTOR, OFFSET_IN_SI_UNITS
40  }
41 
42  public static class ChangeValue {
43 
44  private final ChangeType type;
45 
46  private final double value;
47 
48  public ChangeValue(ChangeType type, double value) {
49  this.type = type;
50  this.value = value;
51  }
52 
53  public ChangeType getType() {
54  return type;
55  }
56 
57  public double getValue() {
58  return value;
59  }
60 
61  @Override
62  public boolean equals(Object o) {
63  if (this == o) return true;
64  if (o == null || getClass() != o.getClass()) return false;
65 
66  ChangeValue that = (ChangeValue) o;
67 
68  if (Double.compare(that.value, value) != 0) return false;
69  return type == that.type;
70  }
71 
72  @Override
73  public int hashCode() {
74  int result;
75  long temp;
76  result = type.hashCode();
77  temp = Double.doubleToLongBits(value);
78  result = 31 * result + (int) (temp ^ (temp >>> 32));
79  return result;
80  }
81  }
82 
83  // ========================================================================
84  // private members
85  // ========================================================================
86 
87  private final List<Link> links = new ArrayList<>();
88 
89  private final List<Link> unmodifiableLinks = Collections.unmodifiableList(links);
90 
91  private final double startTime;
92 
94 
95  private ChangeValue freespeedChange = null;
96 
97  private ChangeValue lanesChange = null;
98 
99  // ========================================================================
100  // constructor
101  // ========================================================================
102 
109  public NetworkChangeEvent(double startTime) {
110  this.startTime = startTime;
111  }
112 
113  // ========================================================================
114  // accessors
115  // ========================================================================
116 
121  public double getStartTime() {
122  return startTime;
123  }
124 
125 
130  public void addLink(Link link) {
131  links.add(link);
132  }
133 
138  public void addLinks(Collection<? extends Link> links1) {
139  this.links.addAll(links1);
140  }
141 
146  public void removeLink(Link link) {
147  links.remove(link);
148  }
149 
154  public Collection<Link> getLinks() {
155  return unmodifiableLinks;
156  }
157 
164  return flowCapacityChange;
165  }
166 
173  public void setFlowCapacityChange(ChangeValue flowCapacityChange) {
174  this.flowCapacityChange = flowCapacityChange;
175  }
176 
183  return freespeedChange;
184  }
185 
191  public void setFreespeedChange(ChangeValue freespeedChange) {
192  this.freespeedChange = freespeedChange;
193  }
194 
201  return lanesChange;
202  }
203 
209  public void setLanesChange(ChangeValue lanesChange) {
210  this.lanesChange = lanesChange;
211  }
212 
213  public static class StartTimeComparator implements Comparator<NetworkChangeEvent>, Serializable, MatsimComparator {
214  private static final long serialVersionUID = 1L;
215  @Override
217  return Double.compare(o1.getStartTime(), o2.getStartTime());
218  }
219  }
220 
221  @Override
222  public boolean equals(Object o) {
223  if (this == o) return true;
224  if (o == null || getClass() != o.getClass()) return false;
225 
227 
228  if (Double.compare(that.startTime, startTime) != 0) return false;
229  if (!links.equals(that.links)) return false;
230  if (flowCapacityChange != null ? !flowCapacityChange.equals(that.flowCapacityChange) : that.flowCapacityChange != null)
231  return false;
232  if (freespeedChange != null ? !freespeedChange.equals(that.freespeedChange) : that.freespeedChange != null)
233  return false;
234  return lanesChange != null ? lanesChange.equals(that.lanesChange) : that.lanesChange == null;
235  }
236 
237  @Override
238  public int hashCode() {
239  int result;
240  long temp;
241  result = links.hashCode();
242  temp = Double.doubleToLongBits(startTime);
243  result = 31 * result + (int) (temp ^ (temp >>> 32));
244  result = 31 * result + (flowCapacityChange != null ? flowCapacityChange.hashCode() : 0);
245  result = 31 * result + (freespeedChange != null ? freespeedChange.hashCode() : 0);
246  result = 31 * result + (lanesChange != null ? lanesChange.hashCode() : 0);
247  return result;
248  }
249 }
void setFlowCapacityChange(ChangeValue flowCapacityChange)
void setFreespeedChange(ChangeValue freespeedChange)
void addLinks(Collection<? extends Link > links1)
int compare(NetworkChangeEvent o1, NetworkChangeEvent o2)
void setLanesChange(ChangeValue lanesChange)