forked from rampatra/Algorithms-and-Data-Structures-in-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMessage.java
70 lines (55 loc) · 1.63 KB
/
Message.java
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
package com.rampatra.blockchain;
import java.io.Serializable;
/**
* @author rampatra
* @since 2019-03-10
*/
public class Message implements Serializable {
enum MessageType {
REQUEST_LATEST_BLOCK,
RECEIVE_LATEST_BLOCK,
REQUEST_BLOCKCHAIN,
RECEIVE_BLOCKCHAIN
}
private MessageType messageType;
private Block latestBlock;
private Blockchain blockchain;
public MessageType getMessageType() {
return messageType;
}
public Block getLatestBlock() {
return latestBlock;
}
public Blockchain getBlockchain() {
return blockchain;
}
public static final class MessageBuilder {
private MessageType messageType;
private Block latestBlock;
private Blockchain blockchain;
private MessageBuilder() {
}
public static MessageBuilder aMessage() {
return new MessageBuilder();
}
public MessageBuilder withMessageType(MessageType messageType) {
this.messageType = messageType;
return this;
}
public MessageBuilder withLatestBlock(Block latestBlock) {
this.latestBlock = latestBlock;
return this;
}
public MessageBuilder withBlockchain(Blockchain blockchain) {
this.blockchain = blockchain;
return this;
}
public Message build() {
Message message = new Message();
message.latestBlock = this.latestBlock;
message.blockchain = this.blockchain;
message.messageType = this.messageType;
return message;
}
}
}