Example usage for java.time LocalDateTime getYear

List of usage examples for java.time LocalDateTime getYear

Introduction

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

Prototype

public int getYear() 

Source Link

Document

Gets the year field.

Usage

From source file:Main.java

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

    System.out.println(a.getYear());
}

From source file:net.ceos.project.poi.annotated.bean.MultiTypeObjectBuilder.java

/**
 * Validate the MultiTypeObject based on the object build with the method
 * 'buildMultiTypeObject'/*ww w.j a  va  2 s  .  c o m*/
 * 
 * @param toValidate
 *            the object to validate
 */
public static void validateMultiTypeObject(MultiTypeObject toValidate) {
    MultiTypeObject base = buildMultiTypeObject();

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());

    Calendar calendarUnmarshal = Calendar.getInstance();
    calendarUnmarshal.setTime(toValidate.getDateAttribute());
    assertEquals(calendar.get(Calendar.YEAR), calendarUnmarshal.get(Calendar.YEAR));
    assertEquals(calendar.get(Calendar.MONTH), calendarUnmarshal.get(Calendar.MONTH));
    assertEquals(calendar.get(Calendar.DAY_OF_MONTH), calendarUnmarshal.get(Calendar.DAY_OF_MONTH));
    LocalDate localDate = LocalDate.now();
    assertEquals(localDate.getDayOfMonth(), toValidate.getLocalDateAttribute().getDayOfMonth());
    assertEquals(localDate.getMonth(), toValidate.getLocalDateAttribute().getMonth());
    assertEquals(localDate.getYear(), toValidate.getLocalDateAttribute().getYear());
    LocalDateTime localDateTime = LocalDateTime.now();
    assertEquals(localDateTime.getDayOfMonth(), toValidate.getLocalDateTimeAttribute().getDayOfMonth());
    assertEquals(localDateTime.getMonth(), toValidate.getLocalDateTimeAttribute().getMonth());
    assertEquals(localDateTime.getYear(), toValidate.getLocalDateTimeAttribute().getYear());
    assertEquals(localDateTime.getHour(), toValidate.getLocalDateTimeAttribute().getHour());

    /* it is possible to have an error below due the time of execution of the test */
    assertEquals(localDateTime.getMinute(), toValidate.getLocalDateTimeAttribute().getMinute());

    assertEquals(base.getStringAttribute(), toValidate.getStringAttribute());
    assertEquals(base.getIntegerAttribute(), toValidate.getIntegerAttribute());
    assertEquals(base.getDoubleAttribute(), toValidate.getDoubleAttribute());
    assertEquals(base.getLongAttribute(), toValidate.getLongAttribute());
    assertEquals(base.getBooleanAttribute(), toValidate.getBooleanAttribute());
    assertEquals(base.getJob().getJobCode(), toValidate.getJob().getJobCode());
    assertEquals(base.getJob().getJobFamily(), toValidate.getJob().getJobFamily());
    assertEquals(base.getJob().getJobName(), toValidate.getJob().getJobName());
    assertEquals(base.getIntegerPrimitiveAttribute(), toValidate.getIntegerPrimitiveAttribute());
    assertEquals(base.getDoublePrimitiveAttribute(), toValidate.getDoublePrimitiveAttribute());
    assertEquals(base.getLongPrimitiveAttribute(), toValidate.getLongPrimitiveAttribute());
    assertEquals(base.isBooleanPrimitiveAttribute(), toValidate.isBooleanPrimitiveAttribute());
    assertEquals(base.getAddressInfo().getAddress(), toValidate.getAddressInfo().getAddress());
    assertEquals(base.getAddressInfo().getNumber(), toValidate.getAddressInfo().getNumber());
    assertEquals(base.getAddressInfo().getCity(), toValidate.getAddressInfo().getCity());
    assertEquals(base.getAddressInfo().getCityCode(), toValidate.getAddressInfo().getCityCode());
    assertEquals(base.getAddressInfo().getCountry(), toValidate.getAddressInfo().getCountry());
    assertEquals(base.getFloatAttribute(), toValidate.getFloatAttribute());
    assertEquals(base.getFloatPrimitiveAttribute(), toValidate.getFloatPrimitiveAttribute());
    assertEquals(base.getUnitFamily(), toValidate.getUnitFamily());
    assertEquals(base.getBigDecimalAttribute(), toValidate.getBigDecimalAttribute());
    assertEquals(base.getShortAttribute(), toValidate.getShortAttribute());
    assertEquals(base.getShortPrimitiveAttribute(), toValidate.getShortPrimitiveAttribute());
    // TODO add new validation below
}

From source file:reactivity.SseController.java

/**
 * <p>/* w w  w .  j a  va  2s  .c  om*/
 * Retrieves and pushes the timeseries associated to the given artifact.
 * </p>
 *
 * @param a the artifact associated to timeseries
 */
private void timeseries(final Artifact a) {

    // Compute the key
    final LocalDateTime i = LocalDateTime.ofInstant(Instant.ofEpochMilli(a.getTimestamp()),
            ZoneId.systemDefault());
    final Object[] key = new Object[] { a.getGroup().getType() + "/" + a.getGroup().getName(), i.getYear(),
            i.getMonthValue(), i.getDayOfMonth() };

    repository.color(key).subscribe((item) -> replayProcessor.onNext(sse(Artifact.class.cast(item))));
}

From source file:edu.unibonn.plotting.TimeSeriesPlotter_Sensors.java

private XYDataset createDataset(ArrayList<Sensor> sensors) {
    final TimeSeriesCollection dataset = new TimeSeriesCollection();

    for (int i = 0; i < sensors.size(); i++) {
        Sensor current_sensor = sensors.get(i);

        final TimeSeries s1 = new TimeSeries("Sensor " + i, Hour.class);

        for (int j = 0; j < current_sensor.getDimensions(); j++) {
            LocalDateTime current_record_time = current_sensor.getInitial_record_time().plusHours(j);
            s1.add(new Hour(current_record_time.getHour(), current_record_time.getDayOfMonth(),
                    current_record_time.getMonthValue(), current_record_time.getYear()),
                    current_sensor.getMeasurement(j));
        }/*  ww  w  .  j  a v  a 2s.c  om*/

        dataset.addSeries(s1);
    }

    dataset.setDomainIsPointsInTime(true);

    return dataset;
}

From source file:edu.unibonn.plotting.TimeSeriesPlotter_Sensors.java

private XYDataset createDataset(ArrayList<Cluster_KMeans> clusters, LocalDateTime from) {
    final TimeSeriesCollection dataset = new TimeSeriesCollection();

    for (int i = 0; i < clusters.size(); i++) {
        Cluster_KMeans current_cluster = clusters.get(i);
        ArrayList<Sensor> member_time_series = current_cluster.getMembership();

        for (Iterator iterator = member_time_series.iterator(); iterator.hasNext();) {
            final TimeSeries s1 = new TimeSeries("Cluster_" + current_cluster.getCluster_id(), Hour.class);

            Sensor current_series = (Sensor) iterator.next();

            for (int j = 0; j < current_series.getDimensions(); j++) {
                LocalDateTime current_record_time = current_series.getInitial_record_time().plusHours(j);
                s1.add(new Hour(current_record_time.getHour(), current_record_time.getDayOfMonth(),
                        current_record_time.getMonthValue(), current_record_time.getYear()),
                        current_series.getMeasurement(j));
            }//w  ww. j  a  v a  2s.  c om

            dataset.addSeries(s1);
        }
    }

    dataset.setDomainIsPointsInTime(true);

    return dataset;
}

From source file:net.atomique.ksar.graph.Graph.java

private Second convertLocalDateTimeToSecond(LocalDateTime ldt) {

    int day = ldt.getDayOfMonth();
    int month = ldt.getMonthValue();
    int year = ldt.getYear();
    int hour = ldt.getHour();
    int minute = ldt.getMinute();
    int second = ldt.getSecond();

    return new Second(second, minute, hour, day, month, year);
}

From source file:net.atomique.ksar.graph.Graph.java

public int parse_line(LocalDateTime ldt, String s) {

    Second now = new Second(ldt.getSecond(), ldt.getMinute(), ldt.getHour(), ldt.getDayOfMonth(),
            ldt.getMonthValue(), ldt.getYear());

    parse_line(now, s);/*  ww  w. ja  va 2  s  . c o  m*/
    return 0;
}

From source file:edu.unibonn.kmeans.mapreduce.plotting.TimeSeriesPlotter_KMeans.java

private XYDataset createDataset(ArrayList<Sensor> sensors) {
    final TimeSeriesCollection dataset = new TimeSeriesCollection();

    for (int i = 0; i < sensors.size(); i++)
    //for (int i = 0; i < 100; i++)
    {//from w w  w .j  a v a2 s  . c  o  m
        Sensor current_sensor = sensors.get(i);
        ArrayList<Measurement> current_measurements = current_sensor.getMeasurements();

        final TimeSeries s1 = new TimeSeries("Sensor " + i, Hour.class);

        for (int j = 0; j < current_measurements.size(); j++) {
            Measurement current_measurement = current_measurements.get(j);

            LocalDateTime current_time = current_measurement.getRecord_time();

            s1.add(new Hour(current_time.getHour(), current_time.getDayOfMonth(), current_time.getMonthValue(),
                    current_time.getYear()), current_measurement.getErlang());
        }

        dataset.addSeries(s1);
    }

    dataset.setDomainIsPointsInTime(true);

    return dataset;
}

From source file:msi.gama.util.GamaDate.java

public IList<?> listValue(final IScope scope, final IType<?> ct) {
    final LocalDateTime ld = LocalDateTime.from(internal);
    return GamaListFactory.create(scope, ct, ld.getYear(), ld.getMonthValue(), ld.getDayOfWeek().getValue(),
            ld.getHour(), ld.getMinute(), ld.getSecond());
}

From source file:de.steilerdev.myVerein.server.controller.admin.EventManagementController.java

/**
 * Returns all events, that are taking place on a specified date. The date parameter needs to be formatted according to the following pattern: YYYY/MM/DD. This function is invoked by GETting the URI /api/admin/event/date
 * @param date The selected date, correctly formatted (YYYY/MM/DD)
 * @return An HTTP response with a status code. If the function succeeds, a list of events is returned, otherwise an error code is returned.
 */// w  w  w  . ja  v a2 s.c o  m
@RequestMapping(value = "date", produces = "application/json", method = RequestMethod.GET)
public ResponseEntity<List<Event>> getEventsOfDate(@RequestParam String date, @CurrentUser User currentUser) {
    logger.trace("[" + currentUser + "] Getting events of date " + date);
    LocalDateTime startOfDay, endOfDay, startOfMonth, endOfMonth;
    ArrayList<Event> eventsOfDay = new ArrayList<>();
    try {
        // Get start of day and start of next day
        startOfDay = LocalDate.parse(date, DateTimeFormatter.ISO_LOCAL_DATE).atStartOfDay();
        endOfDay = startOfDay.plusDays(1);

        startOfMonth = LocalDate.of(startOfDay.getYear(), startOfDay.getMonth(), 1).atStartOfDay();
        endOfMonth = startOfMonth.plusMonths(1);
        logger.debug("[" + currentUser + "] Converted to date object: " + startOfDay.toString());
    } catch (DateTimeParseException e) {
        logger.warn("[" + currentUser + "] Unable to parse date: " + date + ": " + e.toString());
        return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
    }

    logger.debug("Getting all single day events...");
    eventsOfDay.addAll(eventRepository.findAllByStartDateTimeBetweenAndMultiDate(startOfDay, endOfDay, false));
    logger.debug("All single day events retrieved, got " + eventsOfDay.size() + " events so far");

    logger.debug("Getting all multi day events...");
    //Collecting all multi date events, that either start or end within the selected month (which means that events that are spanning over several months are not collected)
    eventsOfDay.addAll(Stream.concat(
            eventRepository.findAllByStartDateTimeBetweenAndMultiDate(startOfMonth, endOfMonth, true).stream(), //All multi date events starting within the month
            eventRepository.findAllByEndDateTimeBetweenAndMultiDate(startOfMonth, endOfMonth, true).stream()) //All multi date events ending within the month
            .distinct() //Removing all duplicated events
            .parallel()
            .filter(event -> event.getStartDate().isEqual(startOfDay.toLocalDate())
                    || event.getEndDate().isEqual(startOfDay.toLocalDate())
                    || (event.getEndDate().isAfter(endOfDay.toLocalDate())
                            && event.getStartDate().isBefore(startOfDay.toLocalDate()))) //Filter all multi date events that do not span over the date
            .collect(Collectors.toList()));
    logger.debug("All multi day events gathered, got " + eventsOfDay.size() + " events so far");

    if (eventsOfDay.isEmpty()) {
        logger.warn("[" + currentUser + "] The events list of " + date + " is empty");
        return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
    } else {
        eventsOfDay.replaceAll(Event::getSendingObjectOnlyNameTimeId);
        logger.debug("[" + currentUser + "] Returning " + eventsOfDay.size() + " events for " + date);
        return new ResponseEntity<>(eventsOfDay, HttpStatus.OK);
    }
}