001/** 002 * Copyright 2018 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.shock.datatypes; 017 018import java.util.List; 019 020import javax.xml.bind.annotation.XmlAccessType; 021import javax.xml.bind.annotation.XmlAccessorType; 022import javax.xml.bind.annotation.XmlElementRef; 023import javax.xml.bind.annotation.XmlRootElement; 024 025import core.tut.pori.http.ResponseData; 026import service.tut.pori.apilta.sensors.datatypes.Definitions; 027 028/** 029 * 030 * 031 */ 032@XmlRootElement(name=Definitions.ELEMENT_MEASUREMENT_LIST) 033@XmlAccessorType(XmlAccessType.NONE) 034public class ShockMeasurementList extends ResponseData { 035 @XmlElementRef 036 private List<ShockMeasurement> _shockMeasurements = null; 037 038 /** 039 * for sub-classing, use the static 040 * 041 * @return true if valid 042 */ 043 protected boolean isValid() { 044 if(isEmpty()){ 045 return false; 046 } 047 for(ShockMeasurement m : _shockMeasurements){ 048 if(!ShockMeasurement.isValid(m)){ 049 return false; 050 } 051 } 052 return true; 053 } 054 055 /** 056 * 057 * @param list 058 * @return true if the list is not null, empty or contain invalid data 059 */ 060 public static boolean isValid(ShockMeasurementList list) { 061 return (list != null && list.isValid()); 062 } 063 064 /** 065 * @return the shockMeasurements 066 */ 067 public List<ShockMeasurement> getShockMeasurements() { 068 return _shockMeasurements; 069 } 070 071 /** 072 * @param shockMeasurements the shockMeasurements to set 073 */ 074 public void setShockMeasurements(List<ShockMeasurement> shockMeasurements) { 075 _shockMeasurements = shockMeasurements; 076 } 077 078 /** 079 * for sub-classing, use the static 080 * 081 * @return true if list is empty 082 */ 083 protected boolean isEmpty() { 084 return (_shockMeasurements == null || _shockMeasurements.isEmpty()); 085 } 086 087 /** 088 * 089 * @param list 090 * @return true if the list is null or empty 091 */ 092 public static boolean isEmpty(ShockMeasurementList list) { 093 return (list == null || list.isEmpty()); 094 } 095 096 /** 097 * 098 * @param measurements 099 * @return return list object containing the given list or null if null or empty list was passed 100 */ 101 public static ShockMeasurementList getShockMeasurementList(List<ShockMeasurement> measurements) { 102 if(measurements == null || measurements.isEmpty()) { 103 return null; 104 } 105 ShockMeasurementList list = new ShockMeasurementList(); 106 list._shockMeasurements = measurements; 107 return list; 108 } 109}