EMMA Coverage Report (generated Tue Dec 18 20:38:46 CET 2007)
[all classes][cz.vutbr.feec.packets.ttp]

## COVERAGE SUMMARY FOR SOURCE FILE [GeneralTTPHeader.java]

name | class, % | method, % | block, % | line, %
--- | --- | --- | --- | ---
GeneralTTPHeader.java | 100% (1/1) | 72% (13/18) | 54% (168/313) | 64% (38,7/60)

### COVERAGE BREAKDOWN BY CLASS AND METHOD

name | class, % | method, % | block, % | line, %
--- | --- | --- | --- | ---
class GeneralTTPHeader | 100% (1/1) | 72% (13/18) | 54% (168/313) | 64% (38,7/60)
compareTo (Object): int |  | 0% (0/1) | 0% (0/33) | 0% (0/6)
getPacketType (): int |  | 0% (0/1) | 0% (0/3) | 0% (0/1)
getPadding (): int |  | 0% (0/1) | 0% (0/3) | 0% (0/1)
hashCode (): int |  | 0% (0/1) | 0% (0/22) | 0% (0/3)
toString (): String |  | 0% (0/1) | 0% (0/26) | 0% (0/4)
generate (byte [], int): int |  | 100% (1/1) | 50% (51/101) | 58% (5,8/10)
<static initializer> |  | 100% (1/1) | 88% (7/8) | 87% (0,9/1)
parse (byte [], int, int): int |  | 100% (1/1) | 89% (39/44) | 89% (8/9)
equals (Object): boolean |  | 100% (1/1) | 95% (36/38) | 89% (8/9)
GeneralTTPHeader (int): void |  | 100% (1/1) | 100% (6/6) | 100% (3/3)
getFeedbackTreeId (): long |  | 100% (1/1) | 100% (3/3) | 100% (1/1)
getLength (): int |  | 100% (1/1) | 100% (3/3) | 100% (1/1)
getVersion (): int |  | 100% (1/1) | 100% (3/3) | 100% (1/1)
setFeedbackTreeId (long): void |  | 100% (1/1) | 100% (4/4) | 100% (2/2)
setLength (int): void |  | 100% (1/1) | 100% (4/4) | 100% (2/2)
setPacketType (int): void |  | 100% (1/1) | 100% (4/4) | 100% (2/2)
setPadding (int): void |  | 100% (1/1) | 100% (4/4) | 100% (2/2)
setVersion (int): void |  | 100% (1/1) | 100% (4/4) | 100% (2/2)

1 | package cz.vutbr.feec.packets.ttp;
2 |
3 | import cz.vutbr.feec.packets.IPacket;
4 | import cz.vutbr.feec.packets.PacketGenerateException;
5 | import cz.vutbr.feec.packets.PacketParseException;
6 | import cz.vutbr.feec.packets.PacketUtils;
7 | import org.apache.commons.lang.builder.ToStringBuilder;
8 | import org.apache.commons.lang.builder.CompareToBuilder;
9 | import org.apache.commons.lang.builder.EqualsBuilder;
10 | import org.apache.commons.lang.builder.HashCodeBuilder;
11 |
12 | public class GeneralTTPHeader implements IPacket {
13 | private int version;
14 |
15 | private int padding;
16 |
17 | private int packetType;
18 |
19 | private long feedbackTreeId;
20 |
21 | private int length;
22 |
23 | public GeneralTTPHeader(int packetType) {
24 | this.setPacketType(packetType);
25 | }
26 |
27 | public int generate(byte[] buffer, int offset)
28 | throws PacketGenerateException {
29 | assert PacketUtils.checkSize(version, 3);
30 | assert PacketUtils.checkSize(padding, 1);
31 | assert PacketUtils.checkSize(packetType, 4);
32 | assert PacketUtils.checkSize(packetType, 16);
33 | assert PacketUtils.checkSize(length, 8);
34 |
35 | byte V_P_T = (byte) ((version << 5) & 0xE0 | (padding << 4) & 0x10 | packetType & 0x0F);
36 | buffer[offset] = V_P_T;
37 |
38 | PacketUtils.setOctet2(buffer, offset + 1, this.getFeedbackTreeId());
39 | PacketUtils.setOctet1(buffer, offset + 3, this.getLength());
40 |
41 | // hlavicka zabere celkem 32 bitu
42 | return 4;
43 | }
44 |
45 | public int parse(byte[] resultArray, int startPos, int length)
46 | throws PacketParseException {
47 | if (length < 4) {
48 | throw new PacketParseException("Header is too short");
49 | }
50 | int first = PacketUtils.getOctet1(resultArray, startPos);
51 | this.setVersion((first & 0xE0) >> 5);
52 | this.setPadding((first & 0x10) >> 4);
53 | this.setPacketType(first & 0x0F);
54 | this.setFeedbackTreeId(PacketUtils.getOctet2(resultArray, 1));
55 | this.setLength(PacketUtils.getOctet1(resultArray, 3));
56 | return 4;
57 | }
58 |
59 | public int getVersion() {
60 | return this.version;
61 | }
62 |
63 | public void setVersion(int version) {
64 | this.version = version;
65 | }
66 |
67 | public int getPadding() {
68 | return this.padding;
69 | }
70 |
71 | public void setPadding(int padding) {
72 | this.padding = padding;
73 | }
74 |
75 | public int getPacketType() {
76 | return this.packetType;
77 | }
78 |
79 | public void setPacketType(int packetType) {
80 | this.packetType = packetType;
81 | }
82 |
83 | public long getFeedbackTreeId() {
84 | return this.feedbackTreeId;
85 | }
86 |
87 | public void setFeedbackTreeId(long feedbackTreeId) {
88 | this.feedbackTreeId = feedbackTreeId;
89 | }
90 |
91 | public int getLength() {
92 | return this.length;
93 | }
94 |
95 | public void setLength(int length) {
96 | this.length = length;
97 | }
98 |
99 | /**
100 | * @see java.lang.Object#toString()
101 | */
102 | public String toString() {
103 | return new ToStringBuilder(this).append("version", this.version)
104 | .append("padding", this.padding).append("packetType",
105 | this.packetType).append("length", this.length).append(
106 | "feedbackTreeId", this.feedbackTreeId).toString();
107 | }
108 |
109 | /**
110 | * @see java.lang.Comparable#compareTo(Object)
111 | */
112 | public int compareTo(Object object) {
113 | GeneralTTPHeader myClass = (GeneralTTPHeader) object;
114 | return new CompareToBuilder().append(this.packetType,
115 | myClass.packetType).append(this.length, myClass.length).append(
116 | this.padding, myClass.padding).append(this.feedbackTreeId,
117 | myClass.feedbackTreeId).append(this.version, myClass.version)
118 | .toComparison();
119 | }
120 |
121 | /**
122 | * @see java.lang.Object#equals(Object)
123 | */
124 | public boolean equals(Object object) {
125 | if (!(object instanceof GeneralTTPHeader)) {
126 | return false;
127 | }
128 | GeneralTTPHeader rhs = (GeneralTTPHeader) object;
129 | return new EqualsBuilder().append(
130 | this.packetType, rhs.packetType)
131 | .append(this.length, rhs.length).append(this.padding,
132 | rhs.padding).append(this.feedbackTreeId,
133 | rhs.feedbackTreeId).append(this.version, rhs.version)
134 | .isEquals();
135 | }
136 |
137 | /**
138 | * @see java.lang.Object#hashCode()
139 | */
140 | public int hashCode() {
141 | return new HashCodeBuilder(-2024644299, 591823357).append(this.packetType).append(this.length)
142 | .append(this.padding).append(this.feedbackTreeId).append(
143 | this.version).toHashCode();
144 | }
145 |
146 | }

[all classes][cz.vutbr.feec.packets.ttp]
EMMA 2.0.5312 EclEmma Fix 1 (C) Vladimir Roubtsov