input
stringlengths
10
828
output
stringlengths
5
107
protected string next type throws ioexception string type null while done type null type read word reader if type length 1 discard empty lines type null continue return type
returns the next type read from the reader given at init or null
private void notify listeners string key object new value list module communication listener list if this listeners null return list this listeners get key if list null return for module communication listener mcl list mcl module value changed key new value
notifies all listeners that have subscribed to the given key
public object get property string key if this properties null return null return this properties get key
returns an object that was stored to this message using the given
protected boolean is known type string type if type equals linestring return true else if type equals multilinestring return true else if type equals point return true else return false
returns true if type is one of the known wkt types
public void update property string key object value throws sim error if this properties null lazy creation to prevent performance overhead for classes that don t use the property feature this properties new hash map string object this properties put key value
updates a value for an existing property
public external event next event external event event this next event if this updates size 0 this next event new external event double max value else this next event this updates remove 0 return event
returns the next scheduled event or event with time double
protected string read word reader r throws ioexception string buffer buf new string buffer char c skip all whitespace r read non whitespace part while c char 1 character is whitespace c buf append c c char r read if c char 1 set done true return buf to string
reads a word ie whitespace delimited string of characters from
public double next events time return this next event get time
returns the next scheduled events time or double
public message replicate message m new message from to id size m copy from this return m
returns a replicate of this message identical except for the unique id
public void add update double sim time external event ee new external event sim time if ee compare to next event 0 this event is already next return else if this next event get time sim time new next event put to queue this next event put the old next event back to q this next event ee else given event happens later put to queue ee
add a new update request for the given time
public string get full property name string setting if contains setting return null if props get property get full property name setting false null return get full property name setting false not found from primary but settings contains must be from 2ndary else return get full property name setting true
returns full namespace prefixed property name for a setting
public int get nrof messages return this router get nrof messages
returns the number of messages this node is carrying
private void put to queue external event ee double ee time ee get time for int i 0 n this updates size i n i double time updates get i get time if time ee time return update with the given time exists no need for new else if ee time time this updates add i ee return all existing updates are earlier add to the end of the list this updates add ee
puts a event to the queue in the right place
protected coord parse point throws ioexception string coords read nested contents reader scanner s new scanner coords double x y try x s next double y s next double catch runtime exception e throw new ioexception bad coordinate values coords return new coord x y
parses a wkt point data from the intialized reader
public int compare to message m return to string compare to m to string
compares two messages by their id alphabetically
public void process event world world this is just a dummy event
processes the external event
public int compare to external event other if this time other time return 0 else if this time other time return 1 else return 1
compares two external events by their time
protected void skip until reader r char until throws ioexception char c do c char r read while c until c char 1
reads and skips all characters until character until is read or
public string to string return ext event this time
returns a string representation of the event
public double get buffer occupancy double b size router get buffer size double free buffer router get free buffer size return 100 b size free buffer b size
returns the buffer occupancy percentage
public void set bidirectional boolean bidi this bidirectional paths bidi
sets bidirectional paths on off
private int get host address string host id string address part if host id matches d address part host id host id is only the address else if host id matches d d string parts host id split d address part parts parts length 1 last occurence is the addr else throw new sim error invalid host id host id return integer parse int address part
parses a host address from a host id string the numeric part before
protected char skip all whitespace reader r throws ioexception char c do c char r read while character is whitespace c c char 1 return c
skips all consecutive whitespace characters from reader
public void set secondary namespace string namespace this secondary namespaces push this secondary namespace this secondary namespace namespace
sets a secondary namespace where a setting is searched from if it
public sim map get map return new sim map this nodes
returns new a sim map that is based on the read map
public void add paths file file int type throws ioexception add paths new file reader file type
adds paths to the map and adds given type to all nodes type
public routing info get routing info return this router get routing info
returns routing info of this hosts router
public void process event world world dtnhost host world get node by address this from addr host delete message id drop
deletes the message
public string read nested contents reader r throws ioexception string buffer contents new string buffer int par open nrof open parentheses char c 0 skip until r par open 1 while c char 1 par open 0 c char r read if c par open if c par open if character is whitespace c c convert all whitespace to basic space contents append c contents delete char at contents length 1 remove last return contents to string
reads everything from the first opening parenthesis until line that
public void add paths reader input int node type throws ioexception this node type node type string type string contents init input while type next type null if type equals linestring contents read nested contents update map parse line string contents else if type equals multilinestring for list coord list parse multilinestring update map list else known type but not interesting skip read nested contents
add paths to current path set
private void update map list coord coords map node previous node null for coord c coords previous node create or update node c previous node
updates simulation map with coordinates in the list
private int draw host address int host range if host range 1 host range 0 return host range 0 return host range 0 rng next int host range 1 host range 0
draws a random host address from the configured address range
public double get last time stamp return last time stamp
returns the time stamp where the last moves read with
private map node create or update node coord c map node previous map node n null n nodes get c try to get the node at that location if n null no node in that location create new n new map node c nodes put c n if previous null n add neighbor previous if bidirectional paths previous add neighbor n if node type 1 n add type node type return n
creates or updates a node that is in location c and next to
public string read nested contents throws ioexception return read nested contents reader
returns nested contents from the reader given at init
public void update if is active return giacomo s hack this net update this router update
updates nodes network layer and router
public double get max time return max time
returns offset max time
public void set nrof preload int nrof if nrof 1 nrof default nrof preload this nrof preload nrof
sets maximum number of events that are read when the next preload occurs
protected boolean is done return this done
returns true if the whole file has been read
protected void set done boolean done this done done
sets the is file read state
public double next events time if events left in buffer 0 in case user request time of an event that doesn t exist return double max value else return queue get next event index get time
returns next events time or double
public double get min time return min time
returns offset min time
public external event next event if queue size 0 no more events return new external event double max value external event ee queue get next event index next event index if next event index queue size ran out of events queue read events nrof preload next event index 0 return ee
returns the next event in the queue or external event with time of
public void restore secondary namespace this secondary namespace this secondary namespaces pop
restores the secondary namespace that was in use before a call to
private boolean set next waypoint if path null path movement get path if path null path has next this next time to move movement next path available this path null return false this destination path get next waypoint this speed path get speed if this mov listeners null for movement listener l this mov listeners l new destination this this destination this speed return true
sets the next destination and speed to correspond the next waypoint
public void connect dtnhost another host if is active this another host return cannot connect self else net connect another host
creates a connection to another host if it is within range
public boolean contains string name try string value get setting name if value null return false else return value trim length 0 catch settings error e return false didn t find the setting
returns true if a setting with defined name in the current namespace
public void bus has stopped int bus id coord bus stop path next path iterator bus traveller movement iterator travellers values iterator while iterator has next bus traveller movement traveller bus traveller movement iterator next if traveller get location null if traveller get location equals bus stop if traveller get state bus traveller movement state waiting for bus path path new path next path traveller enter bus path
called by busses belonging to this system every time the bus has stopped
public void force connection dtnhost another host boolean up if up this net create connection another host else this net destroy connection another host
forces this host to connect disconnect to from another host
public void register bus bus movement bus busses put bus get id bus
registers a bus to be part of a bus control system
public void register traveller bus traveller movement traveller travellers put traveller get id traveller
registers a traveller passenger to be part of a bus control system
public void set map sim map map this sim map map
provide the system with the map
public void send message string id dtnhost to this router send message id to
sends a message from this host to another host
public void set bus stops list coord bus stops this bus stops bus stops
set the bus stops that belong to this system
private string get full property name string name boolean secondary string used namespace secondary secondary namespace namespace if used namespace null return used namespace name else return name
returns full namespace prefixed property name for setting
public int receive message message m dtnhost from int ret val this router receive message m from if ret val message router rcv ok m add node on path this add this node on the messages path return ret val
start receiving a message from another host
public coord get shopping location and get ready ready to shop false new shopping round starts trip scs get evening instructions id start at location trip get location clone return start at location clone
sets the node ready to start a shopping trip
public void set next route coord node location coord node destination from node location clone to node destination clone
sets the next route to be taken
public sim map get map return map
returns the sim map this movement model uses
public boolean is active if this active times null return true no inactive times if cur range null return false out of active times double time sim clock get time if this cur range is out time time for the next time range this cur range active times poll if cur range null return false out of active times return cur range is in range time
returns true if node should be active at the moment
public boolean is in range double time if time start time end return false out of range return true
returns true if the given time is within start and end time
public boolean request deliverable messages connection con return this router request deliverable messages con
requests for deliverable message from this host to be sent trough a
public void add type int type this type type to bit mask type
adds a type indicator to this node
public boolean is ready to shop return ready to shop
checks if a node is at the correct place where the shopping begins
public boolean is out double time return time end
returns true if given time is bigger than end the end time
public boolean is type int types for int type types if is type type return true return false
returns true if the nodes types match any of the given types
private int type to bit mask int type assert type min type type max type invalid node type type return 1 type create the mask by bitwise shift
converts type integer to a bit mask for setting checking type
public coord get min bound return this min bound
returns the upper left corner coordinate of the map
public void add neighbor map node node if node null return add to list node add the node to list
adds the node as this nodes neighbour unless the node is null
public void message transferred string id dtnhost from this router message transferred id from
informs the host that a message was successfully transferred
public coord get max bound return this max bound
returns the lower right corner coordinate of the map
private void add to list map node node if this neighbors contains node node this this neighbors add node
adds the node to list of neighbours unless it is already there or
public coord get offset return this offset
returns the offset that has been caused by translates made to
public boolean is mirrored return this is mirrored
returns true if this map has been mirrored after reading
public string to string return n type 0 t type this location to string
returns a string representation of the map node
public void set next index int index if index stops size index stops size this index index
sets the next index for this route
private void check coord validity list map node nodes check that all map nodes are within world limits for map node n nodes double x n get location get x double y n get location get y if x 0 x get max x y 0 y get max y throw new settings error map node n get location is out of world bounds x 0 get max x y 0 get max y
checks that all coordinates of map nodes are within the min max limits
public void translate double dx double dy for map node n nodes n get location translate dx dy min bound translate dx dy max bound translate dx dy offset translate dx dy needs rehash true
translate whole map by dx and dy
public int compare to map node o return this get location compare to o get location
compares two map nodes by their coordinates
public int get nrof stops return stops size
returns the number of stops on this route
public void message aborted string id dtnhost from int bytes remaining this router message aborted id from bytes remaining
informs the host that a message transfer was aborted
public void mirror assert is mirrored map data already mirrored coord c for map node n nodes c n get location c set location c get x c get y set bounds this is mirrored true needs rehash true
mirrors all map coordinates around x axis x x y y
public map route replicate return new map route type stops
returns a new route with the same settings
private string parse run setting string value final string run array start final string run array end final string run array delim final int min length 3 minimum run is one value e g v if value starts with run array start value ends with run array end run index 0 value length min length return value standard format setting return value value substring 1 value length 1 remove brackets string value arr value split run array delim int arr index run index value arr length value value arr arr index trim return value
parses run specific settings from a string value
private void init with map node node assert ok map nodes null node is type ok map nodes true create needed data structures this unvisited new priority queue map node pq init size new distance comparator this visited new hash set map node this prev nodes new hash map map node map node this distances new distance map set distance to source 0 and initialize unvisited queue this distances put node 0 this unvisited add node
initializes a new search with a source node
public string to string return this nodes to string
returns a string representation of the map
private sim map check cache settings settings int nrof map files settings get int nrof files s if nrof map files cached map files size cached map null return null wrong number of files for int i 1 i nrof map files i string path file settings get setting file s i if path file equals cached map files get i 1 return null found wrong file name all files matched return cached map return cached map
checks map cache if the requested map file s match to the cached
private void relax map node node double node dist distances get node for map node n node get neighbors if visited contains n continue skip visited nodes if ok map nodes null n is type ok map nodes continue skip nodes that are not ok n node s distance from path s source node double n dist node dist get distance node n if distances get n n dist stored distance found dist prev nodes put n node set distance n n dist
relaxes the neighbors of a node updates the shortest distances
public void set speed double speed this speeds new array list double 1 speeds add speed
sets a constant speed for the whole path
public void create new message message m this router create new message m
creates a new message to this hosts router
public void add waypoint coord wp assert this speeds size 1 this method should be used only for paths with constant speed this coords add wp
adds a new waypoint to the end of the path
private void set distance map node n double distance unvisited remove n remove node from old place in the queue distances put n distance update distance unvisited add n insert node to the new place in the queue
sets the distance from source node to a node
public int get max x return this max x
returns the largest x coordinate value this model uses
public void add waypoint coord wp double speed this coords add wp this speeds add speed
adds a new waypoint with a speed towards that waypoint
public void add evening activity node evening activity movement evening movement evening activity nodes put new integer evening movement get id evening movement
register a evening activity node with the system
public coord get next waypoint assert has next path didn t have next wp index 1 waypoint return coords get next wp index
returns the next waypoint on this path
public void set meeting spots list coord meeting spots this meeting spots meeting spots this next trips new evening trip meeting spots size
sets the meeting locations the nodes can choose among
private double get distance map node from map node to return from get location distance to get location
returns the euclidean distance between the two map nodes
public int get max y return this max y
returns the largest y coordinate value this model uses
public boolean has next return next wp index this coords size
returns true if the path has more waypoints false if not