com.neotys.neoload.model.v3.project.scenario.GsonAdaptersPopulationPolicy Maven / Gradle / Ivy
package com.neotys.neoload.model.v3.project.scenario;
import com.google.gson.*;
import com.google.gson.reflect.*;
import com.google.gson.stream.*;
import java.io.IOException;
import java.util.Optional;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.processing.Generated;
import org.immutables.gson.adapter.ExpectedSubtypesAdapter;
/**
* A {@code TypeAdapterFactory} that handles all of the immutable types generated under {@code PopulationPolicy}.
* @see ImmutablePopulationPolicy
*/
@SuppressWarnings({"all", "MethodCanBeStatic"})
@ParametersAreNonnullByDefault
@Generated("org.immutables.processor.ProxyProcessor")
@org.immutables.value.Generated(from = "com.neotys.neoload.model.v3.project.scenario", generator = "Gsons")
public final class GsonAdaptersPopulationPolicy implements TypeAdapterFactory {
@SuppressWarnings({"unchecked", "rawtypes"}) // safe unchecked, types are verified in runtime
@Override
public TypeAdapter create(Gson gson, TypeToken type) {
if (PopulationPolicyTypeAdapter.adapts(type)) {
return (TypeAdapter) new PopulationPolicyTypeAdapter(gson);
}
return null;
}
@Override
public String toString() {
return "GsonAdaptersPopulationPolicy(PopulationPolicy)";
}
@org.immutables.value.Generated(from = "PopulationPolicy", generator = "Gsons")
@SuppressWarnings({"unchecked", "rawtypes"}) // safe unchecked, types are verified in runtime
private static class PopulationPolicyTypeAdapter extends TypeAdapter {
public final LoadPolicy loadPolicyTypeSample = null;
private final TypeAdapter loadPolicyTypeAdapter;
PopulationPolicyTypeAdapter(Gson gson) {
this.loadPolicyTypeAdapter = ExpectedSubtypesAdapter.create(gson,
LoadPolicy.class,
TypeToken.get(CustomLoadPolicy.class),
TypeToken.get(ConstantLoadPolicy.class),
TypeToken.get(PeaksLoadPolicy.class),
TypeToken.get(RampupLoadPolicy.class));
}
static boolean adapts(TypeToken> type) {
return PopulationPolicy.class == type.getRawType()
|| ImmutablePopulationPolicy.class == type.getRawType();
}
@Override
public void write(JsonWriter out, PopulationPolicy value) throws IOException {
if (value == null) {
out.nullValue();
} else {
writePopulationPolicy(out, value);
}
}
@Override
public PopulationPolicy read(JsonReader in) throws IOException {
return readPopulationPolicy(in);
}
private void writePopulationPolicy(JsonWriter out, PopulationPolicy instance)
throws IOException {
out.beginObject();
String nameValue = instance.getName();
if (nameValue != null) {
out.name("name");
out.value(nameValue);
} else if (out.getSerializeNulls()) {
out.name("name");
out.nullValue();
}
Optional descriptionOptional = instance.getDescription();
if (descriptionOptional.isPresent()) {
out.name("description");
String descriptionValue = descriptionOptional.get();
out.value(descriptionValue);
} else if (out.getSerializeNulls()) {
out.name("description");
out.nullValue();
}
LoadPolicy loadPolicyValue = instance.getLoadPolicy();
if (loadPolicyValue != null) {
out.name("loadPolicy");
loadPolicyTypeAdapter.write(out, loadPolicyValue);
} else if (out.getSerializeNulls()) {
out.name("loadPolicy");
out.nullValue();
}
out.endObject();
}
private PopulationPolicy readPopulationPolicy(JsonReader in)
throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
PopulationPolicy.Builder builder = new PopulationPolicy.Builder();
in.beginObject();
while (in.hasNext()) {
eachAttribute(in, builder);
}
in.endObject();
return builder.build();
}
private void eachAttribute(JsonReader in, PopulationPolicy.Builder builder)
throws IOException {
String attributeName = in.nextName();
switch (attributeName.charAt(0)) {
case 'n':
if ("name".equals(attributeName)) {
readInName(in, builder);
return;
}
break;
case 'd':
if ("description".equals(attributeName)) {
readInDescription(in, builder);
return;
}
break;
case 'l':
if ("loadPolicy".equals(attributeName)) {
readInLoadPolicy(in, builder);
return;
}
break;
default:
}
in.skipValue();
}
private void readInName(JsonReader in, PopulationPolicy.Builder builder)
throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
} else {
builder.name(in.nextString());
}
}
private void readInDescription(JsonReader in, PopulationPolicy.Builder builder)
throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
} else {
builder.description(in.nextString());
}
}
private void readInLoadPolicy(JsonReader in, PopulationPolicy.Builder builder)
throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
} else {
LoadPolicy value = loadPolicyTypeAdapter.read(in);
builder.loadPolicy(value);
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy