Skip to content

Commit

Permalink
For #83 and #87 removed excessive sorted of archive positions track
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalidze committed Feb 13, 2015
1 parent 7d85b3b commit a27b5a4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 32 deletions.
42 changes: 15 additions & 27 deletions src/main/java/org/traccar/web/client/Track.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@
*/
package org.traccar.web.client;

import org.traccar.web.client.TrackSegment;
import org.traccar.web.shared.model.Position;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;

Expand All @@ -29,17 +26,14 @@ public class Track {
public List<TrackSegment> segments = new LinkedList<TrackSegment>();

public Track() {

}

public Track(List<Position> positions) {
segments.clear();
segments.add(new TrackSegment(positions,new ArchiveStyle()));
segments.add(new TrackSegment(positions, new ArchiveStyle()));
}

public Track(List<Position> positions, ArchiveStyle style) {
segments.clear();
segments.add(new TrackSegment(positions,style));
segments.add(new TrackSegment(positions, style));
}

public void setStyle(ArchiveStyle style) {
Expand All @@ -56,31 +50,25 @@ public ArchiveStyle getStyle() {
}

public List<Position> getPositions() {
List<Position> positions = new LinkedList<Position>();
for (TrackSegment segment : segments) {
for (Position position : segment.getPositions()) {
positions.add(position);
if (segments.isEmpty()) {
return Collections.emptyList();
} else if (segments.size() == 1) {
return segments.get(0).getPositions();
} else {
List<Position> positions = new LinkedList<Position>();
for (TrackSegment segment : segments) {
for (Position position : segment.getPositions()) {
positions.add(position);
}
}
return positions;
}
return positions;
}

public List<Position> getSortedPositions() {
List<Position> sortedPositions = new LinkedList<Position>(this.getPositions());
Collections.sort(sortedPositions, new Comparator<Position>() {
@Override
public int compare(Position o1, Position o2) {
return o1.getTime().compareTo(o2.getTime());
}
});
return sortedPositions;
}

public List<Position> getTimePositions(long timePrintInterval) {
List<Position> sortedPositions = this.getSortedPositions();
List<Position> withTime = new ArrayList<Position>();
List<Position> withTime = new LinkedList<Position>();
long prevTime = -1;
for (Position position : sortedPositions) {
for (Position position : getPositions()) {
if (prevTime < 0 ||
(position.getTime().getTime() - prevTime >= timePrintInterval * 60 * 1000)) {
withTime.add(position);
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/org/traccar/web/client/TrackSegment.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,24 @@

import org.traccar.web.shared.model.Position;

import java.util.List;
import java.util.*;

public class TrackSegment {

private ArchiveStyle style;
private List<Position> positions;

public TrackSegment() {
this.style = new ArchiveStyle();
}

public TrackSegment(List<Position> positions, ArchiveStyle style) {
this.positions = positions;
this.positions = new ArrayList<Position>(positions);
Collections.sort(this.positions, new Comparator<Position>() {
@Override
public int compare(Position o1, Position o2) {
return o1.getTime().compareTo(o2.getTime());
}
});
this.style = style;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public void showTrack(Track track, boolean clearExisting) {
tracks.clear();
}

List<Position> positions = track.getSortedPositions();
List<Position> positions = track.getPositions();

if (!positions.isEmpty()) {
Point[] linePoints = new Point[positions.size()];
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/traccar/web/client/view/MapView.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public void showArchiveTrack(Track track) {
}

public void showArchivePositions(Track track) {
List<Position> positions = track.getSortedPositions();
List<Position> positions = track.getPositions();
archivePositionRenderer.showPositions(positions);
}

Expand Down

0 comments on commit a27b5a4

Please sign in to comment.