(no commit message)
[utils] / gps / src / main / java / org / wamblee / gps / track / TrackSegmentImpl.java
1 /*
2  * Copyright 2006 the original author or authors.
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */ 
16
17 package org.wamblee.gps.track;
18
19 import java.io.Serializable;
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import org.wamblee.gps.geometry.Point;
24
25 /**
26  * Represents a GPS track. 
27  *
28  * @author Erik Brakkee
29  */
30 public class TrackSegmentImpl implements Serializable, TrackSegment {
31     
32     private String _description; 
33     private List<TrackPoint> _points; 
34     
35     /**
36      * Constructs an empty track. 
37      *
38      */
39     public TrackSegmentImpl(String aDescription) { 
40         _description = aDescription;  
41         _points = new ArrayList<TrackPoint>();
42     }
43     
44     
45     @Override
46     public String getDescription() {
47         return _description;
48     }
49     
50     /**
51      * Adds a point to a track. 
52      * @param aPoint Point. 
53      */
54     public void addPoint(TrackPoint aPoint) { 
55         _points.add(aPoint);
56     }
57     
58     /* (non-Javadoc)
59      * @see org.wamblee.gps.track.TrackSegment#size()
60      */
61     public int size()  { 
62         return _points.size(); 
63     }
64     
65     /* (non-Javadoc)
66      * @see org.wamblee.gps.track.TrackSegment#getMinCoordinate(int)
67      */
68     public double getMinCoordinate(int i) {
69         if ( size() == 0 ) { 
70             throw new IllegalArgumentException("empty track");
71         }
72         double min = getPoint(0).getCoordinates().getX(i);
73         for (int j = 1; j < size(); j++) { 
74             min = Math.min(min, getPoint(j).getCoordinates().getX(i));
75         }
76         return min;
77     }
78     
79     /* (non-Javadoc)
80      * @see org.wamblee.gps.track.TrackSegment#getMaxCoordinate(int)
81      */
82     public double getMaxCoordinate(int i) {
83         if ( size() == 0 ) { 
84             throw new IllegalArgumentException("empty track");
85         }
86         double max = getPoint(0).getCoordinates().getX(i);
87         for (int j = 1; j < size(); j++) { 
88             max = Math.max(max, getPoint(j).getCoordinates().getX(i));
89         }
90         return max;
91     }
92     
93     /* (non-Javadoc)
94      * @see org.wamblee.gps.track.TrackSegment#getPoint(int)
95      */
96     public Point getPoint(int aIndex) { 
97         return _points.get(aIndex);
98     }
99 }