1 package org.argosfields.model;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import org.eclipse.swt.SWT;
7
8 /***
9 * TransportUnit.java
10 *
11 * @author Xavier Cho
12 * @version $Revision: 1.1 $ $Date: 2003/10/19 08:33:43 $
13 */
14 public abstract class TransportUnit extends Unit implements ITransport {
15 private List units;
16
17 public TransportUnit() {
18 this.units = new ArrayList(getTransportSlots());
19 }
20
21 /***
22 * @see org.argosfields.model.ITransport#getTransportSlots()
23 */
24 public abstract int getTransportSlots();
25
26 /***
27 * @see org.argosfields.model.ITransport#getMinUnitWeight()
28 */
29 public abstract int getMinUnitWeight();
30
31 /***
32 * @see org.argosfields.model.ITransport#getMaxUnitWeight()
33 */
34 public abstract int getMaxUnitWeight();
35
36 /***
37 * @see org.argosfields.model.ITransport#getAvailableTransportSlots()
38 */
39 public int getAvailableTransportSlots() {
40 return getTransportSlots() - getUnitCount();
41 }
42
43 /***
44 * @see org.argosfields.model.ITransport#getUnitCount()
45 */
46 public int getUnitCount() {
47 return units.size();
48 }
49
50 /***
51 * @see org.argosfields.model.ITransport#unload(int)
52 */
53 public Unit unload(final int index) {
54 return (Unit) units.get(index);
55 }
56
57 /***
58 * @see org.argosfields.model.ITransport#load(org.argosfields.model.Unit)
59 */
60 public void load(final Unit unit) {
61 if (unit == null) {
62 SWT.error(SWT.ERROR_NULL_ARGUMENT);
63 }
64
65 if (canLoad(unit)) {
66 units.add(unit);
67 }
68 }
69
70 /***
71 * @see org.argosfields.model.ITransport#canLoad(org.argosfields.model.Unit)
72 */
73 public boolean canLoad(final Unit unit) {
74 if (unit == null) {
75 SWT.error(SWT.ERROR_NULL_ARGUMENT);
76 }
77
78 boolean canLoad =
79 getAvailableTransportSlots() > 0
80 && unit.getWeight() >= getMinUnitWeight()
81 && unit.getWeight() <= getMaxUnitWeight();
82
83 return canLoad;
84 }
85
86 /***
87 * @see org.argosfields.model.ITransport#getUnits()
88 */
89 public Unit[] getUnits() {
90 int size = getUnitCount();
91 return (Unit[]) units.toArray(new Unit[size]);
92 }
93 }
This page was automatically generated by Maven