Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2008-2013 LimeTri. All rights reserved. AgroSense is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. There are special exceptions to the terms and conditions of the GPLv3 as it is applied to this software, see the FLOSS License Exception <http://www.agrosense.eu/foss-exception.html>. AgroSense 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 General Public License for more details. You should have received a copy of the GNU General Public License along with AgroSense. If not, see <http://www.gnu.org/licenses/>.
 
 
 package eu.agrosense.api.observations.mappings;
 
 import  com.vividsolutions.jts.geom.Coordinate;
 import  com.vividsolutions.jts.geom.Envelope;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;

Author(s):
johan
 
 public abstract class AbstractObservationMapper extends Mapper<Map<String,Object>> {
     private static final Logger LOGGER = Logger.getLogger(AbstractObservationMapper.class.getName());
     
     //sensordata files don't nicely match the pattern of producing a single object per source record;
     //reuse a single observation, each source row will add one or more measurements to its collections.
     protected final Map<String,Objectobservation = new HashMap<>();
     protected final Envelope envelope = new Envelope();
     protected final Map<TargetAttributeDescriptor,MeasurementCollection0mcMap = new HashMap<>();
     protected int seqNo = 0;
 
     public AbstractObservationMapper(MappableSource sourceMapping mapping,
             Map<TargetAttributeDescriptor,MeasurementTypemeasurementAttributes) {
         super(sourcemapping);
         
         .put(.source.getName());
         
         setupSourceMetadata(sourcemapping);
         setupMeasurementCollections(mappingmeasurementAttributes);
     }
    
    
Setup a lookup table of measurement collections per target attribute. (the observation keeps a list of measurement collections, which we don't want to search through for every value)

Parameters:
mapping
measurementAttributes
 
     private void setupMeasurementCollections(Mapping mappingMap<TargetAttributeDescriptor,MeasurementTypemeasurementAttributes) {
         // loop intersection of attrs used in mapping and sensor attrs that map to measurement values:
         for (TargetAttributeDescriptor tad : mapping.getAttrMapping().keySet()) {
             MeasurementType mt = measurementAttributes.get(tad);
             if (mt != null) {
                 .put(tadnew MeasurementCollection0(mt));
             }
         }
     }
     
     private void setupSourceMetadata(MappableSource sourceMapping mapping) {
 //        Map<String,String> metadata = observation.getSourceMetadata();
         Map<String,Stringmetadata = new HashMap<>();
         
         // TODO: convert metadata to properties, nested map no longer needed (and not possible with PM)
         // create something like a HasSourceMetadata aspect and let Observation interface use it.
 
         metadata.put(.mapping.getTargetId());
         metadata.put(.mapping.getName());
         metadata.put(.source.getName());
     }
     
     // use old repo model as buffer:
     protected class Measurement {
         private Date timestamp;
         private Coordinate coordinate;
         private double value;
 
         public Measurement() {
         }
         
        public Date getTimestamp() {
            return ;
        }
        public void setTimestamp(Date timestamp) {
            this. = timestamp;
        }
        public Coordinate getCoordinate() {
            return ;
        }
        public void setCoordinate(Coordinate coordinate) {
            this. = coordinate;
        }
        public double getValue() {
            return ;
        }
        public void setValue(double value) {
            this. = value;
        }
    }
    
    protected class MeasurementCollection0 {
        private final MeasurementType type;
        private final List<Measurementmeasurements = new LinkedList<>();
        public MeasurementCollection0(MeasurementType type) {
            this. = type;
        }
        public void addMeasurement(Measurement measurement) {
           .add(measurement);
        }
        public MeasurementType getType() {
            return ;
        }
        public List<MeasurementgetMeasurements() {
            return ;
        }
    }
New to GrepCode? Check out our FAQ X