001/** 002 * Copyright 2016 Tampere University of Technology, Pori Department 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package service.tut.pori.apilta.sensors.datatypes; 017 018import java.util.ArrayList; 019import java.util.List; 020 021import javax.xml.bind.annotation.XmlAccessType; 022import javax.xml.bind.annotation.XmlAccessorType; 023import javax.xml.bind.annotation.XmlElementRef; 024import javax.xml.bind.annotation.XmlRootElement; 025 026import core.tut.pori.http.ResponseData; 027 028/** 029 * lists a list of Measurement Data 030 * 031 * @see service.tut.pori.apilta.sensors.datatypes.Measurement 032 */ 033@XmlRootElement(name=Definitions.ELEMENT_MEASUREMENT_LIST) 034@XmlAccessorType(XmlAccessType.NONE) 035public class MeasurementList extends ResponseData { 036 @XmlElementRef 037 private List<Measurement> _measurements = null; 038 039 /** 040 * @return the measurements 041 * @see #setMeasurements(List) 042 */ 043 public List<Measurement> getMeasurements() { 044 return _measurements; 045 } 046 047 /** 048 * @param measurements the measurements to set 049 * @see #getMeasurements() 050 */ 051 public void setMeasurements(List<Measurement> measurements) { 052 _measurements = measurements; 053 } 054 055 /** 056 * for sub-classing, use the static 057 * 058 * @return true if the measurements in this list are valid 059 * @see #isValid(MeasurementList) 060 */ 061 protected boolean isValid() { 062 if(_measurements == null || _measurements.isEmpty()){ 063 return false; 064 } 065 for(Measurement m : _measurements){ 066 if(!Measurement.isValid(m)){ 067 return false; 068 } 069 } 070 return true; 071 } 072 073 /** 074 * 075 * @param list 076 * @return false if the list is null or invalid 077 */ 078 public static boolean isValid(MeasurementList list) { 079 if(list == null){ 080 return false; 081 }else{ 082 return list.isValid(); 083 } 084 } 085 086 /** 087 * for sub-classing, use the static 088 * @return true if empty 089 * @see #isEmpty(MeasurementList) 090 */ 091 protected boolean isEmpty() { 092 return (_measurements == null || _measurements.isEmpty()); 093 } 094 095 /** 096 * 097 * @param list 098 * @return true if the given list is null or empty 099 */ 100 public static boolean isEmpty(MeasurementList list) { 101 return (list == null || list.isEmpty()); 102 } 103 104 /** 105 * 106 * @param measurement 107 * @see #getMeasurements() 108 */ 109 public void addMeasurement(Measurement measurement) { 110 if(_measurements == null){ 111 _measurements = new ArrayList<>(); 112 } 113 _measurements.add(measurement); 114 } 115}