Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: split search enum in different files to improve java generation #104

Merged
merged 4 commits into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,87 +1,33 @@
package com.algolia.model;

import com.google.gson.TypeAdapter;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.util.Objects;

/** BatchDictionaryEntriesRequest */
public class BatchDictionaryEntriesRequest {

/** Actions to perform. */
@JsonAdapter(ActionEnum.Adapter.class)
public enum ActionEnum {
ADDENTRY("addEntry"),

DELETEENTRY("deleteEntry");

private String value;

ActionEnum(String value) {
this.value = value;
}

public String getValue() {
return value;
}

@Override
public String toString() {
return String.valueOf(value);
}

public static ActionEnum fromValue(String value) {
for (ActionEnum b : ActionEnum.values()) {
if (b.value.equals(value)) {
return b;
}
}
throw new IllegalArgumentException("Unexpected value '" + value + "'");
}

public static class Adapter extends TypeAdapter<ActionEnum> {

@Override
public void write(
final JsonWriter jsonWriter,
final ActionEnum enumeration
) throws IOException {
jsonWriter.value(enumeration.getValue());
}

@Override
public ActionEnum read(final JsonReader jsonReader) throws IOException {
String value = jsonReader.nextString();
return ActionEnum.fromValue(value);
}
}
}

@SerializedName("action")
private ActionEnum action;
private DictionaryAction action;

@SerializedName("body")
private DictionaryEntry body;

public BatchDictionaryEntriesRequest action(ActionEnum action) {
public BatchDictionaryEntriesRequest action(DictionaryAction action) {
this.action = action;
return this;
}

/**
* Actions to perform.
* Get action
*
* @return action
*/
@javax.annotation.Nonnull
public ActionEnum getAction() {
public DictionaryAction getAction() {
return action;
}

public void setAction(ActionEnum action) {
public void setAction(DictionaryAction action) {
this.action = action;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.algolia.model;

import com.google.gson.TypeAdapter;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;

/** Actions to perform. */
@JsonAdapter(DictionaryAction.Adapter.class)
public enum DictionaryAction {
ADDENTRY("addEntry"),

DELETEENTRY("deleteEntry");

private String value;

DictionaryAction(String value) {
this.value = value;
}

public String getValue() {
return value;
}

@Override
public String toString() {
return String.valueOf(value);
}

public static DictionaryAction fromValue(String value) {
for (DictionaryAction b : DictionaryAction.values()) {
if (b.value.equals(value)) {
return b;
}
}
throw new IllegalArgumentException("Unexpected value '" + value + "'");
}

public static class Adapter extends TypeAdapter<DictionaryAction> {

@Override
public void write(
final JsonWriter jsonWriter,
final DictionaryAction enumeration
) throws IOException {
jsonWriter.value(enumeration.getValue());
}

@Override
public DictionaryAction read(final JsonReader jsonReader)
throws IOException {
String value = jsonReader.nextString();
return DictionaryAction.fromValue(value);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package com.algolia.model;

import com.google.gson.TypeAdapter;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -29,57 +24,8 @@ public class DictionaryEntry extends HashMap<String, Object> {
@SerializedName("decomposition")
private List<String> decomposition = null;

/** The state of the dictionary entry. */
@JsonAdapter(StateEnum.Adapter.class)
public enum StateEnum {
ENABLED("enabled"),

DISABLED("disabled");

private String value;

StateEnum(String value) {
this.value = value;
}

public String getValue() {
return value;
}

@Override
public String toString() {
return String.valueOf(value);
}

public static StateEnum fromValue(String value) {
for (StateEnum b : StateEnum.values()) {
if (b.value.equals(value)) {
return b;
}
}
throw new IllegalArgumentException("Unexpected value '" + value + "'");
}

public static class Adapter extends TypeAdapter<StateEnum> {

@Override
public void write(
final JsonWriter jsonWriter,
final StateEnum enumeration
) throws IOException {
jsonWriter.value(enumeration.getValue());
}

@Override
public StateEnum read(final JsonReader jsonReader) throws IOException {
String value = jsonReader.nextString();
return StateEnum.fromValue(value);
}
}
}

@SerializedName("state")
private StateEnum state = StateEnum.ENABLED;
private DictionaryEntryState state = DictionaryEntryState.ENABLED;

public DictionaryEntry objectID(String objectID) {
this.objectID = objectID;
Expand Down Expand Up @@ -192,22 +138,22 @@ public void setDecomposition(List<String> decomposition) {
this.decomposition = decomposition;
}

public DictionaryEntry state(StateEnum state) {
public DictionaryEntry state(DictionaryEntryState state) {
this.state = state;
return this;
}

/**
* The state of the dictionary entry.
* Get state
*
* @return state
*/
@javax.annotation.Nullable
public StateEnum getState() {
public DictionaryEntryState getState() {
return state;
}

public void setState(StateEnum state) {
public void setState(DictionaryEntryState state) {
this.state = state;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.algolia.model;

import com.google.gson.TypeAdapter;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;

/** The state of the dictionary entry. */
@JsonAdapter(DictionaryEntryState.Adapter.class)
public enum DictionaryEntryState {
ENABLED("enabled"),

DISABLED("disabled");

private String value;

DictionaryEntryState(String value) {
this.value = value;
}

public String getValue() {
return value;
}

@Override
public String toString() {
return String.valueOf(value);
}

public static DictionaryEntryState fromValue(String value) {
for (DictionaryEntryState b : DictionaryEntryState.values()) {
if (b.value.equals(value)) {
return b;
}
}
throw new IllegalArgumentException("Unexpected value '" + value + "'");
}

public static class Adapter extends TypeAdapter<DictionaryEntryState> {

@Override
public void write(
final JsonWriter jsonWriter,
final DictionaryEntryState enumeration
) throws IOException {
jsonWriter.value(enumeration.getValue());
}

@Override
public DictionaryEntryState read(final JsonReader jsonReader)
throws IOException {
String value = jsonReader.nextString();
return DictionaryEntryState.fromValue(value);
}
}
}
Loading