MATSIM
ChangeModeConfigGroup.java
Go to the documentation of this file.
1 
2 /* *********************************************************************** *
3  * project: org.matsim.*
4  * ChangeModeConfigGroup.java
5  * *
6  * *********************************************************************** *
7  * *
8  * copyright : (C) 2019 by the members listed in the COPYING, *
9  * LICENSE and WARRANTY file. *
10  * email : info at matsim dot org *
11  * *
12  * *********************************************************************** *
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * See also COPYING, LICENSE and WARRANTY file *
19  * *
20  * *********************************************************************** */
21 
22  package org.matsim.core.config.groups;
23 
24 
28 
29 import java.util.Arrays;
30 import java.util.Map;
31 
33 
34  public final static String CONFIG_MODULE = "changeMode";
35  public final static String CONFIG_PARAM_MODES = "modes";
36  public final static String CONFIG_PARAM_IGNORECARAVAILABILITY = "ignoreCarAvailability";
37  public final static String MODE_SWITCH_BEHAVIOR = "modeSwitchBehavior";
38 
39 
40  public enum Behavior { fromAllModesToSpecifiedModes, fromSpecifiedModesToSpecifiedModes }
42 
43  private String[] modes = new String[] { TransportMode.car, TransportMode.pt };
44  private boolean ignoreCarAvailability = true;
46  super(CONFIG_MODULE);
47  }
48 
49  public String[] getModes() {
50  return modes;
51  }
52 
53  @StringGetter( CONFIG_PARAM_MODES )
54  private String getModesString() {
55  return toString( modes );
56  }
57 
59  private void setModes( final String value ) {
60  setModes( toArray( value ) );
61  }
62 
63  public void setModes( final String[] modes ) {
64  this.modes = modes;
65  }
66 
68  public void setIgnoreCarAvailability(final boolean value) {
69  this.ignoreCarAvailability = value;
70  }
71 
73  public boolean getIgnoreCarAvailability() {
74  return ignoreCarAvailability;
75  }
76 
78  public Behavior getBehavior() {
79  return behavior;
80  }
81 
83  public void setBehavior(Behavior behavior) {
84  this.behavior = behavior;
85  }
86 
87  @Override
88  public Map<String, String> getComments() {
89  Map<String, String> comments = super.getComments();
90  comments.put(CONFIG_PARAM_MODES, "Defines all the modes available, including chain-based modes, seperated by commas" );
91  comments.put(CONFIG_PARAM_IGNORECARAVAILABILITY, "Defines whether car availability is considered be considered or not. An agent has no car only if it has no license, or never access to a car. Default: true" );
92  comments.put(MODE_SWITCH_BEHAVIOR,"Defines the mode switch behavior. Possible values "+ Arrays.toString(Behavior.values()) +" Default: fromSpecifiedModesToSpecifiedModes.");
93  return comments;
94  }
95 
96  private static String toString(final String[] modes ) {
97  // (not same as toString() because of argument!)
98 
99  StringBuilder b = new StringBuilder();
100 
101  if (modes.length > 0) b.append( modes[ 0 ] );
102  for (int i=1; i < modes.length; i++) {
103  b.append( ',' );
104  b.append( modes[ i ] );
105  }
106 
107  return b.toString();
108  }
109 
110  private static String[] toArray( final String modes ) {
111  String[] parts = StringUtils.explode(modes, ',');
112 
113  for (int i = 0, n = parts.length; i < n; i++) {
114  parts[i] = parts[i].trim().intern();
115  }
116 
117  return parts;
118  }
119 
120 
121 }
static String [] explode(final String str, final char delimiter, final int limit)