Skip to content

Commit a79a6e5

Browse files
authored
fix: split search enum in different files to improve java generation (#104)
fix ci script thanks to @bodinsamuel
1 parent 76a11b3 commit a79a6e5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1441
-610
lines changed

clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/JSON.java

Lines changed: 460 additions & 0 deletions
Large diffs are not rendered by default.

clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/BatchDictionaryEntriesRequest.java

Lines changed: 5 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,33 @@
11
package com.algolia.model;
22

3-
import com.google.gson.TypeAdapter;
4-
import com.google.gson.annotations.JsonAdapter;
53
import com.google.gson.annotations.SerializedName;
6-
import com.google.gson.stream.JsonReader;
7-
import com.google.gson.stream.JsonWriter;
8-
import java.io.IOException;
94
import java.util.Objects;
105

116
/** BatchDictionaryEntriesRequest */
127
public class BatchDictionaryEntriesRequest {
138

14-
/** Actions to perform. */
15-
@JsonAdapter(ActionEnum.Adapter.class)
16-
public enum ActionEnum {
17-
ADDENTRY("addEntry"),
18-
19-
DELETEENTRY("deleteEntry");
20-
21-
private String value;
22-
23-
ActionEnum(String value) {
24-
this.value = value;
25-
}
26-
27-
public String getValue() {
28-
return value;
29-
}
30-
31-
@Override
32-
public String toString() {
33-
return String.valueOf(value);
34-
}
35-
36-
public static ActionEnum fromValue(String value) {
37-
for (ActionEnum b : ActionEnum.values()) {
38-
if (b.value.equals(value)) {
39-
return b;
40-
}
41-
}
42-
throw new IllegalArgumentException("Unexpected value '" + value + "'");
43-
}
44-
45-
public static class Adapter extends TypeAdapter<ActionEnum> {
46-
47-
@Override
48-
public void write(
49-
final JsonWriter jsonWriter,
50-
final ActionEnum enumeration
51-
) throws IOException {
52-
jsonWriter.value(enumeration.getValue());
53-
}
54-
55-
@Override
56-
public ActionEnum read(final JsonReader jsonReader) throws IOException {
57-
String value = jsonReader.nextString();
58-
return ActionEnum.fromValue(value);
59-
}
60-
}
61-
}
62-
639
@SerializedName("action")
64-
private ActionEnum action;
10+
private DictionaryAction action;
6511

6612
@SerializedName("body")
6713
private DictionaryEntry body;
6814

69-
public BatchDictionaryEntriesRequest action(ActionEnum action) {
15+
public BatchDictionaryEntriesRequest action(DictionaryAction action) {
7016
this.action = action;
7117
return this;
7218
}
7319

7420
/**
75-
* Actions to perform.
21+
* Get action
7622
*
7723
* @return action
7824
*/
7925
@javax.annotation.Nonnull
80-
public ActionEnum getAction() {
26+
public DictionaryAction getAction() {
8127
return action;
8228
}
8329

84-
public void setAction(ActionEnum action) {
30+
public void setAction(DictionaryAction action) {
8531
this.action = action;
8632
}
8733

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.algolia.model;
2+
3+
import com.google.gson.TypeAdapter;
4+
import com.google.gson.annotations.JsonAdapter;
5+
import com.google.gson.stream.JsonReader;
6+
import com.google.gson.stream.JsonWriter;
7+
import java.io.IOException;
8+
9+
/** Actions to perform. */
10+
@JsonAdapter(DictionaryAction.Adapter.class)
11+
public enum DictionaryAction {
12+
ADDENTRY("addEntry"),
13+
14+
DELETEENTRY("deleteEntry");
15+
16+
private String value;
17+
18+
DictionaryAction(String value) {
19+
this.value = value;
20+
}
21+
22+
public String getValue() {
23+
return value;
24+
}
25+
26+
@Override
27+
public String toString() {
28+
return String.valueOf(value);
29+
}
30+
31+
public static DictionaryAction fromValue(String value) {
32+
for (DictionaryAction b : DictionaryAction.values()) {
33+
if (b.value.equals(value)) {
34+
return b;
35+
}
36+
}
37+
throw new IllegalArgumentException("Unexpected value '" + value + "'");
38+
}
39+
40+
public static class Adapter extends TypeAdapter<DictionaryAction> {
41+
42+
@Override
43+
public void write(
44+
final JsonWriter jsonWriter,
45+
final DictionaryAction enumeration
46+
) throws IOException {
47+
jsonWriter.value(enumeration.getValue());
48+
}
49+
50+
@Override
51+
public DictionaryAction read(final JsonReader jsonReader)
52+
throws IOException {
53+
String value = jsonReader.nextString();
54+
return DictionaryAction.fromValue(value);
55+
}
56+
}
57+
}

clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/DictionaryEntry.java

Lines changed: 5 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
package com.algolia.model;
22

3-
import com.google.gson.TypeAdapter;
4-
import com.google.gson.annotations.JsonAdapter;
53
import com.google.gson.annotations.SerializedName;
6-
import com.google.gson.stream.JsonReader;
7-
import com.google.gson.stream.JsonWriter;
8-
import java.io.IOException;
94
import java.util.ArrayList;
105
import java.util.HashMap;
116
import java.util.List;
@@ -29,57 +24,8 @@ public class DictionaryEntry extends HashMap<String, Object> {
2924
@SerializedName("decomposition")
3025
private List<String> decomposition = null;
3126

32-
/** The state of the dictionary entry. */
33-
@JsonAdapter(StateEnum.Adapter.class)
34-
public enum StateEnum {
35-
ENABLED("enabled"),
36-
37-
DISABLED("disabled");
38-
39-
private String value;
40-
41-
StateEnum(String value) {
42-
this.value = value;
43-
}
44-
45-
public String getValue() {
46-
return value;
47-
}
48-
49-
@Override
50-
public String toString() {
51-
return String.valueOf(value);
52-
}
53-
54-
public static StateEnum fromValue(String value) {
55-
for (StateEnum b : StateEnum.values()) {
56-
if (b.value.equals(value)) {
57-
return b;
58-
}
59-
}
60-
throw new IllegalArgumentException("Unexpected value '" + value + "'");
61-
}
62-
63-
public static class Adapter extends TypeAdapter<StateEnum> {
64-
65-
@Override
66-
public void write(
67-
final JsonWriter jsonWriter,
68-
final StateEnum enumeration
69-
) throws IOException {
70-
jsonWriter.value(enumeration.getValue());
71-
}
72-
73-
@Override
74-
public StateEnum read(final JsonReader jsonReader) throws IOException {
75-
String value = jsonReader.nextString();
76-
return StateEnum.fromValue(value);
77-
}
78-
}
79-
}
80-
8127
@SerializedName("state")
82-
private StateEnum state = StateEnum.ENABLED;
28+
private DictionaryEntryState state = DictionaryEntryState.ENABLED;
8329

8430
public DictionaryEntry objectID(String objectID) {
8531
this.objectID = objectID;
@@ -192,22 +138,22 @@ public void setDecomposition(List<String> decomposition) {
192138
this.decomposition = decomposition;
193139
}
194140

195-
public DictionaryEntry state(StateEnum state) {
141+
public DictionaryEntry state(DictionaryEntryState state) {
196142
this.state = state;
197143
return this;
198144
}
199145

200146
/**
201-
* The state of the dictionary entry.
147+
* Get state
202148
*
203149
* @return state
204150
*/
205151
@javax.annotation.Nullable
206-
public StateEnum getState() {
152+
public DictionaryEntryState getState() {
207153
return state;
208154
}
209155

210-
public void setState(StateEnum state) {
156+
public void setState(DictionaryEntryState state) {
211157
this.state = state;
212158
}
213159

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.algolia.model;
2+
3+
import com.google.gson.TypeAdapter;
4+
import com.google.gson.annotations.JsonAdapter;
5+
import com.google.gson.stream.JsonReader;
6+
import com.google.gson.stream.JsonWriter;
7+
import java.io.IOException;
8+
9+
/** The state of the dictionary entry. */
10+
@JsonAdapter(DictionaryEntryState.Adapter.class)
11+
public enum DictionaryEntryState {
12+
ENABLED("enabled"),
13+
14+
DISABLED("disabled");
15+
16+
private String value;
17+
18+
DictionaryEntryState(String value) {
19+
this.value = value;
20+
}
21+
22+
public String getValue() {
23+
return value;
24+
}
25+
26+
@Override
27+
public String toString() {
28+
return String.valueOf(value);
29+
}
30+
31+
public static DictionaryEntryState fromValue(String value) {
32+
for (DictionaryEntryState b : DictionaryEntryState.values()) {
33+
if (b.value.equals(value)) {
34+
return b;
35+
}
36+
}
37+
throw new IllegalArgumentException("Unexpected value '" + value + "'");
38+
}
39+
40+
public static class Adapter extends TypeAdapter<DictionaryEntryState> {
41+
42+
@Override
43+
public void write(
44+
final JsonWriter jsonWriter,
45+
final DictionaryEntryState enumeration
46+
) throws IOException {
47+
jsonWriter.value(enumeration.getValue());
48+
}
49+
50+
@Override
51+
public DictionaryEntryState read(final JsonReader jsonReader)
52+
throws IOException {
53+
String value = jsonReader.nextString();
54+
return DictionaryEntryState.fromValue(value);
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)