summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/uic/barcode/ssbFrame/SsbNonReservation.java
blob: 80fc2bc48ff51993e3d44e3e785b1b79e1483dd7 (plain) (blame)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package org.uic.barcode.ssbFrame;

import org.uic.barcode.asn1.uper.BitBuffer;
import org.uic.barcode.asn1.uper.ByteBitBuffer;
import org.uic.barcode.ticket.EncodingFormatException;

public class SsbNonReservation extends SsbCommonTicketPart {
	
	protected int firstDayOfValidity = 0;
	protected int lastDayOfValidity = 0;
	protected boolean isReturnJourney = false;
	private int infoCode = 0;
	private String text = null;
	private SsbStations stations = new SsbStations();
	

	@Override
	protected int decodeContent(byte[] bytes, int offset) {
		
		offset = offset + decodeCommonPart(bytes);
		
		BitBuffer bits = new ByteBitBuffer(bytes);
		
		isReturnJourney = bits.get(offset);
		offset = offset++;
		
		firstDayOfValidity = bits.getInteger(offset, 9);
		offset = offset + 9;
		
		lastDayOfValidity = bits.getInteger(offset, 9);
		offset = offset + 9;
		
		offset = stations.decode(offset, bytes);
		
		infoCode = bits.getInteger(offset, 14);
		offset = offset + 14;
		
		text = bits.getChar6String(offset, 222);
		offset = offset + 222;
		
		return offset;
		
	}

	@Override
	protected int encodeContent(byte[] bytes, int offset) throws EncodingFormatException {
		
		offset = offset + encodeCommonPart(bytes, offset);
		
		BitBuffer bits = new ByteBitBuffer(bytes);
		
		bits.put(offset, isReturnJourney);
		offset = offset++;
		
		if (firstDayOfValidity < 0 || firstDayOfValidity > 511) {
			throw new EncodingFormatException("SSB first day of validity too big");
		}
		bits.putInteger(offset, 9, firstDayOfValidity);
		offset = offset + 9;
		
		if (lastDayOfValidity < 0 || lastDayOfValidity > 511) {
			throw new EncodingFormatException("SSB last day of validity too big");
		}
		bits.putInteger(offset, 9, lastDayOfValidity);
		offset = offset + 9;
		
		offset = stations.encode(offset, bytes);
		
		if (infoCode < 0 || infoCode > 9999) {
			throw new EncodingFormatException("SSB info code too big");
		}
		bits.putInteger(offset, 14, infoCode);
		offset = offset + 14;
		
		if (text.length() > 37) {
			throw new EncodingFormatException("SSB text too big");
		}
		bits.putChar6String(offset, 222, text);
		offset = offset + 222;
		
		return offset;
		
	}

	public int getFirstDayOfValidity() {
		return firstDayOfValidity;
	}

	public void setFirstDayOfValidity(int firstDayOfValidity) {
		this.firstDayOfValidity = firstDayOfValidity;
	}

	public int getLastDayOfValidity() {
		return lastDayOfValidity;
	}

	public void setLastDayOfValidity(int lastDayOfValidity) {
		this.lastDayOfValidity = lastDayOfValidity;
	}

	public boolean isReturnJourney() {
		return isReturnJourney;
	}

	public void setReturnJourney(boolean isReturnJourney) {
		this.isReturnJourney = isReturnJourney;
	}

	public int getInfoCode() {
		return infoCode;
	}

	public void setInfoCode(int infoCode) {
		this.infoCode = infoCode;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public SsbStations getStations() {
		return stations;
	}
	
	

}