mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-06 12:23:55 +00:00
trying to improve performance by making RaceDefinition.getCompetitors().contains(...) faster using LinkedHashSet
This commit is contained in:
1 parent
15edc88887
commit
02cb51fde6
2 files changed
+24
-14
No files matched your search
+17
-13
@@ -59,18 +59,22 @@ public abstract class AbstractRaceColumn implements RaceColumn {
|
|||||||
@Override
|
@Override
|
||||||
public void setTrackedRace(Fleet fleet, TrackedRace trackedRace) {
|
public void setTrackedRace(Fleet fleet, TrackedRace trackedRace) {
|
||||||
TrackedRace previouslyLinkedRace = this.trackedRaces.get(fleet);
|
TrackedRace previouslyLinkedRace = this.trackedRaces.get(fleet);
|
||||||
if (trackedRace == null) {
|
if (trackedRace != previouslyLinkedRace) {
|
||||||
setRaceIdentifier(fleet, null);
|
synchronized (this) {
|
||||||
this.trackedRaces.remove(fleet);
|
if (trackedRace == null) {
|
||||||
} else {
|
setRaceIdentifier(fleet, null);
|
||||||
this.trackedRaces.put(fleet, trackedRace);
|
this.trackedRaces.remove(fleet);
|
||||||
this.setRaceIdentifier(fleet, trackedRace.getRaceIdentifier());
|
} else {
|
||||||
}
|
this.trackedRaces.put(fleet, trackedRace);
|
||||||
if (previouslyLinkedRace != null) {
|
this.setRaceIdentifier(fleet, trackedRace.getRaceIdentifier());
|
||||||
notifyListenersAboutTrackedRaceUnlinked(fleet, previouslyLinkedRace);
|
}
|
||||||
}
|
}
|
||||||
if (trackedRace != null) {
|
if (previouslyLinkedRace != null) {
|
||||||
notifyListenersAboutTrackedRaceLinked(fleet, trackedRace);
|
notifyListenersAboutTrackedRaceUnlinked(fleet, previouslyLinkedRace);
|
||||||
|
}
|
||||||
|
if (trackedRace != null) {
|
||||||
|
notifyListenersAboutTrackedRaceLinked(fleet, trackedRace);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +108,7 @@ public abstract class AbstractRaceColumn implements RaceColumn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void releaseTrackedRace(Fleet fleet) {
|
public synchronized void releaseTrackedRace(Fleet fleet) {
|
||||||
trackedRaces.remove(fleet);
|
trackedRaces.remove(fleet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-1
@@ -1,6 +1,8 @@
|
|||||||
package com.sap.sailing.domain.base.impl;
|
package com.sap.sailing.domain.base.impl;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import com.sap.sailing.domain.base.BoatClass;
|
import com.sap.sailing.domain.base.BoatClass;
|
||||||
import com.sap.sailing.domain.base.Competitor;
|
import com.sap.sailing.domain.base.Competitor;
|
||||||
@@ -22,7 +24,11 @@ public class RaceDefinitionImpl extends NamedImpl implements RaceDefinition {
|
|||||||
public RaceDefinitionImpl(String name, Course course, BoatClass boatClass, Iterable<Competitor> competitors, Serializable id) {
|
public RaceDefinitionImpl(String name, Course course, BoatClass boatClass, Iterable<Competitor> competitors, Serializable id) {
|
||||||
super(name);
|
super(name);
|
||||||
this.course = course;
|
this.course = course;
|
||||||
this.competitors = competitors;
|
Set<Competitor> competitorsAsLinkedHashSet = new LinkedHashSet<Competitor>();
|
||||||
|
for (Competitor competitor : competitors) {
|
||||||
|
competitorsAsLinkedHashSet.add(competitor);
|
||||||
|
}
|
||||||
|
this.competitors = competitorsAsLinkedHashSet;
|
||||||
this.boatClass = boatClass;
|
this.boatClass = boatClass;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user