19 package org.matsim.core.population;
21 import java.util.LinkedHashMap;
24 import org.apache.logging.log4j.LogManager;
25 import org.apache.logging.log4j.Logger;
38 class PopulationImpl
implements Population, Lockable {
39 private static final Logger log = LogManager.getLogger(PopulationImpl.class);
41 private final Attributes attributes =
new AttributesImpl();
43 private Map<Id<Person>, Person> persons =
new LinkedHashMap<>();
44 private final PopulationFactory populationFactory;
45 private long counter = 0;
46 private long nextMsg = 1;
48 PopulationImpl(PopulationFactory populationFactory2) {
49 this.populationFactory = populationFactory2 ;
53 public void addPerson(
final Person p) {
55 if (this.getPersons().containsKey(p.getId())) {
56 throw new IllegalArgumentException(
"Person with id = " + p.getId() +
" already exists.");
58 if ( p instanceof Lockable ) {
59 ((Lockable) p).setLocked();
64 if (this.counter % this.nextMsg == 0) {
69 this.persons.put( p.getId(), p ) ;
73 public Person removePerson(Id<Person> personId) {
74 return this.persons.remove(personId) ;
78 public final Map<Id<Person>, ? extends Person> getPersons() {
83 public PopulationFactory getFactory() {
84 return this.populationFactory;
88 public String getName() {
93 public void setName(String name) {
98 public final void setLocked() {
99 for ( Person person : this.persons.values() ) {
100 if ( person instanceof Lockable ) {
101 ((Lockable)person).setLocked() ;
106 public void printPlansCount() {
107 log.info(
" person # " + this.counter);
116 public Attributes getAttributes() {