All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.neotys.neoload.model.v3.project.scenario.GsonAdaptersRendezvousPolicy Maven / Gradle / Ivy

There is a newer version: 3.3.3
Show newest version
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 javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.processing.Generated;

/**
 * A {@code TypeAdapterFactory} that handles all of the immutable types generated under {@code RendezvousPolicy}.
 * @see ImmutableRendezvousPolicy
 */
@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 GsonAdaptersRendezvousPolicy implements TypeAdapterFactory {
  @SuppressWarnings({"unchecked", "rawtypes"}) // safe unchecked, types are verified in runtime
  @Override
  public  TypeAdapter create(Gson gson, TypeToken type) {
    if (RendezvousPolicyTypeAdapter.adapts(type)) {
      return (TypeAdapter) new RendezvousPolicyTypeAdapter(gson);
    }
    return null;
  }

  @Override
  public String toString() {
    return "GsonAdaptersRendezvousPolicy(RendezvousPolicy)";
  }

  @org.immutables.value.Generated(from = "RendezvousPolicy", generator = "Gsons")
  @SuppressWarnings({"unchecked", "rawtypes"}) // safe unchecked, types are verified in runtime
  private static class RendezvousPolicyTypeAdapter extends TypeAdapter {
    public final WhenRelease whenTypeSample = null;
    public final Integer timeoutTypeSample = null;
    private final TypeAdapter whenTypeAdapter;
    private final TypeAdapter timeoutTypeAdapter;

    RendezvousPolicyTypeAdapter(Gson gson) {
      this.whenTypeAdapter = gson.getAdapter( WhenRelease.class);
      this.timeoutTypeAdapter = gson.getAdapter( Integer.class);
    } 

    static boolean adapts(TypeToken type) {
      return RendezvousPolicy.class == type.getRawType()
          || ImmutableRendezvousPolicy.class == type.getRawType();
    }

    @Override
    public void write(JsonWriter out, RendezvousPolicy value) throws IOException {
      if (value == null) {
        out.nullValue();
      } else {
        writeRendezvousPolicy(out, value);
      }
    }

    @Override
    public RendezvousPolicy read(JsonReader in) throws IOException {
      return readRendezvousPolicy(in);
    }

    private void writeRendezvousPolicy(JsonWriter out, RendezvousPolicy 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();
      }
      out.name("when");
      whenTypeAdapter.write(out, instance.getWhen());
      out.name("timeout");
      timeoutTypeAdapter.write(out, instance.getTimeout());
      out.endObject();
    }

    private  RendezvousPolicy readRendezvousPolicy(JsonReader in)
        throws IOException {
      if (in.peek() == JsonToken.NULL) {
        in.nextNull();
        return null;
      }
      RendezvousPolicy.Builder builder = new RendezvousPolicy.Builder();
      in.beginObject();
      while (in.hasNext()) {
        eachAttribute(in, builder);
      }
      in.endObject();
      return builder.build();
    }

    private void eachAttribute(JsonReader in, RendezvousPolicy.Builder builder)
        throws IOException {
      String attributeName = in.nextName();
      switch (attributeName.charAt(0)) {
      case 'n':
        if ("name".equals(attributeName)) {
          readInName(in, builder);
          return;
        }
        break;
      case 'w':
        if ("when".equals(attributeName)) {
          readInWhen(in, builder);
          return;
        }
        break;
      case 't':
        if ("timeout".equals(attributeName)) {
          readInTimeout(in, builder);
          return;
        }
        break;
      default:
      }
      in.skipValue();
    }

    private void readInName(JsonReader in, RendezvousPolicy.Builder builder)
        throws IOException {
      if (in.peek() == JsonToken.NULL) {
        in.nextNull();
      } else {
        builder.name(in.nextString());
      }
    }

    private void readInWhen(JsonReader in, RendezvousPolicy.Builder builder)
        throws IOException {
      WhenRelease value = whenTypeAdapter.read(in);
      builder.when(value);
    }

    private void readInTimeout(JsonReader in, RendezvousPolicy.Builder builder)
        throws IOException {
      Integer value = timeoutTypeAdapter.read(in);
      builder.timeout(value);
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy