1 /*** 2 * Java DAB EPG API - Serialize/Deserialize To/From POJOs to XML/Binary as per 3 * ETSI specifications TS 102 818 (XML Specification for DAB EPG) and TS 102 4 * 371 (Transportation and Binary Encoding Specification for EPG). 5 * 6 * Copyright (C) 2007 GCap Media PLC 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public 10 * License as published by the Free Software Foundation; either 11 * version 2.1 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with this library; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 21 */ 22 package com.gcapmedia.dab.epg; 23 24 import java.util.ArrayList; 25 import java.util.Collection; 26 import java.util.Collections; 27 import java.util.List; 28 29 import org.joda.time.DateTime; 30 import org.joda.time.ReadableInstant; 31 32 /*** 33 * 34 */ 35 public class Schedule { 36 37 /*** 38 * Schedule version number 39 */ 40 private int version; 41 42 /*** 43 * Schedule creation time 44 */ 45 private ReadableInstant created; 46 47 /*** 48 * Denotes the originator of the schedule (e.g. BBC) 49 */ 50 private String originator; 51 52 /*** 53 * Scope is used to indicate the time period covered by this schedule, from 54 * the billed start time of the first programme to the billed end time of 55 * the last programme. 56 */ 57 private Scope scope; 58 59 /*** 60 * Schedule programmes 61 */ 62 private List<Programme> programmes; 63 64 /*** 65 * Create a new schedule 66 */ 67 public Schedule() { 68 created = new DateTime(); 69 programmes = new ArrayList<Programme>(); 70 version = 1; 71 } 72 73 /*** 74 * Sets the time the schedule was created 75 * @param created Time the schedule was created 76 */ 77 public void setCreated(ReadableInstant created) { 78 this.created = created; 79 } 80 81 /*** 82 * @return Returns the schedule creation time 83 */ 84 public ReadableInstant getCreated() { 85 return created; 86 } 87 88 /*** 89 * Sets the version number of this schedule 90 * @param version Schedule version number 91 */ 92 public void setVersion(int version) { 93 this.version = version; 94 } 95 96 /*** 97 * @return Returns the schedule version 98 */ 99 public int getVersion() { 100 return version; 101 } 102 103 /*** 104 * Sets the originator for this schedule 105 * @param originator Schedule originator 106 */ 107 public void setOriginator(String originator) { 108 if(originator.length() > 128) { 109 throw new IllegalArgumentException("Originator must be less than or equal to 128 characters in length"); 110 } 111 this.originator = originator; 112 } 113 114 /*** 115 * @return Returns the schedule originator 116 */ 117 public String getOriginator() { 118 return originator; 119 } 120 121 /*** 122 * Sets the schedule scope 123 * @param scope Schedule scope 124 */ 125 public void setScope(Scope scope) { 126 this.scope = scope; 127 } 128 129 /*** 130 * @return Returns the schedule scope 131 */ 132 public Scope getScope() { 133 return scope; 134 } 135 136 /*** 137 * Add a programme to the schedule 138 * @param programme Programme to add 139 */ 140 public void addProgramme(Programme programme) { 141 programmes.add(programme); 142 } 143 144 /*** 145 * @return Returns all programmes in this schedule 146 */ 147 public Collection<Programme> getProgrammes() { 148 return Collections.unmodifiableCollection(programmes); 149 } 150 151 /*** 152 * Remove a programme from the schedule 153 * @param programme Programme to remove 154 */ 155 public void removeProgramme(Programme programme) { 156 programmes.remove(programme); 157 } 158 159 /*** 160 * Clears all programmes from the schedule 161 */ 162 public void clearProgrammes() { 163 programmes.clear(); 164 } 165 166 /*** 167 * @see java.lang.Object#equals(java.lang.Object) 168 */ 169 @Override 170 public boolean equals(Object obj) { 171 if(!(obj instanceof Schedule)) { 172 return false; 173 } 174 Schedule that = (Schedule)obj; 175 return this.scope.equals(that.scope) && 176 this.programmes.equals(that.programmes); 177 } 178 179 /*** 180 * @see java.lang.Object#toString() 181 */ 182 public String toString() { 183 StringBuilder buf = new StringBuilder(); 184 buf.append("Schedule [version=" + version); 185 buf.append(", created=" + created); 186 if(originator != null) { 187 buf.append(", originator=" + originator); 188 } 189 buf.append(", scope=" + scope); 190 buf.append(", progs=" + programmes); 191 buf.append("]"); 192 return buf.toString(); 193 } 194 195 }