MATSIM
PlanImpl.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * Plan.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2007, 2008 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.population;
22 
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.Map;
26 
27 import org.apache.logging.log4j.LogManager;
28 import org.apache.logging.log4j.Logger;
30 import org.matsim.api.core.v01.Id;
40 
41 /* deliberately package */ final class PlanImpl implements Plan {
42 
43  private Id<Plan> id= null;
44 
45  private ArrayList<PlanElement> actsLegs = new ArrayList<>();
46 
47  private Double score = null;
48  private Person person = null;
49 
50  private String type = null;
51 
52  private final static Logger log = LogManager.getLogger(Plan.class);
53 
54  private Customizable customizableDelegate;
55 
56  private final Attributes attributes = new AttributesImpl();
57 
58  @Override
59  public final Attributes getAttributes() {
60  return this.attributes;
61  }
62 
63  /* package */ PlanImpl() {}
64 
65 // @Override
66 // public final Activity createAndAddActivity(final String type1) {
67 // Activity a = new ActivityImpl(type1);
68 // // (PlanImpl knows the corresponding Activity implementation, so it does not have to go through the factory. kai, jun'16)
69 //
70 // this.addActivity(a) ;
71 // return a;
72 // }
73 
74 
75 
77  // create methods
79 
80 // @Override
81 // public Leg createAndAddLeg(final String mode) {
82 // verifyCreateLeg();
83 // Leg leg = new LegImpl( mode ) ;
84 // getPlanElements().add(leg);
85 // return leg;
86 // }
87 
88 // private static void verifyCreateLeg(Plan plan) throws IllegalStateException {
89 // if (plan.getPlanElements().size() == 0) {
90 // throw new IllegalStateException("The order of 'acts'/'legs' is wrong in some way while trying to create a 'leg'.");
91 // }
92 // }
93 
95  // remove methods
97 
98  @Override
99  public final Person getPerson() {
100  return this.person;
101  }
102 
103  @Override
104  public void setPerson(final Person person) {
105  this.person = person;
106  }
107 
108  @Override
109  public final Double getScore() {
110  return this.score;
111  }
112 
113  @Override
114  public void setScore(final Double score) {
115  this.score = score;
116  }
117 
118  @Override
119  public String getType() {
120  return this.type;
121  }
122 
123  @Override
124  public void setType(final String type) {
125  this.type = type;
126  }
127 
128  @Override
129  public Id<Plan> getId() {
130  if(this.id!=null)
131  return this.id;
132  else {
133  if(this.getAttributes().getAttribute(PlanInheritanceModule.PLAN_ID)!=null)
134  return Id.create(this.getAttributes().getAttribute(PlanInheritanceModule.PLAN_ID).toString(),Plan.class);
135  else return null;
136  }
137 
138  }
139 
140  @Override
141  public void setPlanId(Id<Plan> planId) {
142  this.getAttributes().putAttribute(PlanInheritanceModule.PLAN_ID, planId.toString());
143  this.id = planId;
144  }
145 
146  @Override
147  public int getIterationCreated() {
148  return (int) this.getAttributes().getAttribute(PlanInheritanceModule.ITERATION_CREATED);
149  }
150 
151  @Override
152  public void setIterationCreated(int iteration) {
153  this.getAttributes().putAttribute(PlanInheritanceModule.ITERATION_CREATED, iteration);
154  }
155 
156  @Override
157  public String getPlanMutator() {
158  return (String) this.getAttributes().getAttribute(PlanInheritanceModule.PLAN_MUTATOR);
159  }
160 
161  @Override
162  public void setPlanMutator(String planMutator) {
163  this.getAttributes().putAttribute(PlanInheritanceModule.PLAN_MUTATOR, planMutator);
164  }
165 
166  @Override
167  public final List<PlanElement> getPlanElements() {
168  return this.actsLegs;
169  }
170 
171  @Override
172  public final void addLeg(final Leg leg) {
173  this.actsLegs.add(leg);
174  }
175 
176  @Override
177  public final void addActivity(final Activity act) {
178  this.actsLegs.add(act);
179  }
180 
181  @Override
182  public final String toString() {
183 
184  String scoreString = "undefined";
185  if (this.getScore() != null) {
186  scoreString = this.getScore().toString();
187  }
188  String personIdString = "undefined" ;
189  if ( this.getPerson() != null ) {
190  personIdString = this.getPerson().getId().toString() ;
191  }
192 
193  return "[score=" + scoreString + "]" +
194 // "[selected=" + PersonUtils.isSelected(this) + "]" +
195  "[nof_acts_legs=" + getPlanElements().size() + "]" +
196  "[type=" + this.type + "]" +
197  "[personId=" + personIdString + "]" ;
198  }
199 
200  @Override
201  public final Map<String, Object> getCustomAttributes() {
202  if (this.customizableDelegate == null) {
203  this.customizableDelegate = CustomizableUtils.createCustomizable();
204  }
205  return this.customizableDelegate.getCustomAttributes();
206  }
207 
208 
209 
210 // public final void setLocked() {
211 // for ( PlanElement pe : this.actsLegs ) {
212 // if ( pe instanceof ActivityImpl ) {
213 // ((ActivityImpl) pe).setLocked();
214 // } else if ( pe instanceof LegImpl ) {
215 // ((LegImpl) pe).setLocked() ;
216 // }
217 // }
218 // }
219 
220 }