/** * Parses the given string for a textual representation for time and returns * the time value in seconds past midnight. It is the same as {@link #parseTime(String, char)} * with the separator set to ':'. * * @param time the string describing a time to parse. * * @return the parsed time as seconds after midnight. * * @throws IllegalArgumentException when the string cannot be interpreted as a valid time. */ public static final double parseTime(final String time) { return parseTime(time, ':'); }
private void writeCost(Cost cost) throws IOException { this.writer.write("\t<cost "); if (!Time.isUndefinedTime(cost.startTime)) { this.writer.write("start_time=\"" + Time.writeTime(cost.startTime) + "\" "); } if (!Time.isUndefinedTime(cost.endTime) && cost.endTime != Double.POSITIVE_INFINITY // The toll reader converts undefined time to POSITIVE_INFINITY since otherwise it does not make sense. // This, however, means that we need to deal with this here as well. kai, aug'14 ) { this.writer.write("end_time=\"" + Time.writeTime(cost.endTime) + "\" "); } this.writer.write("amount=\"" + cost.amount + "\" />\n"); }
@StringSetter(END_TIME) public void setSimulationEndTime(String simulationEndTime) { double parsedTime = Time.parseTime(simulationEndTime); if (!Time.isUndefinedTime(parsedTime)) { this.simulationEndTime = parsedTime; } }
public void finish(double now) { if ( writer != null ) { while ( records.peek()!=null ) { String record = records.poll(); String timeStr = record.substring(0, 8); log.info( "timeStr=" + timeStr ) ; String nowAsStr = Time.writeTime(now) ; if ( Time.parseTime(timeStr) > now ) { record.replace(timeStr,nowAsStr) ; // (clear disruptions at simulation end rather than at provided time. Makes the VIA time range more meaningful. // Also, I need to clear them since otherwise the time-dep display does not work. :-( kai, feb'18) } writer.println( record ); } writer.close(); } } }
public void testSetDefault() { Time.setDefaultTimeFormat(Time.TIMEFORMAT_HHMMSS); assertEquals("12:34:56", Time.writeTime(12*3600 + 34*60 + 56.789)); Time.setDefaultTimeFormat(Time.TIMEFORMAT_HHMM); assertEquals("12:34", Time.writeTime(12*3600 + 34*60 + 56.789)); Time.setDefaultTimeFormat(Time.TIMEFORMAT_SSSS); assertEquals(Integer.toString(12*3600 + 34*60 + 56), Time.writeTime(12*3600 + 34*60 + 56.789)); Time.setDefaultTimeFormat(Time.TIMEFORMAT_HHMMSSDOTSS); assertEquals("12:34:56.78", Time.writeTime(12*3600 + 34*60 + 56.789).substring(0, 11)); // (conversion to double of .789 looks like .788999999999... thus that dirty trick. // kai/gregor, nov'11) }
@Override public boolean applyAgentFilter(Id<Person> id, double time) { Double earliestLinkExitTime = this.earliestLinkExitTimeProvider.getEarliestLinkExitTime(id); if (Time.isUndefinedTime(earliestLinkExitTime)) return false; else if (earliestLinkExitTime <= time) return false; else return true; } }
public void testConvertHHMMInteger() { assertEquals( 12*3600.0 + 34*60.0, Time.convertHHMMInteger(Integer.valueOf("1234")), 0.0); assertEquals( 1*3600.0 + 2*60.0, Time.convertHHMMInteger(Integer.valueOf("0102")), 0.0); }
public void testUndefined() { // test writing assertEquals("undefined", Time.writeTime(Time.UNDEFINED_TIME)); // test reading assertEquals(Time.UNDEFINED_TIME, Time.parseTime("undefined"), 0.0); assertEquals(Time.UNDEFINED_TIME, Time.parseTime(""), 0.0); assertEquals(Time.UNDEFINED_TIME, Time.parseTime(null), 0.0); }
public void testWriting() { Time.setDefaultTimeFormat(Time.TIMEFORMAT_HHMMSS); assertEquals( "12:34:56", Time.writeTime( 12*3600 + 34*60 + 56.789));// positive assertEquals( "01:02:03", Time.writeTime( 1*3600 + 2*60 + 3.4)); // positive with leading zero assertEquals("-12:34:56", Time.writeTime(-12*3600 - 34*60 - 56.789)); // negative assertEquals("-01:02:03", Time.writeTime( -1*3600 - 2*60 - 3.4)); // negative with leading zero assertEquals( "00:00:00", Time.writeTime(0.0)); // zero /* Integer.MIN_VALUE is a special value in case time values would be represented by int's, and not double's. * Math.abs(Integer.MIN_VALUE) returns Integer.MIN_VALUE again, what could lead to a infinite loop depending * how negative times are handled internally. So this test should ensure this or a future implementation * does not have problems with that. */ assertEquals("-596523:14:08", Time.writeTime(Integer.MIN_VALUE)); }
@Override public double set(Id<TransitStopFacility> fromStop, Id<TransitStopFacility> toStop, double seconds) { if (Double.isNaN(seconds) || Time.isUndefinedTime(seconds)) { return remove(fromStop, toStop); } Map<Id<TransitStopFacility>, Double> innerMap = this.minimalTransferTimes.computeIfAbsent(fromStop, key -> new ConcurrentHashMap<>()); Double value = innerMap.put(toStop, seconds); if (value == null) { return Double.NaN; } return 0; }
@StringGetter(END_TIME) String getEndTimeAsString() { return Time.writeTime(this.endTime ) ; } public double getEndTime() {
private double getDouble(String timeString) { if (timeString.contains(":")) { return Time.parseTime(timeString); } else { return Double.parseDouble(timeString); } }
private static void startLeg(final Leg leg, final BufferedWriter out) throws IOException { out.write("\t\t\t<leg mode=\""); out.write(leg.getMode()); out.write("\""); if (!Time.isUndefinedTime(leg.getDepartureTime())) { out.write(" dep_time=\""); out.write(Time.writeTime(leg.getDepartureTime())); out.write("\""); } if (!Time.isUndefinedTime(leg.getTravelTime())) { out.write(" trav_time=\""); out.write(Time.writeTime(leg.getTravelTime())); out.write("\""); } // if (leg instanceof LegImpl) { // LegImpl l = (LegImpl)leg; // if (l.getDepartureTime() + l.getTravelTime() != Time.UNDEFINED_TIME) { // out.write(" arr_time=\""); // out.write(Time.writeTime(l.getDepartureTime() + l.getTravelTime())); // out.write("\""); // } // } // arrival time is in dtd, but no longer evaluated in code (according to not being in API). kai, jun'16 out.write(">\n"); }
public void testSeparators() { // test writing double dTime = 12*3600 + 34*60 + 56.789; assertEquals("12:34:56", Time.writeTime(dTime, ':')); assertEquals("12/34/56", Time.writeTime(dTime, '/')); assertEquals("12-34-56", Time.writeTime(dTime, '-')); // test reading double iTime = 12*3600 + 34*60 + 56; assertEquals(iTime, Time.parseTime( "12:34:56", ':'), 0.0); assertEquals(iTime, Time.parseTime( "12/34/56", '/'), 0.0); assertEquals(iTime, Time.parseTime( "12-34-56", '-'), 0.0); // test reading negative times assertEquals(-iTime, Time.parseTime( "-12:34:56", ':'), 0.0); assertEquals(-iTime, Time.parseTime( "-12/34/56", '/'), 0.0); assertEquals(-iTime, Time.parseTime( "-12-34-56", '-'), 0.0); }
@Override public final void handleActivity(Activity activity) { double startTime = activity.getStartTime(); double endTime = activity.getEndTime(); if (Time.isUndefinedTime(startTime) && !Time.isUndefinedTime(endTime)) { for (ActivityScoring activityScoringFunction : this.activityScoringFunctions) { activityScoringFunction.handleFirstActivity(activity); } } else if (!Time.isUndefinedTime(startTime) && !Time.isUndefinedTime(endTime)) { for (ActivityScoring activityScoringFunction : this.activityScoringFunctions) { activityScoringFunction.handleActivity(activity); } } else if (!Time.isUndefinedTime(startTime) && Time.isUndefinedTime(endTime)) { for (ActivityScoring activityScoringFunction : this.activityScoringFunctions) { activityScoringFunction.handleLastActivity(activity); } } else { throw new RuntimeException("Trying to score an activity without start or end time. Should not happen."); } }
private double parseTimeToDouble(String timeString) { if (timeString.contains(":")) { return Time.parseTime(timeString); } else { return Double.parseDouble(timeString); } }
private void startLeg(final Leg leg, final BufferedWriter out) throws IOException { out.write("\t\t\t<leg mode=\""); out.write(leg.getMode()); out.write("\""); if (!Time.isUndefinedTime(leg.getDepartureTime())) { out.write(" dep_time=\""); out.write(Time.writeTime(leg.getDepartureTime())); out.write("\""); } if (!Time.isUndefinedTime(leg.getTravelTime())) { out.write(" trav_time=\""); out.write(Time.writeTime(leg.getTravelTime())); out.write("\""); } // if (leg instanceof LegImpl) { // LegImpl l = (LegImpl)leg; // if (l.getDepartureTime() + l.getTravelTime() != Time.UNDEFINED_TIME) { // out.write(" arr_time=\""); // out.write(Time.writeTime(l.getDepartureTime() + l.getTravelTime())); // out.write("\""); // } // } // arrival time is in dtd, but no longer evaluated in code (according to not being in API). kai, jun'16 out.write(">\n"); this.attributesWriter.writeAttributes( "\t\t\t\t" , out , leg.getAttributes() ); }
public DynAgent(Id<Person> id, Id<Link> startLinkId, EventsManager events, DynAgentLogic agentLogic) { this.id = id; this.currentLinkId = startLinkId; this.agentLogic = agentLogic; this.events = events; // initial activity dynActivity = this.agentLogic.computeInitialActivity(this); state = Time.isUndefinedTime(dynActivity.getEndTime()) ? MobsimAgent.State.ABORT : MobsimAgent.State.ACTIVITY; }