summaryrefslogtreecommitdiff
path: root/src/main/java/net/transit/network/packet/ArrayPacket.java
blob: fbea8113d5bcf0030d5b57e0b0426bb43c91ea58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package net.transit.network.packet;

import java.util.ArrayList;

import net.transit.type.Type;

public class ArrayPacket<D> implements Packet<D>
{
    private ArrayList<D> arrayData;
    private Type<D> type;

    public ArrayPacket(D startValue, Type<D> t)
    {
        arrayData = new ArrayList<D>(0);
        arrayData.add(startValue);
        type = t;
    }
    
    @Override
    public D getData()
    {
        if(arrayData.size() > 0) return arrayData.get(0);
        return null;
    }

    public void addData(D data)
    {
        arrayData.add(data);
    }
    
    public int dataStored()
    {
    	return arrayData.size();
    }

    public D popAndShift()
    {
        D temp = null;
        
        if(arrayData.size() > 0)
        {
            temp = arrayData.remove(0);
        }

        return temp;
    }
    
    @Override
	public Type<D> getType() {
		return type;
	}
}