Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: java 8 syntax update #179

Merged
merged 4 commits into from
Feb 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,6 @@
</dependency>

<!-- The third-party dependencies this application has -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.10.9</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package org.eclipse.cargotracker.application;

import java.util.Date;
import java.time.LocalDate;
import java.util.List;

import org.eclipse.cargotracker.domain.model.cargo.Itinerary;
import org.eclipse.cargotracker.domain.model.cargo.TrackingId;
import org.eclipse.cargotracker.domain.model.location.UnLocode;
Expand All @@ -12,7 +11,7 @@
public interface BookingService {

/** Registers a new cargo in the tracking system, not yet routed. */
TrackingId bookNewCargo(UnLocode origin, UnLocode destination, Date arrivalDeadline);
TrackingId bookNewCargo(UnLocode origin, UnLocode destination, LocalDate arrivalDeadline);

/**
* Requests a list of itineraries describing possible routes for this cargo.
Expand All @@ -26,5 +25,5 @@ public interface BookingService {

void changeDestination(TrackingId trackingId, UnLocode unLocode);

void changeDeadline(TrackingId trackingId, Date deadline);
void changeDeadline(TrackingId trackingId, LocalDate deadline);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.eclipse.cargotracker.application;

import javax.validation.constraints.NotNull;

import org.eclipse.cargotracker.domain.model.cargo.TrackingId;

public interface CargoInspectionService {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.eclipse.cargotracker.application;

import java.util.Date;

import java.time.LocalDateTime;
import org.eclipse.cargotracker.domain.model.cargo.TrackingId;
import org.eclipse.cargotracker.domain.model.handling.CannotCreateHandlingEventException;
import org.eclipse.cargotracker.domain.model.handling.HandlingEvent;
Expand All @@ -15,7 +14,7 @@ public interface HandlingEventService {
* been handled.
*/
void registerHandlingEvent(
Date completionTime,
LocalDateTime completionTime,
TrackingId trackingId,
VoyageNumber voyageNumber,
UnLocode unLocode,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package org.eclipse.cargotracker.application.internal;

import java.time.LocalDate;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.ejb.Stateless;
import javax.inject.Inject;

import org.eclipse.cargotracker.application.BookingService;
import org.eclipse.cargotracker.domain.model.cargo.Cargo;
import org.eclipse.cargotracker.domain.model.cargo.CargoRepository;
Expand All @@ -31,7 +29,7 @@ public class DefaultBookingService implements BookingService {

@Override
public TrackingId bookNewCargo(
UnLocode originUnLocode, UnLocode destinationUnLocode, Date arrivalDeadline) {
UnLocode originUnLocode, UnLocode destinationUnLocode, LocalDate arrivalDeadline) {
TrackingId trackingId = cargoRepository.nextTrackingId();
Location origin = locationRepository.find(originUnLocode);
Location destination = locationRepository.find(destinationUnLocode);
Expand Down Expand Up @@ -91,7 +89,7 @@ public void changeDestination(TrackingId trackingId, UnLocode unLocode) {
}

@Override
public void changeDeadline(TrackingId trackingId, Date newDeadline) {
public void changeDeadline(TrackingId trackingId, LocalDate newDeadline) {
Cargo cargo = cargoRepository.find(trackingId);

RouteSpecification routeSpecification =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

import java.util.logging.Level;
import java.util.logging.Logger;

import javax.ejb.Stateless;
import javax.enterprise.event.Event;
import javax.inject.Inject;

import org.eclipse.cargotracker.application.ApplicationEvents;
import org.eclipse.cargotracker.application.CargoInspectionService;
import org.eclipse.cargotracker.domain.model.cargo.Cargo;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package org.eclipse.cargotracker.application.internal;

import java.util.Date;
import java.time.LocalDateTime;
import java.util.logging.Logger;

import javax.ejb.Stateless;
import javax.inject.Inject;

import org.eclipse.cargotracker.application.ApplicationEvents;
import org.eclipse.cargotracker.application.HandlingEventService;
import org.eclipse.cargotracker.domain.model.cargo.TrackingId;
Expand All @@ -27,13 +25,13 @@ public class DefaultHandlingEventService implements HandlingEventService {

@Override
public void registerHandlingEvent(
Date completionTime,
LocalDateTime completionTime,
TrackingId trackingId,
VoyageNumber voyageNumber,
UnLocode unLocode,
HandlingEvent.Type type)
throws CannotCreateHandlingEventException {
Date registrationTime = new Date();
LocalDateTime registrationTime = LocalDateTime.now();

/*
* Using a factory to create a HandlingEvent (aggregate). This is where it is
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
package org.eclipse.cargotracker.application.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/** A few utils for working with Date. */
// TODO [Clean Code] Make this a CDI singleton?
public class DateUtil {
public static final String DATE_PATTERN = "yyyy-MM-dd";
public static final String DT_PATTERN = "yyyy-MM-dd HH:mm";

public static final String DT_FORMAT = "MM/dd/yyyy hh:mm a z";

private DateUtil() {}

public static Date toDate(String date) {
return toDate(date, "00:00.00.000");
public static LocalDate toDate(String date) {
return LocalDate.parse(date, DateTimeFormatter.ofPattern(DATE_PATTERN));
}

public static LocalDateTime toDateTime(String datetime) {
return LocalDateTime.parse(datetime, DateTimeFormatter.ofPattern(DT_PATTERN));
}

public static LocalDateTime toDateTime(String date, String time) {
return toDateTime(date + " " + time);
}

public static Date toDate(String date, String time) {
try {
return new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(date + " " + time);
} catch (ParseException e) {
throw new RuntimeException(e);
}
public static String toString(LocalDateTime dt) {
return dt.format(DateTimeFormatter.ofPattern(DT_FORMAT));
}

public static String getDateFromDateTime(String dateTime) {
Expand Down
Loading