21 package org.matsim.core.network;
23 import java.util.Collections;
26 import org.apache.logging.log4j.LogManager;
27 import org.apache.logging.log4j.Logger;
38 class NodeImpl
implements Node, Lockable {
44 private String type = null;
45 private String origid = null;
47 private transient Map<Id<Link>, Link> inlinks =
new IdentifiableArrayMap<>();
48 private transient Map<Id<Link>, Link> outlinks =
new IdentifiableArrayMap<>();
51 private final Id<Node> id;
52 private boolean locked = false ;
54 private final static Logger log = LogManager.getLogger(Node.class);
55 private final Attributes attributes =
new AttributesImpl();
61 NodeImpl(
final Id<Node>
id,
final Coord coord) {
62 this(id, coord, null);
65 NodeImpl(
final Id<Node>
id,
final Coord coord,
final String type) {
68 NetworkUtils.setType(
this,type);
71 NodeImpl(Id<Node>
id) {
76 void setType(
final String type ) {
77 this.type = type == null ? null : type.intern();
80 private static int cnt2 = 0 ;
82 public final boolean addInLink(Link inlink) {
83 Id<Link> linkid = inlink.getId();
84 if (this.inlinks.containsKey(linkid)) {
85 throw new IllegalArgumentException(
this +
": inlink_id=" + inlink.getId() +
" already exists");
93 this.inlinks.put(linkid, inlink);
97 private static int cnt = 0 ;
99 public final boolean addOutLink(Link outlink) {
100 Id<Link> linkid = outlink.getId();
101 if (this.outlinks.containsKey(linkid)) {
102 throw new IllegalArgumentException(
this +
": outlink_id=" + outlink.getId() +
" already exists");
104 if (this.inlinks.containsKey(linkid) && (cnt < 1)) {
106 log.warn(this.toString() +
": outlink_id=" + outlink.getId() +
" is now in- and out-link");
107 log.warn(Gbl.ONLYONCE) ;
109 this.outlinks.put(linkid, outlink);
113 public void setCoord(
final Coord coord){
118 void setOrigId(
final String origId){
119 this.origid = origId ;
127 public final Link removeInLink(
final Id<Link> linkId ) {
128 return this.inlinks.remove(linkId) ;
132 public Link removeOutLink(
final Id<Link> outLinkId) {
133 return this.outlinks.remove(outLinkId);
149 public Map<Id<Link>, ? extends Link> getInLinks() {
150 return Collections.unmodifiableMap(this.inlinks);
154 public Map<Id<Link>, ? extends Link> getOutLinks() {
155 return Collections.unmodifiableMap(this.outlinks);
159 public Coord getCoord() {
164 public Id<Node> getId() {
182 public String toString() {
183 return "[id=" + this.
id +
"]" +
184 "[coord=" + this.coord +
"]" +
185 "[type=" + this.type +
"]" +
186 "[nof_inlinks=" + this.inlinks.size() +
"]" +
187 "[nof_outlinks=" + this.outlinks.size() +
"]";
191 public void setLocked() {
194 private void testForLocked() {
196 throw new RuntimeException(
"Network is locked; too late to do this. See comments in code.") ;
201 public Attributes getAttributes() {