Java Code Examples for java.time.Duration#toString()

The following examples show how to use java.time.Duration#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DurationJavaDescriptor.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <X> X unwrap(Duration duration, Class<X> type, WrapperOptions options) {
	if ( duration == null ) {
		return null;
	}

	if ( Duration.class.isAssignableFrom( type ) ) {
		return (X) duration;
	}

	if ( String.class.isAssignableFrom( type ) ) {
		return (X) duration.toString();
	}

	if ( Long.class.isAssignableFrom( type ) ) {
		return (X) Long.valueOf( duration.toNanos() );
	}

	throw unknownUnwrap( type );
}
 
Example 2
Source File: DiffDateExpressionProcessor.java    From vividus with Apache License 2.0 6 votes vote down vote up
@Override
public Optional<String> execute(String expression)
{
    Matcher expressionMatcher = DIFF_DATE_PATTERN.matcher(expression);
    if (expressionMatcher.find())
    {
        ZonedDateTime firstZonedDateTime = getZonedDateTime(expressionMatcher, FIRST_INPUT_DATE_GROUP,
                FIRST_INPUT_FORMAT_GROUP);
        ZonedDateTime secondZonedDateTime = getZonedDateTime(expressionMatcher, SECOND_INPUT_DATE_GROUP,
                SECOND_INPUT_FORMAT_GROUP);
        Duration duration = Duration.between(firstZonedDateTime, secondZonedDateTime);
        String durationAsString = duration.toString();
        return Optional.ofNullable(expressionMatcher.group(FORMAT_GROUP))
                       .map(String::trim)
                       .map(String::toUpperCase)
                       .map(t -> EnumUtils.getEnum(ChronoUnit.class, t))
                       .map(u -> u.between(firstZonedDateTime, secondZonedDateTime))
                       .map(Object::toString)
                       .or(() -> processNegative(duration, durationAsString));
    }
    return Optional.empty();
}
 
Example 3
Source File: WatchdogProviderHolder.java    From ldapchai with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void checkIdleTimeout()
{
    if ( wdStatus == HolderStatus.ACTIVE )
    {
        final Duration idleDuration = Duration.between( lastActivity, Instant.now() );
        if ( idleDuration.toMillis() > settings.getIdleTimeoutMS() )
        {
            final String msg = "ldap idle timeout detected ("
                    + idleDuration.toString()
                    + "), closing connection id="
                    + watchdogWrapper.getIdentifier();

            disconnectRealProvider( msg );
        }
    }
}
 
Example 4
Source File: WatchdogProviderHolder.java    From ldapchai with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void checkMaxLifetimeDuration()
{
    if ( wdStatus == HolderStatus.ACTIVE )
    {
        final Duration maxConnectionLifetime = settings.getMaxConnectionLifetime();
        if ( !allowDisconnect || maxConnectionLifetime == null )
        {
            return;
        }

        final Duration ageOfConnection = Duration.between( connectionEstablishedTime, Instant.now() );
        if ( ageOfConnection.compareTo( maxConnectionLifetime ) > 0 )
        {
            final String msg = "connection lifetime (" + ageOfConnection.toString()
                    + ") exceeded maximum configured lifetime (" + maxConnectionLifetime.toString() + ")";

            disconnectRealProvider( msg );
        }
    }
}
 
Example 5
Source File: DefaultAggregationService.java    From jetlinks-community with Apache License 2.0 5 votes vote down vote up
protected static String durationFormat(Duration duration) {
    String durationStr = duration.toString();
    if (durationStr.contains("S")) {
        return duration.toMillis() / 1000 + "s";
    } else if (!durationStr.contains("S") && durationStr.contains("M")) {
        return duration.toMinutes() + "m";
    } else if (!durationStr.contains("S") && !durationStr.contains("M")) {
        if (duration.toHours() % 24 == 0) {
            return duration.toDays() + "d";
        } else {
            return duration.toHours() + "h";
        }
    }
    throw new UnsupportedOperationException("不支持的时间周期:" + duration.toString());
}
 
Example 6
Source File: DurationWriteConverter.java    From bearchoke with Apache License 2.0 5 votes vote down vote up
@Override
public String convert(Duration duration) {
    String result = null;

    if (log.isTraceEnabled()) {
        log.trace("Converting Duration {} to string", duration.toString());
    }

    result = duration.toString();

    return result;
}
 
Example 7
Source File: BeamHelper.java    From dbeam with Apache License 2.0 5 votes vote down vote up
public static PipelineResult waitUntilDone(
    final PipelineResult result, final Duration exportTimeout) {
  // terminal state might be null, such as:
  // {{ @link org.apache.beam.runners.dataflow.DataflowPipelineJob.waitUntilFinish }}
  @Nullable
  final PipelineResult.State terminalState =
      result.waitUntilFinish(org.joda.time.Duration.millis(exportTimeout.toMillis()));
  if (terminalState == null || !terminalState.isTerminal()) {
    try {
      result.cancel();
    } catch (IOException e) {
      throw new Pipeline.PipelineExecutionException(
          new Exception(
              String.format(
                  "Job exceeded timeout of %s, but was not possible to cancel, "
                      + "finished with terminalState %s",
                  exportTimeout.toString(), terminalState),
              e));
    }
    throw new Pipeline.PipelineExecutionException(
        new Exception("Job cancelled after exceeding timeout " + exportTimeout.toString()));
  }
  if (!terminalState.equals(PipelineResult.State.DONE)) {
    throw new Pipeline.PipelineExecutionException(
        new Exception("Job finished with terminalState " + terminalState.toString()));
  }
  return result;
}
 
Example 8
Source File: FmtDuration.java    From super-csv with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @throws SuperCsvCellProcessorException if value is null or not a Duration
 */
public Object execute(final Object value, final CsvContext context) {
	validateInputNotNull(value, context);
	if( !(value instanceof Duration) ) {
		throw new SuperCsvCellProcessorException(Duration.class, value, context, this);
	}
	final Duration duration = (Duration) value;
	final String result = duration.toString();
	return next.execute(result, context);
}
 
Example 9
Source File: CircuitBreakerImpl.java    From fastbreak with Apache License 2.0 5 votes vote down vote up
protected CircuitBreakerTimeoutException generateNewCircuitBreakerTimeoutException(long timeoutNanos) {
    Duration duration = Duration.ofNanos(timeoutNanos);
    return new CircuitBreakerTimeoutException(
        id,
        "The CompletableFuture took longer than the CircuitBreaker timeout of " + duration.toString()
        + ". circuit_breaker_id=" + id
    );
}
 
Example 10
Source File: WatchdogProviderHolder.java    From ldapchai with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void checkOperationTimeout()
{
    if ( wdStatus == HolderStatus.ACTIVE )
    {
        final Duration operationDuration = Duration.between( lastActivity, Instant.now() );
        if ( operationDuration.toMillis() > settings.getOperationTimeoutMS() )
        {
            final String msg = "ldap operation timeout detected ("
                    + operationDuration.toString()
                    + "), closing questionable connection id="
                    + watchdogWrapper.getIdentifier();
            disconnectRealProvider( msg );
        }
    }
}
 
Example 11
Source File: ZkDurationSerializer.java    From emodb with Apache License 2.0 4 votes vote down vote up
@Override
public String toString(Duration duration) {
    return duration.toString();
}
 
Example 12
Source File: IntegerColumnDurationMapper.java    From jadira with Apache License 2.0 4 votes vote down vote up
@Override
public String toNonNullString(Duration value) {
    return value.toString();
}
 
Example 13
Source File: DurationTypeAdapter.java    From javers with Apache License 2.0 4 votes vote down vote up
@Override
public String serialize(Duration sourceValue) {
    return sourceValue.toString();
}
 
Example 14
Source File: DurationXmlAdapter.java    From threeten-jaxb with Apache License 2.0 4 votes vote down vote up
@Override
public String marshal(Duration value) {
    return value != null ? value.toString() : null;
}
 
Example 15
Source File: BigDecimalColumnDurationMapper.java    From jadira with Apache License 2.0 4 votes vote down vote up
@Override
public String toNonNullString(Duration value) {
    return value.toString();
}
 
Example 16
Source File: LongColumnDurationMapper.java    From jadira with Apache License 2.0 4 votes vote down vote up
@Override
public String toNonNullString(Duration value) {
    return value.toString();
}
 
Example 17
Source File: DurationFormatter.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String print(Duration object, Locale locale) {
	return object.toString();
}
 
Example 18
Source File: CucumberPerf.java    From cucumber-performance with MIT License 4 votes vote down vote up
/**
 * @return Duration of of Cucumber Perf execution.
 */
public String getRunTime() {
	Duration d = Duration.between(start, end);
	return d.toString();
}
 
Example 19
Source File: BigIntegerColumnDurationMapper.java    From jadira with Apache License 2.0 4 votes vote down vote up
@Override
public String toNonNullString(Duration value) {
    return value.toString();
}
 
Example 20
Source File: DurationFormatter.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public String print(Duration object, Locale locale) {
	return object.toString();
}