mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-04 11:23:50 +00:00
Refactored RacePlaceOrder and locations-String of EventDAO
This commit is contained in:
1 parent
6143cca737
commit
424d39bc83
5 files changed
+59
-47
No files matched your search
+2
-1
@@ -4,6 +4,7 @@ import java.io.Serializable;
|
||||
|
||||
public interface RacePlaceOrder extends Serializable {
|
||||
|
||||
Iterable<Placemark> getPlaces();
|
||||
Placemark getStartPlace();
|
||||
Placemark getFinishPlace();
|
||||
|
||||
}
|
||||
+28
-20
@@ -1,8 +1,6 @@
|
||||
package com.sap.sailing.domain.common.impl;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.sap.sailing.domain.common.Placemark;
|
||||
import com.sap.sailing.domain.common.RacePlaceOrder;
|
||||
@@ -10,39 +8,44 @@ import com.sap.sailing.domain.common.RacePlaceOrder;
|
||||
public class RacePlaceOrderImpl implements RacePlaceOrder, Serializable {
|
||||
private static final long serialVersionUID = 7590835541329816755L;
|
||||
|
||||
private List<Placemark> places;
|
||||
private Placemark start;
|
||||
private Placemark finish;
|
||||
|
||||
RacePlaceOrderImpl() {}
|
||||
|
||||
public RacePlaceOrderImpl(List<Placemark> places) {
|
||||
this.places = places;
|
||||
public RacePlaceOrderImpl(Placemark startPlace, Placemark finishPlace) {
|
||||
this.start = startPlace;
|
||||
this.finish = finishPlace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Placemark> getPlaces() {
|
||||
return Collections.unmodifiableCollection(places);
|
||||
public Placemark getStartPlace() {
|
||||
return start;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Placemark getFinishPlace() {
|
||||
return finish;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder b = new StringBuilder();
|
||||
boolean first = true;
|
||||
for (Placemark place : places) {
|
||||
if (place != null && first) {
|
||||
b.append(place.getCountryCode() + ", " + place.getName());
|
||||
first = false;
|
||||
} else if (place != null) {
|
||||
b.append(" -> " + place.getCountryCode() + ", " + place.getName());
|
||||
String result = "";
|
||||
if (start != null) {
|
||||
result += start.getCountryCode() + ", " + start.getName();
|
||||
if (!start.equals(finish)) {
|
||||
result += " -> " + finish.getCountryCode() + ", " + finish.getName();
|
||||
}
|
||||
}
|
||||
return b.toString();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((places == null) ? 0 : places.hashCode());
|
||||
result = prime * result + ((finish == null) ? 0 : finish.hashCode());
|
||||
result = prime * result + ((start == null) ? 0 : start.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -55,10 +58,15 @@ public class RacePlaceOrderImpl implements RacePlaceOrder, Serializable {
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
RacePlaceOrderImpl other = (RacePlaceOrderImpl) obj;
|
||||
if (places == null) {
|
||||
if (other.places != null)
|
||||
if (finish == null) {
|
||||
if (other.finish != null)
|
||||
return false;
|
||||
} else if (!places.equals(other.places))
|
||||
} else if (!finish.equals(other.finish))
|
||||
return false;
|
||||
if (start == null) {
|
||||
if (other.start != null)
|
||||
return false;
|
||||
} else if (!start.equals(other.start))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
+4
-5
@@ -1071,12 +1071,11 @@ public abstract class TrackedRaceImpl implements TrackedRace, CourseListener {
|
||||
}
|
||||
|
||||
if (startBest != null) {
|
||||
final List<Placemark> places = new ArrayList<Placemark>();
|
||||
places.add(startBest);
|
||||
if (!startBest.equals(finishBest)) {
|
||||
places.add(finishBest);
|
||||
if (finishBest != null) {
|
||||
order = new RacePlaceOrderImpl(startBest, finishBest);
|
||||
} else {
|
||||
order = new RacePlaceOrderImpl(startBest, startBest);
|
||||
}
|
||||
order = new RacePlaceOrderImpl(places);
|
||||
}
|
||||
|
||||
return order;
|
||||
|
||||
+23
-19
@@ -10,7 +10,7 @@ public class EventDAO extends NamedDAO implements IsSerializable {
|
||||
public List<RegattaDAO> regattas;
|
||||
public List<CompetitorDAO> competitors;
|
||||
|
||||
private String locations = null;
|
||||
public String locations;
|
||||
|
||||
public EventDAO() {
|
||||
}
|
||||
@@ -20,31 +20,35 @@ public class EventDAO extends NamedDAO implements IsSerializable {
|
||||
this.name = name;
|
||||
this.regattas = regattas;
|
||||
this.competitors = competitors;
|
||||
fillLocations();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the locations of the event as String.<br />
|
||||
* It has a format like this "Location1 -> Location2 -> ..." if the event has more than one location. Otherwhise it
|
||||
* returns just the name of the location.<br />
|
||||
* The locations are retrieved from the {@link RaceDAO RaceDAOs} in the {@link RegattaDAO RegattaDAOs}.
|
||||
*
|
||||
* @return The locations of the event as String
|
||||
*/
|
||||
public String getLocationAsString() {
|
||||
private void fillLocations() {
|
||||
//TODO Finish the format of the location string
|
||||
if (locations == null) {
|
||||
locations = "";
|
||||
for (RegattaDAO regattaDAO : regattas) {
|
||||
for (RaceDAO raceDAO : regattaDAO.races) {
|
||||
RacePlaceOrder placeOrder = raceDAO.racePlaces;
|
||||
if (placeOrder != null) {
|
||||
locations += placeOrder.toString() + "; ";
|
||||
StringBuilder b = new StringBuilder();
|
||||
boolean first = true;
|
||||
RacePlaceOrder previousOrder = null;
|
||||
locations = "";
|
||||
for (RegattaDAO regattaDAO : regattas) {
|
||||
for (RaceDAO raceDAO : regattaDAO.races) {
|
||||
RacePlaceOrder order = raceDAO.racePlaces;
|
||||
if (order != null) {
|
||||
if (first) {
|
||||
b.append(order.toString());
|
||||
previousOrder = order;
|
||||
first = false;
|
||||
} else {
|
||||
if (previousOrder.getFinishPlace().equals(order.getStartPlace())) {
|
||||
b.append(" -> " + order.getStartPlace().getCountryCode() + ", " + order.getStartPlace().getName());
|
||||
} else {
|
||||
b.append("; " + order.toString());
|
||||
}
|
||||
previousOrder = order;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return locations;
|
||||
locations = b.toString().equals("") ? null : b.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+2
-2
@@ -173,7 +173,7 @@ public class OverviewEventPanel extends AbstractEventPanel {
|
||||
TextColumn<EventDAO> locationColumn = new TextColumn<EventDAO>() {
|
||||
@Override
|
||||
public String getValue(EventDAO eventDAO) {
|
||||
String locations = eventDAO.getLocationAsString();
|
||||
String locations = eventDAO.locations;
|
||||
return locations != null ? locations : stringConstants.locationNotAvailable();
|
||||
}
|
||||
};
|
||||
@@ -329,7 +329,7 @@ public class OverviewEventPanel extends AbstractEventPanel {
|
||||
sortHandler.setComparator(locationColumn, new Comparator<EventDAO>() {
|
||||
@Override
|
||||
public int compare(EventDAO e1, EventDAO e2) {
|
||||
return e1.getLocationAsString().compareTo(e2.getLocationAsString());
|
||||
return e1.locations.compareTo(e2.locations);
|
||||
}
|
||||
});
|
||||
sortHandler.setComparator(nameColumn, new Comparator<EventDAO>() {
|
||||
|
||||
Reference in new issue
Block a user