package pl.edu.agh.dsm.common.measurement.impl;

import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pl.edu.agh.dsm.common.dto.MeasurementDto;
import pl.edu.agh.dsm.common.measurement.MeasurementRepository;

import java.util.List;
import java.util.UUID;

public class MeasurementRepositoryImpl implements MeasurementRepository {

    static final Logger logger = LoggerFactory.getLogger(MeasurementRepositoryImpl.class);

    List<MeasurementDto> collector = Lists.newArrayList();

    @Override
    public List<MeasurementDto> findAll(Predicate<MeasurementDto> preconditions) {
        logger.debug("find all measurements with conditions {}" , preconditions);

        Iterable<MeasurementDto> iter = Lists.newArrayList();
        Iterables.addAll(collector, iter);

        return Lists.newArrayList(Iterables.filter(iter, preconditions));
    }

    @Override
    public MeasurementDto find(final UUID uuid) {
        logger.debug("find measurement with id {}" , uuid);

        Iterable<MeasurementDto> iter = Lists.newArrayList();
        Iterables.addAll(collector, iter);

        return Iterables.find(iter, new Predicate<MeasurementDto>() {
            @Override
            public boolean apply(MeasurementDto measurementDto) {
                return measurementDto.getId().equals(uuid);
            }
        });
    }

    @Override
    public void remove(UUID uuid) {
        logger.debug("remove measurement with id {}" , uuid);

        collector.remove(find(uuid));
    }

    @Override
    public void save(MeasurementDto measurementDto) {
        logger.debug("save measurement {}" , measurementDto);

        collector.add(measurementDto);
    }
}

@@ -556,16 +556,23 @@
 );%0A%0A    
+static 
 List%3CMea
@@ -584,25 +584,20 @@
 entDto%3E 
-collector
+repo
  = Lists
@@ -877,33 +877,28 @@
 bles.addAll(
-collector
+repo
 , iter);%0A%0A  
@@ -1188,25 +1188,20 @@
 .addAll(
-collector
+repo
 , iter);
@@ -1574,25 +1574,20 @@
         
-collector
+repo
 .remove(
@@ -1749,17 +1749,12 @@
     
-collector
+repo
 .add

fix repo impl