File: Char4.java

package info (click to toggle)
pilot-link 0.8.7-2
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 2,256 kB
  • ctags: 3,233
  • sloc: ansic: 24,039; java: 2,162; cpp: 1,641; sh: 1,585; makefile: 1,363; perl: 723; yacc: 660; python: 239; tcl: 14
file content (66 lines) | stat: -rw-r--r-- 1,152 bytes parent folder | download | duplicates (2)
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

package Pdapilot;

public class Char4 {
	private int value;
	private byte[] b;
	
	public Char4(int id) {
		this.set(id);
	}

	public Char4(String id) {
		this.set(id);
	}

	public Char4(byte[] b) throws java.lang.CloneNotSupportedException {
		this.set(b);
	}
	
	public Char4() {
		this.set(0);
	}
	
	public void set(int id) {
		value = id;
		b = new byte[4];
		b[3] = (byte)(id & 0xff); id >>= 8;
		b[2] = (byte)(id & 0xff); id >>= 8;
		b[1] = (byte)(id & 0xff); id >>= 8;
		b[0] = (byte)(id & 0xff); id >>= 8;
	}

	public void set(String id) {
		byte[] by = id.getBytes();
		try {
			this.set(by);
		} catch(java.lang.CloneNotSupportedException e) {
			/* Don't be silly! */
		}
	}
	
	public void set(byte[] b) throws java.lang.CloneNotSupportedException{
		this.b = (byte[])b.clone();
		value = (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3];
	}
	
	public int getInt() {
		return value;
	}
	
	public byte[] getBytes() {
		return b;
	}

	public String getString() {
		return new String(b, 0, b.length);
	}
	
	public boolean equals(Char4 other) {
		return (value == other.value);
	}
	
	public String toString() {
		return Util.prettyPrint(b);
	}
}