/*
 * Copyright (C) 2013  Christian Autermann, Jan Alexander Wirwahn,
 *                     Arne De Wall, Dustin Demuth, Saqib Rasheed
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package io.car.server.rest;

import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import org.joda.time.DateTime;

import com.google.common.collect.Lists;
import com.vividsolutions.jts.geom.Geometry;

import io.car.server.core.entities.Measurement;
import io.car.server.core.entities.Sensor;
import io.car.server.core.entities.Track;
import io.car.server.core.entities.User;

/**
 * TODO JavaDoc
 * @author Christian Autermann <autermann@uni-muenster.de>
 */
public class TrackWithMeasurments implements Track, Iterable<Measurement> {

    private Track track;
    private List<Measurement> measurements = Lists.newLinkedList();

    public TrackWithMeasurments(Track track) {
        this.track = track;
    }

    @Override
    public String getName() {
        return track.getName();
    }

    @Override
    public Track setName(String name) {
        return track.setName(name);
    }

    @Override
    public String getDescription() {
        return track.getDescription();
    }

    @Override
    public Track setDescription(String description) {
        return track.setDescription(description);
    }

    @Override
    public String getIdentifier() {
        return track.getIdentifier();
    }

    @Override
    public Track setIdentifier(String id) {
        return track.setIdentifier(id);
    }

    @Override
    public User getUser() {
        return track.getUser();
    }

    @Override
    public Track setUser(User user) {
        return track.setUser(user);
    }

    @Override
    public Sensor getSensor() {
        return track.getSensor();
    }

    @Override
    public Track setSensor(Sensor track) {
        return this.track.setSensor(track);
    }

    @Override
    public Geometry getBbox() {
        return track.getBbox();
    }

    @Override
    public Track setBbox(Geometry bbox) {
        return track.setBbox(bbox);
    }

    @Override
    public Track setBbox(double minx, double miny, double maxx, double maxy) {
        return track.setBbox(minx, miny, maxx, maxy);
    }

    @Override
    public DateTime getCreationDate() {
        return track.getCreationDate();
    }

    @Override
    public DateTime getLastModificationDate() {
        return track.getLastModificationDate();
    }

    @Override
    public Iterator<Measurement> iterator() {
        return measurements.iterator();
    }

    public boolean addMeasurement(Measurement e) {
        return measurements.add(e);
    }

    public boolean removeMeasurement(Measurement o) {
        return measurements.remove(o);
    }

    public List<Measurement> getMeasurements() {
        return Collections.unmodifiableList(measurements);
    }

    public Track getTrack() {
        return track;
    }
}

@@ -1679,39 +1679,32 @@
 name) %7B%0A        
-return 
 track.setName(na
@@ -1704,24 +1704,45 @@
 Name(name);%0A
+        return this;%0A
     %7D%0A%0A    @
@@ -1901,39 +1901,32 @@
 tion) %7B%0A        
-return 
 track.setDescrip
@@ -1944,16 +1944,37 @@
 ption);%0A
+        return this;%0A
     %7D%0A%0A 
@@ -2125,39 +2125,32 @@
 g id) %7B%0A        
-return 
 track.setIdentif
@@ -2158,16 +2158,37 @@
 er(id);%0A
+        return this;%0A
     %7D%0A%0A 
@@ -2319,39 +2319,32 @@
 user) %7B%0A        
-return 
 track.setUser(us
@@ -2348,16 +2348,37 @@
 (user);%0A
+        return this;%0A
     %7D%0A%0A 
@@ -2524,31 +2524,24 @@
 ) %7B%0A        
-return 
 this.track.s
@@ -2557,16 +2557,37 @@
 track);%0A
+        return this;%0A
     %7D%0A%0A 
@@ -2726,39 +2726,32 @@
 bbox) %7B%0A        
-return 
 track.setBbox(bb
@@ -2755,16 +2755,37 @@
 (bbox);%0A
+        return this;%0A
     %7D%0A%0A 
@@ -2880,31 +2880,24 @@
 ) %7B%0A        
-return 
 track.setBbo
@@ -2923,16 +2923,37 @@
  maxy);%0A
+        return this;%0A
     %7D%0A%0A 

return the right track