Example usage for java.time LocalDateTime getMinute

List of usage examples for java.time LocalDateTime getMinute

Introduction

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

Prototype

public int getMinute() 

Source Link

Document

Gets the minute-of-hour field.

Usage

From source file:com.objy.se.ClassAccessor.java

public Object getCorrectValue(String strValue, LogicalType logicalType) {
    Object retValue = null;/*w w w .  ja  v  a  2 s.c o m*/
    switch (logicalType) {
    case INTEGER: {
        long attrValue = 0;
        try {
            if (!strValue.equals("")) {
                attrValue = Long.parseLong(strValue);
            }
        } catch (NumberFormatException nfEx) {
            //        System.out.println("... entry: " + entry.getValue() + " for raw: " + entry.getKey());
            nfEx.printStackTrace();
            throw nfEx;
        }
        retValue = Long.valueOf(attrValue);
    }
        break;
    case REAL: {
        double attrValue = 0;
        try {
            if (!strValue.equals("")) {
                attrValue = Double.parseDouble(strValue);
            }
        } catch (NumberFormatException nfEx) {
            //        System.out.println("... entry: " + entry.getValue() + " for raw: " + entry.getKey());
            nfEx.printStackTrace();
            throw nfEx;
        }
        retValue = Double.valueOf(attrValue);
    }
        break;
    case STRING:
        retValue = strValue;
        break;
    case BOOLEAN: {
        if (strValue.equalsIgnoreCase("TRUE") || strValue.equals("1")) {
            retValue = Boolean.valueOf(true);
        } else if (strValue.equalsIgnoreCase("FALSE") || strValue.equals("0")) {
            retValue = Boolean.valueOf(false);
        } else {
            LOG.error("Expected Boolean value but got: {}", strValue);
            throw new IllegalStateException("Possible invalid configuration... check mapper vs. schema"
                    + "... or check records for invalid values");
        }
    }
        break;

    case CHARACTER: {
        if (strValue.length() == 1) {
            retValue = Character.valueOf(strValue.charAt(0));
        } else { /* not a char value... report that */
            LOG.error("Expected Character value but got: {}", strValue);
            throw new IllegalStateException("Possible invalid configuration... check mapper vs. schema"
                    + "... or check records for invalid values");
        }
    }
        break;
    case DATE: {
        try {
            LocalDate ldate = LocalDate.parse(strValue, dateFormatter);
            //            System.out.println("... ... year: " + ldate.getYear() + " - month:" + ldate.getMonthValue());
            retValue = new com.objy.db.Date(ldate.getYear(), ldate.getMonthValue(), ldate.getDayOfMonth());
        } catch (DateTimeParseException ex) {
            LOG.error(ex.toString());
            throw new IllegalStateException("Possible invalid configuration... check mapper vs. schema"
                    + "... or check records for invalid values");
        }
    }
        break;
    case DATE_TIME: {
        try {
            //            System.out.println(".... formatter: " + mapper.getDateTimeFormat());
            LocalDateTime ldt = LocalDateTime.parse(strValue, dateTimeFormatter);
            //            System.out.println("... ... year: " + ldt.getYear() + 
            //                    " - month:" + ldt.getMonthValue() + " - day: " +
            //                    ldt.getDayOfMonth() + " - hour: " + ldt.getHour() +
            //                    " - min: " + ldt.getMinute() + " - sec: " + 
            //                    ldt.getSecond() + " - nsec: " + ldt.getNano() );
            //retValue = new com.objy.db.DateTime(date.getTime(), TimeKind.LOCAL);
            retValue = new com.objy.db.DateTime(ldt.getYear(), ldt.getMonthValue(), ldt.getDayOfMonth(),
                    ldt.getHour(), ldt.getMinute(), ldt.getSecond(), ldt.getNano());
        } catch (DateTimeParseException ex) {
            LOG.error(ex.toString());
            throw new IllegalStateException("Possible invalid configuration... check mapper vs. schema"
                    + "... or check records for invalid values");
        }
    }
        break;
    case TIME: {
        try {
            //            System.out.println(".... formatter: " + mapper.getTimeFormat());
            LocalDateTime ltime = LocalDateTime.parse(strValue, dateFormatter);
            //            System.out.println("... ... hour: " + ltime.getHour() +
            //                    " - min: " + ltime.getMinute() + " - sec: " + 
            //                    ltime.getSecond() + " - nsec: " + ltime.getNano() );
            //retValue = new com.objy.db.DateTime(date.getTime(), TimeKind.LOCAL);
            retValue = new com.objy.db.Time(ltime.getHour(), ltime.getMinute(), ltime.getSecond(),
                    ltime.getNano());
        } catch (DateTimeParseException ex) {
            LOG.error(ex.toString());
            throw new IllegalStateException("Possible invalid configuration... check mapper vs. schema"
                    + "... or check records for invalid values");
        }
    }
    default: {
        throw new UnsupportedOperationException("LogicalType: " + logicalType + " is not supported!!!");
    }
    }
    return retValue;
}

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()));
    });//  ww  w.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);

}

From source file:nl.utwente.ewi.caes.tactiletriana.simulation.devices.UncontrollableLoad.java

@Override
public void tick(Simulation simulation, boolean connected) {
    super.tick(simulation, connected);
    LocalDateTime t = simulation.getCurrentTime();
    int minuteOfYear = t.getDayOfYear() * 24 * 60 + t.getHour() * 60 + t.getMinute();
    setCurrentConsumption(profile[profileNumber][minuteOfYear]);
}

From source file:no.imr.stox.functions.acoustic.PgNapesIO.java

public static void export2(String cruise, String country, String callSignal, String path, String fileName,
        List<DistanceBO> distances, Double groupThickness, Integer freqFilter, String specFilter,
        boolean withZeros) {
    Set<Integer> freqs = distances.stream().flatMap(dist -> dist.getFrequencies().stream())
            .map(FrequencyBO::getFreq).collect(Collectors.toSet());
    if (freqFilter == null && freqs.size() == 1) {
        freqFilter = freqs.iterator().next();
    }//from www .j a v  a  2s .com

    if (freqFilter == null) {
        System.out.println("Multiple frequencies, specify frequency filter as parameter");
        return;
    }
    Integer freqFilterF = freqFilter; // ef.final
    List<String> acList = distances.parallelStream().flatMap(dist -> dist.getFrequencies().stream())
            .filter(fr -> freqFilterF.equals(fr.getFreq())).map(f -> {
                DistanceBO d = f.getDistanceBO();
                LocalDateTime sdt = LocalDateTime.ofInstant(d.getStart_time().toInstant(), ZoneOffset.UTC);
                Double intDist = d.getIntegrator_dist();
                String month = StringUtils.leftPad(sdt.getMonthValue() + "", 2, "0");
                String day = StringUtils.leftPad(sdt.getDayOfMonth() + "", 2, "0");
                String hour = StringUtils.leftPad(sdt.getHour() + "", 2, "0");
                String minute = StringUtils.leftPad(sdt.getMinute() + "", 2, "0");
                String log = Conversion.formatDoubletoDecimalString(d.getLog_start(), "0.0");
                String acLat = Conversion.formatDoubletoDecimalString(d.getLat_start(), "0.000");
                String acLon = Conversion.formatDoubletoDecimalString(d.getLon_start(), "0.000");
                return Stream
                        .of(d.getNation(), d.getPlatform(), d.getCruise(), log, sdt.getYear(), month, day, hour,
                                minute, acLat, acLon, intDist, f.getFreq(), f.getThreshold())
                        .map(o -> o == null ? "" : o.toString()).collect(Collectors.joining("\t")) + "\t";
            }).collect(Collectors.toList());
    String fil1 = path + "/" + fileName + ".txt";
    acList.add(0, Stream.of("Country", "Vessel", "Cruise", "Log", "Year", "Month", "Day", "Hour", "Min",
            "AcLat", "AcLon", "Logint", "Frequency", "Sv_threshold").collect(Collectors.joining("\t")));
    try {
        Files.write(Paths.get(fil1), acList, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
    } catch (IOException ex) {
        Logger.getLogger(PgNapesIO.class.getName()).log(Level.SEVERE, null, ex);
    }
    acList.clear();
    // Acoustic values
    distances.stream().filter(d -> d.getPel_ch_thickness() != null)
            .flatMap(dist -> dist.getFrequencies().stream()).filter(fr -> freqFilterF.equals(fr.getFreq()))
            .forEachOrdered(f -> {
                try {
                    Double groupThicknessF = Math.max(f.getDistanceBO().getPel_ch_thickness(), groupThickness);
                    Map<String, Map<Integer, Double>> pivot = f.getSa().stream()
                            .filter(s -> s.getCh_type().equals("P")).map(s -> new SAGroup(s, groupThicknessF))
                            .filter(s -> s.getSpecies() != null
                                    && (specFilter == null || specFilter.equals(s.getSpecies())))
                            // create pivot table: species (dim1) -> depth interval index (dim2) -> sum sa (group aggregator)
                            .collect(Collectors.groupingBy(SAGroup::getSpecies, Collectors.groupingBy(
                                    SAGroup::getDepthGroupIdx, Collectors.summingDouble(SAGroup::sa))));
                    if (pivot.isEmpty() && specFilter != null && withZeros) {
                        pivot.put(specFilter, new HashMap<>());
                    }
                    Integer maxGroupIdx = pivot.entrySet().stream().flatMap(e -> e.getValue().keySet().stream())
                            .max(Integer::compare).orElse(null);
                    if (maxGroupIdx == null) {
                        return;
                    }
                    acList.addAll(pivot.entrySet().stream().sorted(Comparator.comparing(Map.Entry::getKey))
                            .flatMap(e -> {
                                return IntStream.range(0, maxGroupIdx + 1).boxed().map(groupIdx -> {
                                    Double chUpDepth = groupIdx * groupThicknessF;
                                    Double chLowDepth = (groupIdx + 1) * groupThicknessF;
                                    Double sa = e.getValue().get(groupIdx);
                                    if (sa == null) {
                                        sa = 0d;
                                    }
                                    String res = null;
                                    if (withZeros || sa > 0d) {
                                        DistanceBO d = f.getDistanceBO();
                                        String log = Conversion.formatDoubletoDecimalString(d.getLog_start(),
                                                "0.0");
                                        LocalDateTime sdt = LocalDateTime
                                                .ofInstant(d.getStart_time().toInstant(), ZoneOffset.UTC);
                                        String month = StringUtils.leftPad(sdt.getMonthValue() + "", 2, "0");
                                        String day = StringUtils.leftPad(sdt.getDayOfMonth() + "", 2, "0");
                                        //String sas = String.format(Locale.UK, "%11.5f", sa);
                                        res = Stream
                                                .of(d.getNation(), d.getPlatform(), d.getCruise(), log,
                                                        sdt.getYear(), month, day, e.getKey(), chUpDepth,
                                                        chLowDepth, sa)
                                                .map(o -> o == null ? "" : o.toString())
                                                .collect(Collectors.joining("\t"));
                                    }
                                    return res;
                                }).filter(s -> s != null);
                            }).collect(Collectors.toList()));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            });

    String fil2 = path + "/" + fileName + "Values.txt";
    acList.add(0, Stream.of("Country", "Vessel", "Cruise", "Log", "Year", "Month", "Day", "Species",
            "ChUppDepth", "ChLowDepth", "SA").collect(Collectors.joining("\t")));
    try {
        Files.write(Paths.get(fil2), acList, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
    } catch (IOException ex) {
        Logger.getLogger(PgNapesIO.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:org.apache.tez.dag.history.logging.proto.DagManifesFileScanner.java

private boolean loadMore() throws IOException {
    LocalDateTime now = manifestLogger.getNow();
    LocalDate today = now.toLocalDate();
    String todayDir = manifestLogger.getDirForDate(today);
    loadNewFiles(todayDir);//  w  ww. j av a 2  s .c om
    while (newFiles.isEmpty()) {
        if (now.getHour() * 3600 + now.getMinute() * 60 + now.getSecond() < syncTime) {
            // We are in the delay window for today, do not advance date if we are moving from
            // yesterday.
            if (scanDir.equals(manifestLogger.getDirForDate(today.minusDays(1)))) {
                return false;
            }
        }
        String nextDir = manifestLogger.getNextDirectory(scanDir);
        if (nextDir == null) {
            return false;
        }
        scanDir = nextDir;
        offsets = new HashMap<>();
        retryCount = new HashMap<>();
        loadNewFiles(todayDir);
    }
    return true;
}

From source file:org.codice.ddf.admin.insecure.defaults.service.DefaultUsersDeletionScheduler.java

private String cronCalculator(Instant firstInstall) {
    Instant threeDayTimestamp = firstInstall.plus(Duration.ofDays(3).minus(Duration.ofMinutes(30)));
    LocalDateTime localDateTime = LocalDateTime.ofInstant(threeDayTimestamp, ZoneId.systemDefault());

    return String.format("%d+%d+%d+%d+%d+?+%d", localDateTime.getSecond(), localDateTime.getMinute(),
            localDateTime.getHour(), localDateTime.getDayOfMonth(), localDateTime.getMonthValue(),
            localDateTime.getYear());//from   w  ww  . j ava2 s .  c  o m
}

From source file:org.eclipse.smarthome.core.scheduler.CronHelper.java

/**
 * Returns CRON expression from the provided {@link LocalDateTime} instance
 *
 * @param localDateTime the {@link LocalDateTime} instance
 * @return the CRON expression/*  w ww.j  a  v a2  s.c  om*/
 * @throws NullPointerException
 *             if {@code localDateTime} is null
 */
public static String createCronFromTemporal(LocalDateTime localDateTime) {
    requireNonNull(localDateTime, "Temporal instance cannot be null");
    int minute = localDateTime.getMinute();
    int hour = localDateTime.getHour();
    int day = localDateTime.getDayOfMonth();
    int month = localDateTime.getMonth().getValue();
    int year = localDateTime.getYear();

    StringBuilder builder = new StringBuilder();
    builder.append(SECONDS).append(SPACE).append(minute).append(SPACE).append(hour).append(SPACE).append(day)
            .append(SPACE).append(month).append(SPACE).append(DAYS_OF_WEEK).append(SPACE).append(year);
    return builder.toString();
}

From source file:org.eclipse.smarthome.core.scheduler.CronHelper.java

/**
 * Returns CRON expression that denotes the repetition every provided
 * seconds//from  ww  w.  java2 s. c  om
 *
 * @param totalSecs the seconds (cannot be zero or negative or more than 86400)
 * @return the CRON expression
 * @throws IllegalArgumentException
 *             if {@code totalSecs} is zero or negative or more than 86400
 */
public static String createCronForRepeatEverySeconds(int totalSecs) {
    if (totalSecs < 0 && totalSecs <= 86400) {
        throw new IllegalArgumentException("Seconds cannot be zero or negative or more than 86400");
    }

    StringBuilder builder = new StringBuilder();
    if (totalSecs < 60) {
        builder.append(ANY).append(EACH).append(totalSecs).append(SPACE).append(ANY).append(SPACE).append(ANY)
                .append(SPACE).append(ANY).append(SPACE).append(ANY).append(SPACE).append(DAYS_OF_WEEK)
                .append(SPACE).append(ANY);
        return builder.toString();
    }
    if (totalSecs >= 60 && totalSecs < 60 * 60) {
        int secs = totalSecs % 60;
        int mins = totalSecs / 60;

        builder.append(secs).append(SPACE).append(ANY).append(EACH).append(mins).append(SPACE).append(ANY)
                .append(SPACE).append(ANY).append(SPACE).append(ANY).append(SPACE).append(DAYS_OF_WEEK)
                .append(SPACE).append(ANY);
        return builder.toString();
    }
    if (totalSecs >= 60 * 60 && totalSecs < 60 * 60 * 24) {
        int secs = totalSecs % 60;
        int mins = totalSecs % 3600 / 60;
        int hours = totalSecs / 3600;

        builder.append(secs).append(SPACE).append(mins).append(SPACE).append(ANY).append(EACH).append(hours)
                .append(SPACE).append(ANY).append(SPACE).append(ANY).append(SPACE).append(DAYS_OF_WEEK)
                .append(SPACE).append(ANY);
        return builder.toString();
    }
    if (totalSecs == 60 * 60 * 24) {
        LocalDateTime now = LocalDateTime.now();
        int minute = now.getMinute();
        int hour = now.getHour();

        builder.append("0").append(SPACE).append(minute).append(SPACE).append(hour).append(SPACE).append(ANY)
                .append(SPACE).append(ANY).append(SPACE).append(DAYS_OF_WEEK).append(SPACE).append(ANY);
        return builder.toString();
    }
    return EMPTY;
}