Skip to content

Commit

Permalink
Refactor: Remove unnecessary imports and reformat code
Browse files Browse the repository at this point in the history
Removed unused imports such as `Collectors` and `ArrayList` in multiple files for cleaner code. Reformatted switch-case statements and code blocks for improved readability and consistency.
  • Loading branch information
rokon12 committed Jul 20, 2024
1 parent 63ac0cc commit 51923b6
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import org.eclipse.cargotracker.domain.model.cargo.Itinerary;
import org.eclipse.cargotracker.domain.model.cargo.Leg;
import org.eclipse.cargotracker.domain.model.cargo.RouteSpecification;
Expand Down Expand Up @@ -82,8 +81,7 @@ public List<Itinerary> fetchRoutesForSpecification(RouteSpecification routeSpeci
}

private Itinerary toItinerary(TransitPath transitPath) {
List<Leg> legs =
transitPath.getTransitEdges().stream().map(this::toLeg).toList();
List<Leg> legs = transitPath.getTransitEdges().stream().map(this::toLeg).toList();
return new Itinerary(legs);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@
* At the moment, coordinates are effectively a shared DTO in the interface layer. It may be
* converted to a domain level concern at some point. *
*/
public record Coordinates(double latitude, double longitude) {

}
public record Coordinates(double latitude, double longitude) {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@
import java.util.List;

public record CargoStatus(
String trackingId,
String destination,
String statusText,
boolean misdirected,
String eta,
String nextExpectedActivity,
List<TrackingEvents> events) {
String trackingId,
String destination,
String statusText,
boolean misdirected,
String eta,
String nextExpectedActivity,
List<TrackingEvents> events) {

public CargoStatus {
events = List.copyOf(events);
}
public CargoStatus {
events = List.copyOf(events);
}

@Override
public List<TrackingEvents> events() {
return Collections.unmodifiableList(events);
}
@Override
public List<TrackingEvents> events() {
return Collections.unmodifiableList(events);
}

/**
* @return A readable string describing the cargo status.
*/
public String getStatusText() {
return statusText;
}
}
/**
* @return A readable string describing the cargo status.
*/
public String getStatusText() {
return statusText;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package org.eclipse.cargotracker.interfaces.booking.facade.dto;

public record TrackingEvents(boolean expected, String description, String time) {
}
public record TrackingEvents(boolean expected, String description, String time) {}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.io.Serializable;
import java.time.LocalDate;
import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.cargotracker.application.BookingService;
import org.eclipse.cargotracker.domain.model.cargo.Cargo;
import org.eclipse.cargotracker.domain.model.cargo.CargoRepository;
Expand Down Expand Up @@ -118,8 +117,6 @@ public List<RouteCandidate> requestPossibleRoutesForCargo(String trackingId) {
List<Itinerary> itineraries =
bookingService.requestPossibleRoutesForCargo(new TrackingId(trackingId));

return itineraries.stream()
.map(itineraryCandidateDtoAssembler::toDto)
.toList();
return itineraries.stream().map(itineraryCandidateDtoAssembler::toDto).toList();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.eclipse.cargotracker.interfaces.booking.facade.internal.assembler;

import static java.util.stream.Collectors.toList;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import jakarta.inject.Inject;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.cargotracker.application.util.DateConverter;
import org.eclipse.cargotracker.domain.model.cargo.Cargo;
import org.eclipse.cargotracker.domain.model.cargo.Delivery;
Expand Down Expand Up @@ -40,7 +39,8 @@ private String getCargoStatusText(Cargo cargo) {
Delivery delivery = cargo.getDelivery();
return switch (delivery.getTransportStatus()) {
case IN_PORT -> "In port " + delivery.getLastKnownLocation().getName();
case ONBOARD_CARRIER -> "Onboard voyage " + delivery.getCurrentVoyage().getVoyageNumber().getIdString();
case ONBOARD_CARRIER ->
"Onboard voyage " + delivery.getCurrentVoyage().getVoyageNumber().getIdString();
case CLAIMED -> "Claimed";
case NOT_RECEIVED -> "Not received";
case UNKNOWN -> "Unknown";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import jakarta.inject.Inject;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.cargotracker.application.util.DateConverter;
import org.eclipse.cargotracker.domain.model.cargo.Itinerary;
import org.eclipse.cargotracker.domain.model.cargo.Leg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import jakarta.enterprise.context.ApplicationScoped;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.cargotracker.domain.model.location.Location;

@ApplicationScoped
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ private String timeFrom(HandlingEvent event) {
}

private String descriptionFrom(HandlingEvent.Type type, String location, String voyageNumber) {
return switch (type) {
case LOAD -> "Loaded onto voyage " + voyageNumber + " in " + location;
case UNLOAD -> "Unloaded off voyage " + voyageNumber + " in " + location;
case RECEIVE -> "Received in " + location;
case CLAIM -> "Claimed in " + location;
case CUSTOMS -> "Cleared customs in " + location;
};
return switch (type) {
case LOAD -> "Loaded onto voyage " + voyageNumber + " in " + location;
case UNLOAD -> "Unloaded off voyage " + voyageNumber + " in " + location;
case RECEIVE -> "Received in " + location;
case CLAIM -> "Claimed in " + location;
case CUSTOMS -> "Cleared customs in " + location;
};
}

private String voyageNumberFrom(HandlingEvent handlingEvent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import jakarta.inject.Named;
import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cargotracker.interfaces.booking.facade.BookingServiceFacade;
import org.eclipse.cargotracker.interfaces.booking.facade.dto.CargoRoute;
Expand Down Expand Up @@ -56,11 +55,11 @@ public List<Location> getPotentialDestinations() {
String destinationCode = cargo.getFinalDestinationCode().toLowerCase();

return locations.stream()
.filter(location ->
!location.getUnLocode().toLowerCase().equals(originCode) &&
!location.getUnLocode().toLowerCase().equals(destinationCode)
)
.toList();
.filter(
location ->
!location.getUnLocode().toLowerCase().equals(originCode)
&& !location.getUnLocode().toLowerCase().equals(destinationCode))
.toList();
}

public String getDestinationUnlocode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,14 @@ public String getStatusCode() {
public String getStatusText() {
Delivery delivery = cargo.getDelivery();

return switch (delivery.getTransportStatus()) {
case IN_PORT -> "In port " + cargo.getRouteSpecification().getDestination().getName();
case ONBOARD_CARRIER -> "Onboard voyage " + delivery.getCurrentVoyage().getVoyageNumber().getIdString();
case CLAIMED -> "Claimed";
case NOT_RECEIVED -> "Not received";
case UNKNOWN -> "Unknown";
};
return switch (delivery.getTransportStatus()) {
case IN_PORT -> "In port " + cargo.getRouteSpecification().getDestination().getName();
case ONBOARD_CARRIER ->
"Onboard voyage " + delivery.getCurrentVoyage().getVoyageNumber().getIdString();
case CLAIMED -> "Claimed";
case NOT_RECEIVED -> "Not received";
case UNKNOWN -> "Unknown";
};
}

public boolean isMisdirected() {
Expand Down Expand Up @@ -166,19 +167,21 @@ public boolean isExpected() {
}

public String getDescription() {
return switch (handlingEvent.getType()) {
case LOAD -> "Loaded onto voyage "
+ handlingEvent.getVoyage().getVoyageNumber().getIdString()
+ " in "
+ handlingEvent.getLocation().getName();
case UNLOAD -> "Unloaded off voyage "
+ handlingEvent.getVoyage().getVoyageNumber().getIdString()
+ " in "
+ handlingEvent.getLocation().getName();
case RECEIVE -> "Received in " + handlingEvent.getLocation().getName();
case CLAIM -> "Claimed in " + handlingEvent.getLocation().getName();
case CUSTOMS -> "Cleared customs in " + handlingEvent.getLocation().getName();
};
return switch (handlingEvent.getType()) {
case LOAD ->
"Loaded onto voyage "
+ handlingEvent.getVoyage().getVoyageNumber().getIdString()
+ " in "
+ handlingEvent.getLocation().getName();
case UNLOAD ->
"Unloaded off voyage "
+ handlingEvent.getVoyage().getVoyageNumber().getIdString()
+ " in "
+ handlingEvent.getLocation().getName();
case RECEIVE -> "Received in " + handlingEvent.getLocation().getName();
case CLAIM -> "Claimed in " + handlingEvent.getLocation().getName();
case CUSTOMS -> "Cleared customs in " + handlingEvent.getLocation().getName();
};
}
}
}

0 comments on commit 51923b6

Please sign in to comment.