Example usage for java.time LocalDateTime withMinute

List of usage examples for java.time LocalDateTime withMinute

Introduction

In this page you can find the example usage for java.time LocalDateTime withMinute.

Prototype

public LocalDateTime withMinute(int minute) 

Source Link

Document

Returns a copy of this LocalDateTime with the minute-of-hour altered.

Usage

From source file:Main.java

public static void main(String[] args) {
    LocalDateTime a = LocalDateTime.of(2014, 6, 30, 12, 01);

    LocalDateTime t = a.withMinute(34);

    System.out.println(t);//from  w w  w . j a  va 2s  . c o  m
}

From source file:io.mandrel.metrics.MetricsService.java

public Timeserie serie(String name) {
    Timeserie serie = metricsRepository.serie(name);

    LocalDateTime now = LocalDateTime.now();
    LocalDateTime minus4Hours = now.withMinute(0).withSecond(0).withNano(0).minusHours(4);

    LocalDateTime firstTime = CollectionUtils.isNotEmpty(serie) && serie.first() != null
            && serie.first().getTime().isBefore(minus4Hours) ? serie.first().getTime() : minus4Hours;
    LocalDateTime lastTime = now;

    Set<Data> results = LongStream.range(0, Duration.between(firstTime, lastTime).toMinutes())
            .mapToObj(minutes -> firstTime.plusMinutes(minutes)).map(time -> Data.of(time, Long.valueOf(0)))
            .collect(TreeSet::new, TreeSet::add, (left, right) -> {
                left.addAll(right);//from   w w w  . j  a va2s.c o m
            });

    Timeserie serieWithBlank = new Timeserie();
    serieWithBlank.addAll(results);
    serieWithBlank.addAll(serie);

    return serieWithBlank;
}

From source file:io.mandrel.metrics.impl.MongoMetricsRepository.java

@Scheduled(cron = "0 0 * * * *")
public void prepareNextMinutes() {
    log.debug("Preparing next metric bucket");

    // TODO Distributed lock!
    LocalDateTime now = LocalDateTime.now();
    LocalDateTime keytime = now.withMinute(0).withSecond(0).withNano(0).plusMinutes(1);

    prepareMinutes(keytime);/*from   ww  w  . j a  va  2 s .  c  o m*/
}

From source file:io.mandrel.metrics.impl.MongoMetricsRepository.java

@Override
public void sync(Map<String, Long> accumulators) {

    LocalDateTime now = LocalDateTime.now();
    LocalDateTime keytime = now.withMinute(0).withSecond(0).withNano(0);

    // {global.XXX=0, global.YYY=0, ...} to {global{XXX=O, YYY=0}, ...}
    Stream<Pair<String, Pair<String, Long>>> map = accumulators.entrySet().stream().map(e -> {
        Iterable<String> results = splitter.split(e.getKey());
        List<String> elts = Lists.newArrayList(results);
        return Pair.of(elts.get(0), Pair.of(elts.get(1), e.getValue()));
    });//from   www. j  a v a  2  s.  c  o  m
    Map<String, List<Pair<String, Long>>> byKey = map.collect(Collectors.groupingBy(e -> e.getLeft(),
            Collectors.mapping(e -> e.getRight(), Collectors.toList())));

    List<? extends WriteModel<Document>> requests = byKey.entrySet().stream().map(e -> {
        Document updates = new Document();

        e.getValue().stream().forEach(i -> {
            Iterable<String> results = splitter.split(i.getKey());
            List<String> elts = Lists.newArrayList(results);
            if (elts.size() > 1) {
                updates.put(elts.get(0) + "." + JsonBsonCodec.toBson(elts.get(1)), i.getValue());
            } else {
                updates.put(i.getKey(), i.getValue());
            }
        });

        return new UpdateOneModel<Document>(Filters.eq("_id", e.getKey()), new Document("$inc", updates),
                new UpdateOptions().upsert(true));
    }).collect(Collectors.toList());

    counters.bulkWrite(requests);

    requests = byKey.entrySet().stream().map(e -> {
        List<UpdateOneModel<Document>> tsUpdates = Lists.newArrayList();

        e.getValue().stream().forEach(i -> {
            Iterable<String> results = splitter.split(i.getKey());
            List<String> elts = Lists.newArrayList(results);

            if (elts.size() == 1 && e.getKey().equalsIgnoreCase(MetricKeys.global())) {
                tsUpdates.add(new UpdateOneModel<Document>(
                        Filters.and(Filters.eq("type", e.getKey() + MetricKeys.METRIC_DELIM + i.getKey()),
                                Filters.eq("timestamp_hour", keytime)),
                        new Document("$inc",
                                new Document("values." + Integer.toString(now.getMinute()), i.getValue())),
                        new UpdateOptions().upsert(true)));
            }
        });

        return tsUpdates;
    }).flatMap(list -> list.stream()).collect(Collectors.toList());

    timeseries.bulkWrite(requests);

}