Search in sources :

Example 81 with TypeToken

use of com.google.common.reflect.TypeToken in project azure-sdk-for-java by Azure.

the class VirtualMachineScaleSetsInner method deallocateWithServiceResponseAsync.

/**
     * Deallocates specific virtual machines in a VM scale set. Shuts down the virtual machines and releases the compute resources. You are not billed for the compute resources that this virtual machine scale set deallocates.
     *
     * @param resourceGroupName The name of the resource group.
     * @param vmScaleSetName The name of the VM scale set.
     * @param instanceIds The virtual machine scale set instance ids.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable for the request
     */
public Observable<ServiceResponse<OperationStatusResponseInner>> deallocateWithServiceResponseAsync(String resourceGroupName, String vmScaleSetName, List<String> instanceIds) {
    if (resourceGroupName == null) {
        throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.");
    }
    if (vmScaleSetName == null) {
        throw new IllegalArgumentException("Parameter vmScaleSetName is required and cannot be null.");
    }
    if (this.client.subscriptionId() == null) {
        throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.");
    }
    Validator.validate(instanceIds);
    final String apiVersion = "2016-04-30-preview";
    VirtualMachineScaleSetVMInstanceIDs vmInstanceIDs = null;
    if (instanceIds != null) {
        vmInstanceIDs = new VirtualMachineScaleSetVMInstanceIDs();
        vmInstanceIDs.withInstanceIds(instanceIds);
    }
    Observable<Response<ResponseBody>> observable = service.deallocate(resourceGroupName, vmScaleSetName, this.client.subscriptionId(), apiVersion, this.client.acceptLanguage(), vmInstanceIDs, this.client.userAgent());
    return client.getAzureClient().getPostOrDeleteResultAsync(observable, new TypeToken<OperationStatusResponseInner>() {
    }.getType());
}
Also used : Response(retrofit2.Response) ServiceResponse(com.microsoft.rest.ServiceResponse) VirtualMachineScaleSetVMInstanceIDs(com.microsoft.azure.management.compute.VirtualMachineScaleSetVMInstanceIDs) TypeToken(com.google.common.reflect.TypeToken)

Example 82 with TypeToken

use of com.google.common.reflect.TypeToken in project retrofit by square.

the class CallAdapterTest method parameterizedTypes.

@Test
public void parameterizedTypes() {
    ParameterizedType one = (ParameterizedType) new TypeToken<List<String>>() {
    }.getType();
    assertThat(getParameterUpperBound(0, one)).isSameAs(String.class);
    ParameterizedType two = (ParameterizedType) new TypeToken<Map<String, String>>() {
    }.getType();
    assertThat(getParameterUpperBound(0, two)).isSameAs(String.class);
    assertThat(getParameterUpperBound(1, two)).isSameAs(String.class);
    ParameterizedType wild = (ParameterizedType) new TypeToken<List<? extends CharSequence>>() {
    }.getType();
    assertThat(getParameterUpperBound(0, wild)).isSameAs(CharSequence.class);
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) TypeToken(com.google.common.reflect.TypeToken) Test(org.junit.Test)

Example 83 with TypeToken

use of com.google.common.reflect.TypeToken in project retrofit by square.

the class ExecutorCallAdapterFactoryTest method responseType.

@Test
public void responseType() {
    Type classType = new TypeToken<Call<String>>() {
    }.getType();
    assertThat(factory.get(classType, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type wilcardType = new TypeToken<Call<? extends String>>() {
    }.getType();
    assertThat(factory.get(wilcardType, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type genericType = new TypeToken<Call<List<String>>>() {
    }.getType();
    assertThat(factory.get(genericType, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(new TypeToken<List<String>>() {
    }.getType());
}
Also used : Type(java.lang.reflect.Type) TypeToken(com.google.common.reflect.TypeToken) Test(org.junit.Test)

Example 84 with TypeToken

use of com.google.common.reflect.TypeToken in project retrofit by square.

the class RxJava2CallAdapterFactoryTest method responseTypes.

@Test
public void responseTypes() {
    Type oBodyClass = new TypeToken<Observable<String>>() {
    }.getType();
    assertThat(factory.get(oBodyClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type sBodyClass = new TypeToken<Single<String>>() {
    }.getType();
    assertThat(factory.get(sBodyClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type mBodyClass = new TypeToken<Maybe<String>>() {
    }.getType();
    assertThat(factory.get(sBodyClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type fBodyClass = new TypeToken<Flowable<String>>() {
    }.getType();
    assertThat(factory.get(sBodyClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type oBodyWildcard = new TypeToken<Observable<? extends String>>() {
    }.getType();
    assertThat(factory.get(oBodyWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type sBodyWildcard = new TypeToken<Single<? extends String>>() {
    }.getType();
    assertThat(factory.get(sBodyWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type mBodyWildcard = new TypeToken<Maybe<? extends String>>() {
    }.getType();
    assertThat(factory.get(sBodyWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type fBodyWildcard = new TypeToken<Flowable<? extends String>>() {
    }.getType();
    assertThat(factory.get(sBodyWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type oBodyGeneric = new TypeToken<Observable<List<String>>>() {
    }.getType();
    assertThat(factory.get(oBodyGeneric, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(new TypeToken<List<String>>() {
    }.getType());
    Type sBodyGeneric = new TypeToken<Single<List<String>>>() {
    }.getType();
    assertThat(factory.get(sBodyGeneric, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(new TypeToken<List<String>>() {
    }.getType());
    Type mBodyGeneric = new TypeToken<Maybe<List<String>>>() {
    }.getType();
    assertThat(factory.get(sBodyGeneric, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(new TypeToken<List<String>>() {
    }.getType());
    Type fBodyGeneric = new TypeToken<Flowable<List<String>>>() {
    }.getType();
    assertThat(factory.get(sBodyGeneric, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(new TypeToken<List<String>>() {
    }.getType());
    Type oResponseClass = new TypeToken<Observable<Response<String>>>() {
    }.getType();
    assertThat(factory.get(oResponseClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type sResponseClass = new TypeToken<Single<Response<String>>>() {
    }.getType();
    assertThat(factory.get(sResponseClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type mResponseClass = new TypeToken<Maybe<Response<String>>>() {
    }.getType();
    assertThat(factory.get(sResponseClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type fResponseClass = new TypeToken<Flowable<Response<String>>>() {
    }.getType();
    assertThat(factory.get(sResponseClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type oResponseWildcard = new TypeToken<Observable<Response<? extends String>>>() {
    }.getType();
    assertThat(factory.get(oResponseWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type sResponseWildcard = new TypeToken<Single<Response<? extends String>>>() {
    }.getType();
    assertThat(factory.get(sResponseWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type mResponseWildcard = new TypeToken<Maybe<Response<? extends String>>>() {
    }.getType();
    assertThat(factory.get(sResponseWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type fResponseWildcard = new TypeToken<Flowable<Response<? extends String>>>() {
    }.getType();
    assertThat(factory.get(sResponseWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type oResultClass = new TypeToken<Observable<Result<String>>>() {
    }.getType();
    assertThat(factory.get(oResultClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type sResultClass = new TypeToken<Single<Result<String>>>() {
    }.getType();
    assertThat(factory.get(sResultClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type mResultClass = new TypeToken<Maybe<Result<String>>>() {
    }.getType();
    assertThat(factory.get(sResultClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type fResultClass = new TypeToken<Flowable<Result<String>>>() {
    }.getType();
    assertThat(factory.get(sResultClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type oResultWildcard = new TypeToken<Observable<Result<? extends String>>>() {
    }.getType();
    assertThat(factory.get(oResultWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type sResultWildcard = new TypeToken<Single<Result<? extends String>>>() {
    }.getType();
    assertThat(factory.get(sResultWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type mResultWildcard = new TypeToken<Maybe<Result<? extends String>>>() {
    }.getType();
    assertThat(factory.get(sResultWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type fResultWildcard = new TypeToken<Flowable<Result<? extends String>>>() {
    }.getType();
    assertThat(factory.get(sResultWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
}
Also used : Maybe(io.reactivex.Maybe) Observable(io.reactivex.Observable) Type(java.lang.reflect.Type) Single(io.reactivex.Single) TypeToken(com.google.common.reflect.TypeToken) Flowable(io.reactivex.Flowable) Test(org.junit.Test)

Example 85 with TypeToken

use of com.google.common.reflect.TypeToken in project EventHub by Codecademy.

the class BatchTrackEvent method execute.

@Override
public synchronized void execute(final HttpServletRequest request, final HttpServletResponse response) throws IOException {
    List<Map<String, String>> events = gson.fromJson(request.getParameter("events"), new TypeToken<List<Map<String, String>>>() {
    }.getType());
    List<Long> eventIds = Lists.newArrayList();
    PrintWriter writer = response.getWriter();
    for (Map<String, String> eventMap : events) {
        String date = eventMap.get("date");
        if (date == null) {
            date = dateHelper.getDate();
        }
        Event event = new Event.Builder(eventMap.get("event_type"), eventMap.get("external_user_id"), date, eventMap).build();
        eventIds.add(eventHub.addEvent(event));
    }
    writer.println(gson.toJson(eventIds));
}
Also used : TypeToken(com.google.common.reflect.TypeToken) Event(com.codecademy.eventhub.model.Event) Map(java.util.Map) PrintWriter(java.io.PrintWriter)

Aggregations

TypeToken (com.google.common.reflect.TypeToken)135 Test (org.junit.Test)60 HttpResponse (co.cask.common.http.HttpResponse)26 URL (java.net.URL)24 ServiceResponse (com.microsoft.rest.ServiceResponse)22 Response (retrofit2.Response)22 BinaryEncoder (co.cask.cdap.common.io.BinaryEncoder)18 BinaryDecoder (co.cask.cdap.common.io.BinaryDecoder)17 PipedInputStream (java.io.PipedInputStream)17 PipedOutputStream (java.io.PipedOutputStream)17 ReflectionDatumReader (co.cask.cdap.internal.io.ReflectionDatumReader)16 List (java.util.List)16 Map (java.util.Map)11 ImmutableList (com.google.common.collect.ImmutableList)9 Type (java.lang.reflect.Type)9 AbstractViewTest (org.corfudb.runtime.view.AbstractViewTest)9 NotFoundException (co.cask.cdap.common.NotFoundException)8 VirtualMachineScaleSetVMInstanceIDs (com.microsoft.azure.management.compute.VirtualMachineScaleSetVMInstanceIDs)8 Gson (com.google.gson.Gson)7 JsonObject (com.google.gson.JsonObject)7