21 package org.matsim.matrices;
23 import java.util.ArrayList;
24 import java.util.List;
26 import java.util.TreeMap;
28 import org.apache.logging.log4j.LogManager;
29 import org.apache.logging.log4j.Logger;
37 private final String
id;
38 private String
desc = null;
41 private final TreeMap<String,ArrayList<Entry>>
fromLocs =
new TreeMap<>();
42 private final TreeMap<String,ArrayList<Entry>>
toLocs =
new TreeMap<>();
44 private static final Logger
log = LogManager.getLogger(
Matrix.class);
53 public Matrix(
final String
id,
final String desc) {
55 throw new NullPointerException(
"id must not be null");
68 Entry e =
new Entry(fromLocId, toLocId, value);
71 if (!this.fromLocs.containsKey(fromLocId)) {
72 this.fromLocs.put(fromLocId,
new ArrayList<Entry>());
74 ArrayList<Entry> fe = this.fromLocs.get(fromLocId);
78 if (!this.toLocs.containsKey(toLocId)) {
79 this.toLocs.put(toLocId,
new ArrayList<Entry>());
81 ArrayList<Entry> te = this.toLocs.get(toLocId);
86 if (this.counter % this.nextMsg == 0) {
88 log.info(
"Matrix id=" + this.
id +
": entry # " + this.counter);
99 public final Entry setEntry(
final String fromLocId,
final String toLocId,
final double value) {
108 public final void setDesc(
final String desc) {
116 public final void removeEntry(
final String from_loc,
final String to_loc) {
118 ArrayList<Entry> from_loc_entries = this.fromLocs.get(from_loc);
119 ArrayList<Entry> to_loc_entries = this.toLocs.get(to_loc);
121 if ((from_loc_entries == null) || (to_loc_entries == null)) {
123 " and to_loc_id=" + to_loc +
" does not exist!" +
124 " Inconsistent data strucutre!!!");
127 if (!from_loc_entries.remove(entry)) {
129 " and to_loc_id=" + to_loc +
" does not exist!" +
130 " Inconsistent data strucutre!!!");
132 if (from_loc_entries.isEmpty()) {
133 this.fromLocs.remove(from_loc);
136 if (!to_loc_entries.remove(entry)) {
138 " and to_loc_id=" + to_loc +
" does not exist!" +
139 " Inconsistent data strucutre!!!");
141 if (to_loc_entries.isEmpty()) {
142 this.toLocs.remove(to_loc);
144 log.info(
"entry " + entry.
toString() +
" removed.");
168 return this.fromLocs.get(fromLocationId);
172 return this.toLocs.get(toLocationId);
176 ArrayList<Entry> fe = this.fromLocs.get(from);
177 if (fe == null)
return null;
178 for (
int i=0; i<fe.size(); i++) {
193 return "[id=" + this.
id +
"]" +
194 "[desc=" + this.desc +
"]" +
195 "[nof_from_locs=" + this.fromLocs.size() +
"]" +
196 "[nof_to_locs=" + this.toLocs.size() +
"]";
final List< Entry > getFromLocEntries(final String fromLocationId)
final Entry createAndAddEntry(final String fromLocId, final String toLocId, final double value)
final TreeMap< String, ArrayList< Entry > > fromLocs
final List< Entry > getToLocEntries(final String toLocationId)
final void removeEntry(final String from_loc, final String to_loc)
final String getToLocation()
final Map< String, ArrayList< Entry > > getFromLocations()
final TreeMap< String, ArrayList< Entry > > toLocs
final Entry setEntry(final String fromLocId, final String toLocId, final double value)
final Map< String, ArrayList< Entry > > getToLocations()
Matrix(final String id, final String desc)
final void setDesc(final String desc)
final void setValue(final double value)
final Entry getEntry(final String from, final String to)