MATSIM
LinkFilter.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * LinkFilter.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2013 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.withinday.replanning.identifiers.filter;
22 
23 import java.util.Iterator;
24 import java.util.Map;
25 import java.util.Set;
26 
27 import org.matsim.api.core.v01.Id;
32 
39 public class LinkFilter implements AgentFilter {
40 
41  private final Map<Id<Person>, MobsimAgent> agents;
42  private final Set<Id<Link>> links;
43 
44  // use the factory
45  /*package*/ LinkFilter(Map<Id<Person>, MobsimAgent> agents, Set<Id<Link>> links) {
46  this.agents = agents;
47  this.links = links;
48  }
49 
50  @Override
51  public void applyAgentFilter(Set<Id<Person>> set, double time) {
52  Iterator<Id<Person>> iter = set.iterator();
53 
54  while (iter.hasNext()) {
55  Id<Person> id = iter.next();
56  if (!this.applyAgentFilter(id, time)) iter.remove();
57  }
58  }
59 
60  @Override
61  public boolean applyAgentFilter(Id<Person> id, double time) {
62  MobsimAgent agent = this.agents.get(id);
63 
64  if (!(links.contains(agent.getCurrentLinkId()))) return false;
65  else return true;
66  }
67 }