View Javadoc
1   /**
2    * Copyright 2011-2013 The Kuali Foundation Licensed under the Educational
3    * Community License, Version 2.0 (the "License"); you may not use this file
4    * except in compliance with the License. You may obtain a copy of the License
5    * at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12   * License for the specific language governing permissions and limitations under
13   * the License.
14   */
15  package org.kuali.mobility.computerlabs.entity;
16  
17  import java.io.Serializable;
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import javax.xml.bind.annotation.XmlElement;
22  import javax.xml.bind.annotation.XmlRootElement;
23  import org.apache.commons.collections.CollectionUtils;
24  import org.kuali.mobility.computerlabs.util.LabTransform;
25  import org.kuali.mobility.computerlabs.util.LocationTransform;
26  
27  /**
28   * An object representing a location for a computer lab. This most likely would
29   * be a building. LocationImpl contains the name of the building and a
30   * <code>List&lt;LabImpl&gt;</code> of labs or rooms in the building containing
31   * available computers.
32   *
33   * @author Kuali Mobility Team
34   */
35  @XmlRootElement(name = "location")
36  public class LocationImpl implements Serializable, Comparable<Location>, Location {
37  
38  	private static final long serialVersionUID = -4991494626566555287L;
39  	private String name;
40  	@XmlElement(name = "labs")
41  	private List<LabImpl> labs;
42  
43  	private static final LabTransform LAB_TRANSFORM = new LabTransform();
44  
45  	public LocationImpl() {
46  		super();
47  		this.labs = new ArrayList<LabImpl>();
48  	}
49  
50  	public LocationImpl(String name) {
51  		this.name = name;
52  		this.labs = new ArrayList<LabImpl>();
53  	}
54  
55  	@Override
56  	public List<LabImpl> getLabs() {
57  		return labs;
58  	}
59  
60  	@Override
61  	public void setLabs(List<? extends Lab> labs) {
62  		CollectionUtils.collect(labs, LAB_TRANSFORM, this.labs);
63  	}
64  
65  	@Override
66  	public void addLab( Lab lab ) {
67  		this.labs.add( LAB_TRANSFORM.transform(lab) );
68  	}
69  
70  	@Override
71  	public String getName() {
72  		return name;
73  	}
74  
75  	@Override
76  	public void setName(String name) {
77  		this.name = name;
78  	}
79  
80  	@Override
81  	public int compareTo(Location that) {
82  		if (this == null || that == null) {
83  			return -1;
84  		}
85  		if (this.getName() == that.getName()) {
86  			return 0;
87  		}
88  		return this.getName().compareTo(that.getName());
89  	}
90  }