/
ImmutableJavaScriptMessageMapperMapperOptions.java
174 lines (151 loc) · 6.25 KB
/
ImmutableJavaScriptMessageMapperMapperOptions.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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
* Copyright (c) 2017 Bosch Software Innovations GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/index.php
*
* Contributors:
* Bosch Software Innovations GmbH - initial contribution
*/
package org.eclipse.ditto.services.amqpbridge.mapping.mapper.javascript;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import javax.annotation.Nullable;
/**
* TODO doc
*/
final class ImmutableJavaScriptMessageMapperMapperOptions implements JavaScriptMessageMapperMapperOptions {
@Nullable private final String incomingMappingScript;
@Nullable private final String outgoingMappingScript;
private final boolean loadBytebufferJS;
private final boolean loadLongJS;
private final boolean loadMustacheJS;
ImmutableJavaScriptMessageMapperMapperOptions(@Nullable final String incomingMappingScript,
@Nullable final String outgoingMappingScript, final boolean loadBytebufferJS, final boolean loadLongJS,
final boolean loadMustacheJS) {
this.incomingMappingScript = incomingMappingScript;
this.outgoingMappingScript = outgoingMappingScript;
this.loadBytebufferJS = loadBytebufferJS;
this.loadLongJS = loadLongJS;
this.loadMustacheJS = loadMustacheJS;
}
@Override
public Optional<String> getIncomingMappingScript() {
return Optional.ofNullable(incomingMappingScript);
}
@Override
public Optional<String> getOutgoingMappingScript() {
return Optional.ofNullable(outgoingMappingScript);
}
@Override
public boolean isLoadBytebufferJS() {
return loadBytebufferJS;
}
@Override
public boolean isLoadLongJS() {
return loadLongJS;
}
@Override
public boolean isLoadMustacheJS() {
return loadMustacheJS;
}
@Override
public Map<String, String> getProperties() {
final Map<String, String> optionsMap = new HashMap<>();
optionsMap.put("incomingMappingScript", incomingMappingScript);
optionsMap.put("outgoingMappingScript", outgoingMappingScript);
optionsMap.put("loadBytebufferJS", Boolean.valueOf(loadBytebufferJS).toString());
optionsMap.put("loadLongJS", Boolean.valueOf(loadLongJS).toString());
optionsMap.put("loadMustacheJS", Boolean.valueOf(loadMustacheJS).toString());
return Collections.unmodifiableMap(optionsMap);
}
@Override
public boolean equals(@Nullable final Object o) {
if (this == o) {
return true;
}
if (!(o instanceof ImmutableJavaScriptMessageMapperMapperOptions)) {
return false;
}
final ImmutableJavaScriptMessageMapperMapperOptions that = (ImmutableJavaScriptMessageMapperMapperOptions) o;
return loadBytebufferJS == that.loadBytebufferJS &&
loadLongJS == that.loadLongJS &&
loadMustacheJS == that.loadMustacheJS &&
Objects.equals(incomingMappingScript, that.incomingMappingScript) &&
Objects.equals(outgoingMappingScript, that.outgoingMappingScript);
}
@Override
public int hashCode() {
return Objects.hash(incomingMappingScript, outgoingMappingScript, loadBytebufferJS, loadLongJS, loadMustacheJS);
}
@Override
public String toString() {
return getClass().getSimpleName() + " [" +
"incomingMappingScript=" + incomingMappingScript +
", outgoingMappingScript=" + outgoingMappingScript +
", loadBytebufferJS=" + loadBytebufferJS +
", loadLongJS=" + loadLongJS +
", loadMustacheJS=" + loadMustacheJS +
"]";
}
/**
*
*/
static final class Builder implements JavaScriptMessageMapperMapperOptions.Builder {
@Nullable private String incomingMappingScript;
@Nullable private String outgoingMappingScript;
private boolean loadBytebufferJS;
private boolean loadLongJS;
private boolean loadMustacheJS;
Builder(final Map<String, String> options) {
incomingMappingScript = Optional.ofNullable(options.get("incomingMappingScript"))
.orElse(null);
outgoingMappingScript = Optional.ofNullable(options.get("outgoingMappingScript"))
.orElse(null);
loadBytebufferJS = Optional.ofNullable(options.get("loadBytebufferJS"))
.map(Boolean::parseBoolean)
.orElse(false);
loadLongJS = Optional.ofNullable(options.get("loadLongJS"))
.map(Boolean::parseBoolean)
.orElse(false);
loadMustacheJS = Optional.ofNullable(options.get("loadMustacheJS"))
.map(Boolean::parseBoolean)
.orElse(false);
}
@Override
public JavaScriptMessageMapperMapperOptions.Builder incomingMappingScript(@Nullable final String mappingScript) {
incomingMappingScript = mappingScript;
return this;
}
@Override
public JavaScriptMessageMapperMapperOptions.Builder outgoingMappingScript(@Nullable final String mappingScript) {
outgoingMappingScript = mappingScript;
return this;
}
@Override
public JavaScriptMessageMapperMapperOptions.Builder loadBytebufferJS(final boolean load) {
loadBytebufferJS = load;
return this;
}
@Override
public JavaScriptMessageMapperMapperOptions.Builder loadLongJS(final boolean load) {
loadLongJS = load;
return this;
}
@Override
public JavaScriptMessageMapperMapperOptions.Builder loadMustacheJS(final boolean load) {
loadMustacheJS = load;
return this;
}
@Override
public JavaScriptMessageMapperMapperOptions build() {
return new ImmutableJavaScriptMessageMapperMapperOptions(incomingMappingScript, outgoingMappingScript,
loadBytebufferJS, loadLongJS, loadMustacheJS);
}
}
}