/** * Waits for the dialogue thread to end. * * @param timeout maximum time to wait for the thread to end. A value of * Duration.ZERO (or equivalent) means to wait forever. * @throws InterruptedException if the current thread was interrupted while * waiting for the dialogue thread to terminate. */ public void join(Duration timeout) throws InterruptedException { mDialogueThread.join(timeout.getMilliseconds()); }
duration = Duration.sum(duration, Duration.year(Long.parseLong(yearsMatch))); duration = Duration.sum(duration, Duration.days(Long.parseLong(daysMatch))); duration = Duration.sum(duration, Duration.hours(Long.parseLong(hoursMatch))); duration = Duration.sum(duration, Duration.minutes(Long.parseLong(minutesMatch))); duration = Duration.sum(duration, Duration.seconds(Long.parseLong(secondsMatch))); duration = Duration.sum(duration, Duration.milliseconds(Long.parseLong(millisecondsMatch)));
public static Duration sum(Duration a, Duration b) { long millisecondsA = a.getMilliseconds(); long millisecondsB = b.getMilliseconds(); long allowedMax = Long.MAX_VALUE - millisecondsA; if (millisecondsB > allowedMax) throw new AssertionError("Time sum would overflow Long capacity."); return new Duration(millisecondsA + millisecondsB); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((mDuration == null) ? 0 : mDuration.hashCode()); return result; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Pause other = (Pause) obj; if (mDuration == null) { if (other.mDuration != null) return false; } else if (!mDuration.equals(other.mDuration)) return false; return true; } }
private static void addRecordingInfo(JsonObject resultObject, VoiceXmlInputTurn voiceXmlInputTurn, Map<String, FileUpload> files) { if (!resultObject.containsKey(RECORDING_META_DATA_PROPERTY)) return; JsonObject recordingMetaData = resultObject.getJsonObject(RECORDING_META_DATA_PROPERTY); Duration duration; if (recordingMetaData.containsKey(DURATION_PROPERTY)) { long durationInMilliseconds = JsonUtils.getLongProperty(recordingMetaData, DURATION_PROPERTY); duration = Duration.milliseconds(durationInMilliseconds); } else { duration = null; } boolean maxTime = recordingMetaData.getBoolean(MAX_TIME_PROPERTY, false); String dtmfTermChar = recordingMetaData.getString(TERM_CHAR_PROPERTY, null); FileUpload file; if (!files.containsKey(RECORDING_PARAMETER)) { file = null; } else { file = files.get(RECORDING_PARAMETER); } voiceXmlInputTurn.setRecordingInfo(new RecordingInfo(file, duration, maxTime, dtmfTermChar)); }
waitForDialoguesToTerminateThread.join(Duration.seconds(10).getMilliseconds()); if (waitForDialoguesToTerminateThread.isAlive()) { waitForDialoguesToTerminateThread.interrupt(); waitForDialoguesToTerminateThread.join(Duration.seconds(2).getMilliseconds());
public static Duration seconds(long seconds) { Assert.between(0, seconds, Long.MAX_VALUE / SECOND_IN_MILLIS); return new Duration(seconds * SECOND_IN_MILLIS); }
@Override public String toString() { if (mMilliseconds == 0) return "0 ms"; StringBuffer buffer = new StringBuffer(); long value = append(buffer, YEAR_IN_MILLIS, "year", mMilliseconds, true, true); value = append(buffer, DAY_IN_MILLIS, "day", value, true, true); value = append(buffer, HOUR_IN_MILLIS, "hour", value, true, true); value = append(buffer, MINUTE_IN_MILLIS, "minute", value, true, true); value = append(buffer, SECOND_IN_MILLIS, "second", value, true, true); append(buffer, 1, "millisecond", value, true, true); if (mMilliseconds > 1000) { buffer.append("("); buffer.append(mMilliseconds); buffer.append(" ms)"); } return buffer.toString(); }
private Duration getDuration(String key) throws ServletException { ServletConfig servletConfig = getServletConfig(); String duration = servletConfig.getInitParameter(key); if (duration == null) return null; try { return Duration.parse(duration); } catch (IllegalArgumentException exception) { throw new ServletException("Unable to parse duration for init-arg '" + key + "'", exception); } }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((mName == null) ? 0 : mName.hashCode()); result = prime * result + ((mTime == null) ? 0 : mTime.hashCode()); return result; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; FetchConfiguration other = (FetchConfiguration) obj; if (mFetchHint != other.mFetchHint) return false; if (mMaxAge == null) { if (other.mMaxAge != null) return false; } else if (!mMaxAge.equals(other.mMaxAge)) return false; if (mMaxStale == null) { if (other.mMaxStale != null) return false; } else if (!mMaxStale.equals(other.mMaxStale)) return false; if (mTimeOut == null) { if (other.mTimeOut != null) return false; } else if (!mTimeOut.equals(other.mTimeOut)) return false; return true; }
private static void addTransferStatusInfo(JsonObject resultObject, VoiceXmlInputTurn voiceXmlInputTurn) { if (!resultObject.containsKey(TRANSFER_PROPERTY)) return; JsonObject transferResultObject = resultObject.getJsonObject(TRANSFER_PROPERTY); TransferStatus transferStatus = new TransferStatus(transferResultObject.getString(TRANSFER_STATUS_PROPERTY)); long durationValue; if (transferResultObject.containsKey(TRANSFER_DURATION_PROPERTY)) { durationValue = JsonUtils.getLongProperty(transferResultObject, TRANSFER_DURATION_PROPERTY); } else { durationValue = 0; } Duration duration = Duration.milliseconds(durationValue); voiceXmlInputTurn.setTransferResult(new TransferStatusInfo(transferStatus, duration)); }
public static Duration minutes(long minutes) { Assert.between(0, minutes, Long.MAX_VALUE / MINUTE_IN_MILLIS); return new Duration(minutes * MINUTE_IN_MILLIS); }
public static void addDurationProperty(JsonObjectBuilder builder, String propertyName, Duration duration) { if (duration == null) { builder.addNull(propertyName); } else { builder.add(propertyName, duration.getMilliseconds()); } }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + (mFetchHint == null ? 0 : mFetchHint.hashCode()); result = prime * result + (mMaxAge == null ? 0 : mMaxAge.hashCode()); result = prime * result + (mMaxStale == null ? 0 : mMaxStale.hashCode()); result = prime * result + (mTimeOut == null ? 0 : mTimeOut.hashCode()); return result; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; MarkInfo other = (MarkInfo) obj; if (mName == null) { if (other.mName != null) return false; } else if (!mName.equals(other.mName)) return false; if (mTime == null) { if (other.mTime != null) return false; } else if (!mTime.equals(other.mTime)) return false; return true; }
private void addRecognitionInfo(JsonObject jsonObject, VoiceXmlInputTurn voiceXmlInputTurn) { if (!jsonObject.containsKey(RECOGNITION_PROPERTY)) return; JsonObject recognitionObject = jsonObject.getJsonObject(RECOGNITION_PROPERTY); JsonArray recognitionResultArray = recognitionObject.getJsonArray(RESULT_PROPERTY); MarkInfo markInfo = null; if (recognitionObject.containsKey(MARK_PROPERTY)) { JsonObject markObject = recognitionObject.getJsonObject(MARK_PROPERTY); long timeInMilliseconds = JsonUtils.getLongProperty(markObject, MARK_TIME_PROPERTY); markInfo = new MarkInfo(markObject.getString(MARK_NAME_PROPERTY), Duration.milliseconds(timeInMilliseconds)); } voiceXmlInputTurn.setRecognitionInfo(new RecognitionInfo(recognitionResultArray, markInfo)); }
public static Duration hours(long hours) { Assert.between(0, hours, Long.MAX_VALUE / HOUR_IN_MILLIS); return new Duration(hours * HOUR_IN_MILLIS); }
public static void addDurationProperty(Element parent, String propertyName, Duration value) { if (value != null) { addProperty(parent, propertyName, value.getMilliseconds() + MILLISECOND_UNIT_SUFFIX); } }