Skip to content

Commit 9d8f503

Browse files
committed
refactoring getter/setters for package index.get #2657
1 parent 73a447d commit 9d8f503

File tree

14 files changed

+93
-187
lines changed

14 files changed

+93
-187
lines changed

src/main/java/org/elasticsearch/action/get/GetResponse.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class GetResponse extends ActionResponse implements Iterable<GetField>, T
5454
* Does the document exists.
5555
*/
5656
public boolean exists() {
57-
return getResult.exists();
57+
return getResult.isExists();
5858
}
5959

6060
/**
@@ -68,7 +68,7 @@ public boolean isExists() {
6868
* The index the document was fetched from.
6969
*/
7070
public String index() {
71-
return getResult.index();
71+
return getResult.getIndex();
7272
}
7373

7474
/**
@@ -82,7 +82,7 @@ public String getIndex() {
8282
* The type of the document.
8383
*/
8484
public String type() {
85-
return getResult.type();
85+
return getResult.getType();
8686
}
8787

8888
/**
@@ -96,7 +96,7 @@ public String getType() {
9696
* The id of the document.
9797
*/
9898
public String id() {
99-
return getResult.id();
99+
return getResult.getId();
100100
}
101101

102102
/**
@@ -110,7 +110,7 @@ public String getId() {
110110
* The version of the doc.
111111
*/
112112
public long version() {
113-
return getResult.version();
113+
return getResult.getVersion();
114114
}
115115

116116
/**
@@ -179,7 +179,7 @@ public Map<String, Object> getSource() {
179179
}
180180

181181
public Map<String, GetField> fields() {
182-
return getResult.fields();
182+
return getResult.getFields();
183183
}
184184

185185
public Map<String, GetField> getFields() {

src/main/java/org/elasticsearch/action/mlt/TransportMoreLikeThisAction.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ public void onResponse(GetResponse getResponse) {
158158
String field = it.next();
159159
GetField getField = getResponse.field(field);
160160
if (getField != null) {
161-
for (Object value : getField.values()) {
162-
addMoreLikeThis(request, boolBuilder, getField.name(), value.toString());
161+
for (Object value : getField.getValues()) {
162+
addMoreLikeThis(request, boolBuilder, getField.getName(), value.toString());
163163
}
164164
it.remove();
165165
}

src/main/java/org/elasticsearch/action/update/TransportUpdateAction.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ protected void shardOperation(final UpdateRequest request, final ActionListener<
220220
new String[]{SourceFieldMapper.NAME, RoutingFieldMapper.NAME, ParentFieldMapper.NAME, TTLFieldMapper.NAME}, true);
221221

222222
// no doc, what to do, what to do...
223-
if (!getResult.exists()) {
223+
if (!getResult.isExists()) {
224224
if (request.upsertRequest() == null) {
225225
listener.onFailure(new DocumentMissingException(new ShardId(request.index(), request.shardId()), request.type(), request.id()));
226226
return;
@@ -283,8 +283,8 @@ public void run() {
283283
Object fetchedTTL = null;
284284
final Map<String, Object> updatedSourceAsMap;
285285
final XContentType updateSourceContentType = sourceAndContent.v1();
286-
String routing = getResult.fields().containsKey(RoutingFieldMapper.NAME) ? getResult.field(RoutingFieldMapper.NAME).value().toString() : null;
287-
String parent = getResult.fields().containsKey(ParentFieldMapper.NAME) ? getResult.field(ParentFieldMapper.NAME).value().toString() : null;
286+
String routing = getResult.getFields().containsKey(RoutingFieldMapper.NAME) ? getResult.field(RoutingFieldMapper.NAME).getValue().toString() : null;
287+
String parent = getResult.getFields().containsKey(ParentFieldMapper.NAME) ? getResult.field(ParentFieldMapper.NAME).getValue().toString() : null;
288288

289289
if (request.script() == null && request.doc() != null) {
290290
IndexRequest indexRequest = request.doc();
@@ -331,7 +331,7 @@ public void run() {
331331
// apply script to update the source
332332
// No TTL has been given in the update script so we keep previous TTL value if there is one
333333
if (ttl == null) {
334-
ttl = getResult.fields().containsKey(TTLFieldMapper.NAME) ? (Long) getResult.field(TTLFieldMapper.NAME).value() : null;
334+
ttl = getResult.getFields().containsKey(TTLFieldMapper.NAME) ? (Long) getResult.field(TTLFieldMapper.NAME).getValue() : null;
335335
if (ttl != null) {
336336
ttl = ttl - (System.currentTimeMillis() - getDate); // It is an approximation of exact TTL value, could be improved
337337
}
@@ -342,7 +342,7 @@ public void run() {
342342
if (operation == null || "index".equals(operation)) {
343343
final IndexRequest indexRequest = Requests.indexRequest(request.index()).type(request.type()).id(request.id()).routing(routing).parent(parent)
344344
.source(updatedSourceAsMap, updateSourceContentType)
345-
.version(getResult.version()).replicationType(request.replicationType()).consistencyLevel(request.consistencyLevel())
345+
.version(getResult.getVersion()).replicationType(request.replicationType()).consistencyLevel(request.consistencyLevel())
346346
.timestamp(timestamp).ttl(ttl)
347347
.percolate(request.percolate())
348348
.refresh(request.refresh());
@@ -377,7 +377,7 @@ public void run() {
377377
});
378378
} else if ("delete".equals(operation)) {
379379
DeleteRequest deleteRequest = Requests.deleteRequest(request.index()).type(request.type()).id(request.id()).routing(routing).parent(parent)
380-
.version(getResult.version()).replicationType(request.replicationType()).consistencyLevel(request.consistencyLevel());
380+
.version(getResult.getVersion()).replicationType(request.replicationType()).consistencyLevel(request.consistencyLevel());
381381
deleteRequest.operationThreaded(false);
382382
deleteAction.execute(deleteRequest, new ActionListener<DeleteResponse>() {
383383
@Override
@@ -405,12 +405,12 @@ public void run() {
405405
}
406406
});
407407
} else if ("none".equals(operation)) {
408-
UpdateResponse update = new UpdateResponse(getResult.index(), getResult.type(), getResult.id(), getResult.version());
409-
update.getResult(extractGetResult(request, getResult.version(), updatedSourceAsMap, updateSourceContentType, null));
408+
UpdateResponse update = new UpdateResponse(getResult.getIndex(), getResult.getType(), getResult.getId(), getResult.getVersion());
409+
update.getResult(extractGetResult(request, getResult.getVersion(), updatedSourceAsMap, updateSourceContentType, null));
410410
listener.onResponse(update);
411411
} else {
412412
logger.warn("Used update operation [{}] for script [{}], doing nothing...", operation, request.script);
413-
listener.onResponse(new UpdateResponse(getResult.index(), getResult.type(), getResult.id(), getResult.version()));
413+
listener.onResponse(new UpdateResponse(getResult.getIndex(), getResult.getType(), getResult.getId(), getResult.getVersion()));
414414
}
415415
}
416416

@@ -439,7 +439,7 @@ protected GetResult extractGetResult(final UpdateRequest request, long version,
439439
getField = new GetField(field, new ArrayList<Object>(2));
440440
fields.put(field, getField);
441441
}
442-
getField.values().add(value);
442+
getField.getValues().add(value);
443443
}
444444
}
445445
}

src/main/java/org/elasticsearch/index/get/GetField.java

+1-13
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,17 @@ public GetField(String name, List<Object> values) {
4646
this.values = values;
4747
}
4848

49-
public String name() {
50-
return name;
51-
}
52-
5349
public String getName() {
5450
return name;
5551
}
5652

57-
public Object value() {
53+
public Object getValue() {
5854
if (values != null && !values.isEmpty()) {
5955
return values.get(0);
6056
}
6157
return null;
6258
}
6359

64-
public Object getValue() {
65-
return value();
66-
}
67-
68-
public List<Object> values() {
69-
return values;
70-
}
71-
7260
public List<Object> getValues() {
7361
return values;
7462
}

src/main/java/org/elasticsearch/index/get/GetResult.java

+8-47
Original file line numberDiff line numberDiff line change
@@ -79,74 +79,39 @@ public GetResult(String index, String type, String id, long version, boolean exi
7979
}
8080
}
8181

82-
/**
83-
* Does the document exists.
84-
*/
85-
public boolean exists() {
86-
return exists;
87-
}
88-
8982
/**
9083
* Does the document exists.
9184
*/
9285
public boolean isExists() {
9386
return exists;
9487
}
9588

96-
/**
97-
* The index the document was fetched from.
98-
*/
99-
public String index() {
100-
return this.index;
101-
}
102-
10389
/**
10490
* The index the document was fetched from.
10591
*/
10692
public String getIndex() {
10793
return index;
10894
}
10995

110-
/**
111-
* The type of the document.
112-
*/
113-
public String type() {
114-
return type;
115-
}
116-
11796
/**
11897
* The type of the document.
11998
*/
12099
public String getType() {
121100
return type;
122101
}
123102

124-
/**
125-
* The id of the document.
126-
*/
127-
public String id() {
128-
return id;
129-
}
130-
131103
/**
132104
* The id of the document.
133105
*/
134106
public String getId() {
135107
return id;
136108
}
137109

138-
/**
139-
* The version of the doc.
140-
*/
141-
public long version() {
142-
return this.version;
143-
}
144-
145110
/**
146111
* The version of the doc.
147112
*/
148113
public long getVersion() {
149-
return this.version;
114+
return version;
150115
}
151116

152117
/**
@@ -224,10 +189,6 @@ public Map<String, Object> getSource() {
224189
return sourceAsMap();
225190
}
226191

227-
public Map<String, GetField> fields() {
228-
return this.fields;
229-
}
230-
231192
public Map<String, GetField> getFields() {
232193
return fields;
233194
}
@@ -263,15 +224,15 @@ public XContentBuilder toXContentEmbedded(XContentBuilder builder, Params params
263224
if (fields != null && !fields.isEmpty()) {
264225
builder.startObject(Fields.FIELDS);
265226
for (GetField field : fields.values()) {
266-
if (field.values().isEmpty()) {
227+
if (field.getValues().isEmpty()) {
267228
continue;
268229
}
269-
if (field.values().size() == 1) {
270-
builder.field(field.name(), field.values().get(0));
230+
if (field.getValues().size() == 1) {
231+
builder.field(field.getName(), field.getValues().get(0));
271232
} else {
272-
builder.field(field.name());
233+
builder.field(field.getName());
273234
builder.startArray();
274-
for (Object value : field.values()) {
235+
for (Object value : field.getValues()) {
275236
builder.value(value);
276237
}
277238
builder.endArray();
@@ -284,7 +245,7 @@ public XContentBuilder toXContentEmbedded(XContentBuilder builder, Params params
284245

285246
@Override
286247
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
287-
if (!exists()) {
248+
if (!isExists()) {
288249
builder.startObject();
289250
builder.field(Fields._INDEX, index);
290251
builder.field(Fields._TYPE, type);
@@ -331,7 +292,7 @@ public void readFrom(StreamInput in) throws IOException {
331292
fields = newHashMapWithExpectedSize(size);
332293
for (int i = 0; i < size; i++) {
333294
GetField field = readGetField(in);
334-
fields.put(field.name(), field);
295+
fields.put(field.getName(), field);
335296
}
336297
}
337298
}

0 commit comments

Comments
 (0)