-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWrapperIdea.java
92 lines (73 loc) · 2.65 KB
/
WrapperIdea.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* This is the basic idea as to how these Wrappers could work
** Essentially, its 'just' wrapping around googles autogenerated API for the individual proto file
** the just is in quotation marks because it's actually much more effort than one might expect....
*/
package com.uhh.code.polymorph;
public class Nice2 {
private Nice2() {}
public interface TestProtoGet
{
int getAuthVersion();
int getAuthProtocol();
int getChallengeNumber();
}
public class TestProto implements TestProtoGet
{
private Nice.TestProto wrappedMessage;
private TestProto() {}
protected TestProto(Nice.TestProto message)
{
this.wrappedMessage = message;
}
@Override
public int getAuthVersion() {
return Integer.parseInt(wrappedMessage.getAuthVersion());
}
@Override
public int getAuthProtocol() {
return Integer.parseInt(wrappedMessage.getAuthProtocol());
}
@Override
public int getChallengeNumber() {
return Integer.parseInt(wrappedMessage.getChallengeNumber());
}
public Builder newBuilder()
{
var originalBuilder = Nice.TestProto.newBuilder();
return new Nice2.TestProto.Builder(originalBuilder);
}
public class Builder implements Nice2.TestProtoGet
{
private Nice.TestProto.Builder wrappedBuilder;
protected Builder(Nice.TestProto.Builder builder)
{
this.wrappedBuilder = builder;
}
@Override
public int getAuthVersion() {
return Integer.parseInt(wrappedBuilder.getAuthVersion());
}
@Override
public int getAuthProtocol() {
return Integer.parseInt(wrappedBuilder.getAuthProtocol());
}
@Override
public int getChallengeNumber() {
return Integer.parseInt(wrappedBuilder.getChallengeNumber());
}
public void setAuthVersion(Integer authVersion) {
wrappedBuilder.setAuthVersion(String.valueOf(authVersion));
}
public void setAuthProtocol(Integer authProtocol) {
wrappedBuilder.setAuthProtocol(String.valueOf(authProtocol));
}
public void setChallengeNumber(Integer challengeNumber) {
wrappedBuilder.setChallengeNumber(String.valueOf(challengeNumber));
}
public Nice2.TestProto build()
{
return new Nice2.TestProto(wrappedBuilder.build());
}
}
}
}