mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-10 22:30:56 +00:00
Sort method for Named collections moved to the Util class.
This commit is contained in:
1 parent
4ec82ff2e2
commit
aad22a2e28
4 files changed
+21
-58
No files matched your search
+2
-22
@@ -1,8 +1,6 @@
|
||||
package com.sap.sailing.gwt.autoplay.client.place.start;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
@@ -36,8 +34,8 @@ import com.sap.sailing.gwt.ui.raceboard.RaceBoardPerspectiveSettings;
|
||||
import com.sap.sailing.gwt.ui.shared.EventDTO;
|
||||
import com.sap.sailing.gwt.ui.shared.LeaderboardGroupDTO;
|
||||
import com.sap.sailing.gwt.ui.shared.StrippedLeaderboardDTO;
|
||||
import com.sap.sse.common.Util;
|
||||
import com.sap.sse.common.settings.Settings;
|
||||
import com.sap.sse.common.util.NaturalComparator;
|
||||
import com.sap.sse.gwt.client.GWTLocaleUtil;
|
||||
import com.sap.sse.gwt.client.dialog.DataEntryDialog.DialogCallback;
|
||||
import com.sap.sse.gwt.client.event.LocaleChangeEvent;
|
||||
@@ -144,29 +142,11 @@ public class DesktopStartView extends Composite implements StartView {
|
||||
this.events.clear();
|
||||
this.events.addAll(events);
|
||||
eventSelectionBox.addItem(StringMessages.INSTANCE.pleaseSelectAnEvent());
|
||||
for (EventDTO event : sortEvents(events)) {
|
||||
for (EventDTO event : Util.sortNamedCollection(events)) {
|
||||
eventSelectionBox.addItem(event.getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort list of events alphabetically
|
||||
*
|
||||
* @param events
|
||||
* - collection that is going to be sorted
|
||||
* @return sorted list
|
||||
*/
|
||||
private List<EventDTO> sortEvents(List<EventDTO> events) {
|
||||
List<EventDTO> sortedEvents = new ArrayList<>(events);
|
||||
Collections.sort(sortedEvents, new Comparator<EventDTO>() {
|
||||
@Override
|
||||
public int compare(EventDTO event1, EventDTO event2) {
|
||||
return new NaturalComparator().compare(event1.getName(), event2.getName());
|
||||
}
|
||||
});
|
||||
return sortedEvents;
|
||||
}
|
||||
|
||||
@UiHandler("eventSelectionBox")
|
||||
void onEventSelectionChange(ChangeEvent event) {
|
||||
EventDTO selectedEvent = getSelectedEvent();
|
||||
|
||||
+2
-12
@@ -1,8 +1,5 @@
|
||||
package com.sap.sailing.gwt.ui.adminconsole;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -29,6 +26,7 @@ import com.sap.sailing.gwt.ui.shared.CourseAreaDTO;
|
||||
import com.sap.sailing.gwt.ui.shared.EventDTO;
|
||||
import com.sap.sailing.gwt.ui.shared.RegattaDTO;
|
||||
import com.sap.sailing.gwt.ui.shared.SeriesDTO;
|
||||
import com.sap.sse.common.Util;
|
||||
import com.sap.sse.gwt.client.controls.listedit.ListEditorComposite;
|
||||
|
||||
/**
|
||||
@@ -192,15 +190,7 @@ public abstract class AbstractRegattaWithSeriesAndFleetsDialog<T> extends DataEn
|
||||
|
||||
private void setupEventAndCourseAreaListBoxes(StringMessages stringMessages) {
|
||||
sailingEventsListBox.addItem(stringMessages.selectSailingEvent());
|
||||
final List<EventDTO> sortedEvents = new ArrayList<>();
|
||||
sortedEvents.addAll(existingEvents);
|
||||
Collections.sort(sortedEvents, new Comparator<EventDTO>() {
|
||||
@Override
|
||||
public int compare(EventDTO o1, EventDTO o2) {
|
||||
return o1.getName().compareTo(o2.getName());
|
||||
}
|
||||
});
|
||||
for (EventDTO event : sortedEvents) {
|
||||
for (EventDTO event : Util.sortNamedCollection(existingEvents)) {
|
||||
sailingEventsListBox.addItem(event.getName());
|
||||
if(defaultEvent != null){
|
||||
if (defaultEvent.getName().equals(event.getName())){
|
||||
|
||||
+2
-24
@@ -1,10 +1,6 @@
|
||||
package com.sap.sailing.gwt.ui.adminconsole;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gwt.event.dom.client.ChangeEvent;
|
||||
import com.google.gwt.event.dom.client.ChangeHandler;
|
||||
@@ -17,7 +13,7 @@ import com.sap.sailing.gwt.ui.client.StringMessages;
|
||||
import com.sap.sailing.gwt.ui.shared.CourseAreaDTO;
|
||||
import com.sap.sailing.gwt.ui.shared.EventDTO;
|
||||
import com.sap.sailing.gwt.ui.shared.StrippedLeaderboardDTO;
|
||||
import com.sap.sse.common.util.NaturalComparator;
|
||||
import com.sap.sse.common.Util;
|
||||
import com.sap.sse.gwt.client.ErrorReporter;
|
||||
|
||||
public abstract class FlexibleLeaderboardDialog extends AbstractLeaderboardDialog {
|
||||
@@ -113,7 +109,7 @@ public abstract class FlexibleLeaderboardDialog extends AbstractLeaderboardDialo
|
||||
protected ListBox createSailingEventListBox() {
|
||||
ListBox eventListBox = createListBox(false);
|
||||
eventListBox.addItem("Please select a sailing event...");
|
||||
for (EventDTO event : sortEvents(existingEvents)) {
|
||||
for (EventDTO event : Util.sortNamedCollection(existingEvents)) {
|
||||
eventListBox.addItem(event.getName());
|
||||
}
|
||||
eventListBox.addChangeHandler(new ChangeHandler() {
|
||||
@@ -125,24 +121,6 @@ public abstract class FlexibleLeaderboardDialog extends AbstractLeaderboardDialo
|
||||
return eventListBox;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort collection of events alphabetically
|
||||
*
|
||||
* @param events
|
||||
* - collection that is going to be sorted
|
||||
* @return sorted list
|
||||
*/
|
||||
private List<EventDTO> sortEvents(Collection<EventDTO> events) {
|
||||
List<EventDTO> sortedEvents = new ArrayList<>(events);
|
||||
Collections.sort(sortedEvents, new Comparator<EventDTO>() {
|
||||
@Override
|
||||
public int compare(EventDTO event1, EventDTO event2) {
|
||||
return new NaturalComparator().compare(event1.getName(), event2.getName());
|
||||
}
|
||||
});
|
||||
return sortedEvents;
|
||||
}
|
||||
|
||||
protected void onEventSelectionChanged() {
|
||||
EventDTO selectedEvent = getSelectedEvent();
|
||||
courseAreaListBox.clear();
|
||||
|
||||
@@ -4,6 +4,8 @@ import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
@@ -12,6 +14,8 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sap.sse.common.util.NaturalComparator;
|
||||
|
||||
|
||||
public class Util {
|
||||
|
||||
@@ -535,4 +539,15 @@ public class Util {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static <T extends Named> List<T> sortNamedCollection(Collection<T> collection) {
|
||||
List<T> sortedCollection = new ArrayList<>(collection);
|
||||
Collections.sort(sortedCollection, new Comparator<T>() {
|
||||
@Override
|
||||
public int compare(T o1, T o2) {
|
||||
return new NaturalComparator().compare(o1.getName(), o2.getName());
|
||||
}
|
||||
});
|
||||
return sortedCollection;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user