Example usage for java.time Duration getSeconds

List of usage examples for java.time Duration getSeconds

Introduction

In this page you can find the example usage for java.time Duration getSeconds.

Prototype

public long getSeconds() 

Source Link

Document

Gets the number of seconds in this duration.

Usage

From source file:com.publictransitanalytics.scoregenerator.output.ComparativeTimeQualifiedPointAccessibility.java

public ComparativeTimeQualifiedPointAccessibility(final PathScoreCard scoreCard,
        final PathScoreCard trialScoreCard, final Grid grid, final Center centerPoint, final LocalDateTime time,
        LocalDateTime trialTime, final Duration tripDuration, final boolean backward, final String name,
        final String trialName, final Duration inServiceTime, final Duration trialInServiceTime)
        throws InterruptedException {

    type = AccessibilityType.COMPARATIVE_TIME_QUALIFIED_POINT_ACCESSIBILITY;
    direction = backward ? Direction.INBOUND : Direction.OUTBOUND;
    mapBounds = new Bounds(grid.getBounds());
    center = new Point(centerPoint.getLogicalCenter().getPointRepresentation());
    this.time = time.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss"));
    this.trialTime = trialTime.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss"));

    this.tripDuration = DurationFormatUtils.formatDurationWords(tripDuration.toMillis(), true, true);
    final ImmutableMap.Builder<Bounds, ComparativeFullSectorReachInformation> builder = ImmutableMap.builder();

    final Set<Sector> sectors = grid.getAllSectors();

    final TaskIdentifier task = new TaskIdentifier(time, centerPoint);
    for (final Sector sector : sectors) {
        final MovementPath sectorPath = scoreCard.getBestPath(sector, task);
        final MovementPath trialSectorPath = trialScoreCard.getBestPath(sector, task);
        if (sectorPath != null || trialSectorPath != null) {
            final Bounds sectorBounds = new Bounds(sector);

            builder.put(sectorBounds, new ComparativeFullSectorReachInformation(sectorPath, trialSectorPath));
        }//from   ww  w .  ja  v  a2 s. c  om
    }
    sectorPaths = builder.build();
    totalSectors = grid.getReachableSectors().size();
    this.name = name;
    this.trialName = trialName;
    inServiceSeconds = inServiceTime.getSeconds();
    trialInServiceSeconds = trialInServiceTime.getSeconds();
}

From source file:org.graylog2.bindings.providers.JestClientProvider.java

@Inject
public JestClientProvider(@Named("elasticsearch_hosts") List<URI> elasticsearchHosts,
        @Named("elasticsearch_connect_timeout") Duration elasticsearchConnectTimeout,
        @Named("elasticsearch_socket_timeout") Duration elasticsearchSocketTimeout,
        @Named("elasticsearch_idle_timeout") Duration elasticsearchIdleTimeout,
        @Named("elasticsearch_max_total_connections") int elasticsearchMaxTotalConnections,
        @Named("elasticsearch_max_total_connections_per_route") int elasticsearchMaxTotalConnectionsPerRoute,
        @Named("elasticsearch_discovery_enabled") boolean discoveryEnabled,
        @Named("elasticsearch_discovery_filter") @Nullable String discoveryFilter,
        @Named("elasticsearch_discovery_frequency") Duration discoveryFrequency, Gson gson) {
    this.factory = new JestClientFactory();
    this.credentialsProvider = new BasicCredentialsProvider();
    final List<String> hosts = elasticsearchHosts.stream().map(hostUri -> {
        if (!Strings.isNullOrEmpty(hostUri.getUserInfo())) {
            final Iterator<String> splittedUserInfo = Splitter.on(":").split(hostUri.getUserInfo()).iterator();
            if (splittedUserInfo.hasNext()) {
                final String username = splittedUserInfo.next();
                final String password = splittedUserInfo.hasNext() ? splittedUserInfo.next() : null;
                credentialsProvider//from   w  w  w. j  av a2s  . co m
                        .setCredentials(
                                new AuthScope(hostUri.getHost(), hostUri.getPort(), AuthScope.ANY_REALM,
                                        hostUri.getScheme()),
                                new UsernamePasswordCredentials(username, password));
            }
        }
        return hostUri.toString();
    }).collect(Collectors.toList());

    final HttpClientConfig.Builder httpClientConfigBuilder = new HttpClientConfig.Builder(hosts)
            .credentialsProvider(credentialsProvider)
            .connTimeout(Math.toIntExact(elasticsearchConnectTimeout.toMillis()))
            .readTimeout(Math.toIntExact(elasticsearchSocketTimeout.toMillis()))
            .maxConnectionIdleTime(elasticsearchIdleTimeout.getSeconds(), TimeUnit.SECONDS)
            .maxTotalConnection(elasticsearchMaxTotalConnections)
            .defaultMaxTotalConnectionPerRoute(elasticsearchMaxTotalConnectionsPerRoute).multiThreaded(true)
            .discoveryEnabled(discoveryEnabled).discoveryFilter(discoveryFilter)
            .discoveryFrequency(discoveryFrequency.getSeconds(), TimeUnit.SECONDS).gson(gson);

    factory.setHttpClientConfig(httpClientConfigBuilder.build());
}

From source file:com.publictransitanalytics.scoregenerator.output.PointAccessibility.java

public PointAccessibility(final int taskCount, final PathScoreCard scoreCard, final Grid grid,
        final PointLocation centerPoint, final LocalDateTime startTime, final LocalDateTime lastTime,
        final Duration samplingInterval, final Duration tripDuration, final boolean backward,
        final Duration inServiceTime) throws InterruptedException {
    type = AccessibilityType.POINT_ACCESSIBILITY;
    direction = backward ? Direction.INBOUND : Direction.OUTBOUND;
    mapBounds = new Bounds(grid.getBounds());
    center = new Point(centerPoint);
    this.startTime = startTime.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss"));
    this.endTime = lastTime.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss"));
    this.samplingInterval = DurationFormatUtils.formatDurationWords(samplingInterval.toMillis(), true, true);

    this.tripDuration = DurationFormatUtils.formatDurationWords(tripDuration.toMillis(), true, true);

    this.taskCount = taskCount;

    final Set<Sector> sectors = grid.getAllSectors();
    totalSectors = grid.getReachableSectors().size();

    final ImmutableMap.Builder<Bounds, SectorReachInformation> informationBuilder = ImmutableMap.builder();

    for (final Sector sector : sectors) {
        final Map<LogicalTask, MovementPath> taskPaths = scoreCard.getBestPaths(sector);
        if (!taskPaths.isEmpty()) {
            final ImmutableSet.Builder<MovementPath> bestPathsBuilder = ImmutableSet.builder();
            int count = 0;
            for (final MovementPath taskPath : taskPaths.values()) {
                if (taskPath != null) {
                    bestPathsBuilder.add(taskPath);
                    count++;//from w  w  w.j a  va  2 s  .com
                }
            }
            final Bounds bounds = new Bounds(sector);
            final Set<LocalDateTime> reachTimes = scoreCard.getReachedTimes(sector);
            final SectorReachInformation information = new SectorReachInformation(bestPathsBuilder.build(),
                    count, reachTimes);
            informationBuilder.put(bounds, information);
        }
    }
    sectorPaths = informationBuilder.build();

    inServiceSeconds = inServiceTime.getSeconds();
}

From source file:org.janusgraph.graphdb.database.management.ManagementSystem.java

/**
 * Sets time-to-live for those schema types that support it
 *
 * @param type//www  .  j  a v a 2 s .  c o m
 * @param duration Note that only 'seconds' granularity is supported
 */
@Override
public void setTTL(final JanusGraphSchemaType type, final Duration duration) {
    if (!graph.getBackend().getStoreFeatures().hasCellTTL())
        throw new UnsupportedOperationException("The storage engine does not support TTL");
    if (type instanceof VertexLabelVertex) {
        Preconditions.checkArgument(((VertexLabelVertex) type).isStatic(),
                "must define vertex label as static to allow setting TTL");
    } else {
        Preconditions.checkArgument(type instanceof EdgeLabelVertex || type instanceof PropertyKeyVertex,
                "TTL is not supported for type " + type.getClass().getSimpleName());
    }
    Preconditions.checkArgument(type instanceof JanusGraphSchemaVertex);

    Integer ttlSeconds = (duration.isZero()) ? null : (int) duration.getSeconds();

    setTypeModifier(type, ModifierType.TTL, ttlSeconds);
}

From source file:com.publictransitanalytics.scoregenerator.output.ComparativeNetworkAccessibility.java

public ComparativeNetworkAccessibility(final int taskCount, final int trialTaskCount, final ScoreCard scoreCard,
        final ScoreCard trialScoreCard, final Grid grid, final Set<Sector> centerSectors,
        final LocalDateTime startTime, final LocalDateTime endTime, final LocalDateTime trialStartTime,
        final LocalDateTime trialEndTime, final Duration tripDuration, final Duration samplingInterval,
        final boolean backward, final String trialName, final Duration inServiceTime,
        final Duration trialInServiceTime) throws InterruptedException {
    type = AccessibilityType.COMPARATIVE_NETWORK_ACCESSIBILITY;

    direction = backward ? Direction.INBOUND : Direction.OUTBOUND;
    mapBounds = new Bounds(grid.getBounds());
    boundsCenter = new Point(grid.getBounds().getCenter());
    this.startTime = startTime.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss"));
    this.endTime = endTime.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss"));
    this.trialStartTime = trialStartTime.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss"));
    this.trialEndTime = trialEndTime.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss"));
    this.samplingInterval = DurationFormatUtils.formatDurationWords(samplingInterval.toMillis(), true, true);

    this.tripDuration = DurationFormatUtils.formatDurationWords(tripDuration.toMillis(), true, true);

    this.taskCount = taskCount;
    this.trialTaskCount = trialTaskCount;

    final Set<Sector> sectors = grid.getAllSectors();
    totalSectors = grid.getReachableSectors().size();

    final ImmutableMap.Builder<Bounds, CountComparison> countBuilder = ImmutableMap.builder();
    for (final Sector sector : sectors) {
        final int count = scoreCard.hasPath(sector) ? scoreCard.getReachedCount(sector) : 0;
        final int trialCount = trialScoreCard.hasPath(sector) ? trialScoreCard.getReachedCount(sector) : 0;

        if (count != 0 && trialCount != 0) {
            final Bounds bounds = new Bounds(sector);
            final CountComparison comparison = new CountComparison(count, trialCount);
            countBuilder.put(bounds, comparison);
        }/*from w w  w . j a  v  a2  s  .c  o m*/
    }

    sectorCounts = countBuilder.build();

    this.centerPoints = centerSectors.stream().map(sector -> new Point(sector.getBounds().getCenter()))
            .collect(Collectors.toSet());
    sampleCount = centerPoints.size();

    this.trialName = trialName;

    inServiceSeconds = inServiceTime.getSeconds();
    trialInServiceSeconds = trialInServiceTime.getSeconds();
}

From source file:com.publictransitanalytics.scoregenerator.output.ComparativePointAccessibility.java

public ComparativePointAccessibility(final int taskCount, final int trialTaskCount,
        final PathScoreCard scoreCard, final PathScoreCard trialScoreCard, final Grid grid,
        final PointLocation centerPoint, final LocalDateTime startTime, final LocalDateTime endTime,
        final LocalDateTime trialStartTime, final LocalDateTime trialEndTime, final Duration samplingInterval,
        final Duration tripDuration, final boolean backward, final String trialName,
        final Duration inServiceTime, final Duration trialInServiceTime) throws InterruptedException {
    type = AccessibilityType.COMPARATIVE_POINT_ACCESSIBILITY;
    direction = backward ? Direction.INBOUND : Direction.OUTBOUND;
    mapBounds = new Bounds(grid.getBounds());
    center = new Point(centerPoint);
    this.startTime = startTime.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss"));
    this.endTime = endTime.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss"));
    this.trialStartTime = trialStartTime.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss"));
    this.trialEndTime = trialEndTime.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss"));
    this.samplingInterval = DurationFormatUtils.formatDurationWords(samplingInterval.toMillis(), true, true);

    this.tripDuration = DurationFormatUtils.formatDurationWords(tripDuration.toMillis(), true, true);

    this.taskCount = taskCount;
    this.trialTaskCount = trialTaskCount;

    final Set<Sector> sectors = grid.getAllSectors();
    totalSectors = grid.getReachableSectors().size();

    final ImmutableMap.Builder<Bounds, ComparativeSectorReachInformation> informationBuilder = ImmutableMap
            .builder();//from w w w  . j a  va 2  s  .com

    for (final Sector sector : sectors) {
        final Map<LogicalTask, MovementPath> bestPaths = scoreCard.getBestPaths(sector);
        final Map<LogicalTask, MovementPath> trialBestPaths = trialScoreCard.getBestPaths(sector);
        if (!bestPaths.isEmpty() || !trialBestPaths.isEmpty()) {
            final Set<MovementPath> bestPathSet = getBestPathSet(bestPaths);
            final Set<LocalDateTime> reachTimes = scoreCard.getReachedTimes(sector);
            final Set<MovementPath> trialBestPathSet = getBestPathSet(trialBestPaths);
            final Set<LocalDateTime> trialReachTimes = trialScoreCard.getReachedTimes(sector);
            int numBestPaths = bestPathSet.size();
            int numTrialBestPaths = trialBestPathSet.size();

            final Bounds bounds = new Bounds(sector);
            final ComparativeSectorReachInformation information = new ComparativeSectorReachInformation(
                    bestPathSet, numBestPaths, reachTimes, trialBestPathSet, numTrialBestPaths,
                    trialReachTimes);
            informationBuilder.put(bounds, information);
        }
    }
    sectorPaths = informationBuilder.build();
    this.trialName = trialName;

    inServiceSeconds = inServiceTime.getSeconds();
    trialInServiceSeconds = trialInServiceTime.getSeconds();
}