use of com.google.common.reflect.TypeToken in project retrofit by square.
the class RxJavaCallAdapterFactoryTest 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 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 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 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 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 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 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);
}
use of com.google.common.reflect.TypeToken in project retrofit by square.
the class GuavaCallAdapterFactoryTest method responseType.
@Test
public void responseType() {
Type bodyClass = new TypeToken<ListenableFuture<String>>() {
}.getType();
assertThat(factory.get(bodyClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
Type bodyWildcard = new TypeToken<ListenableFuture<? extends String>>() {
}.getType();
assertThat(factory.get(bodyWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
Type bodyGeneric = new TypeToken<ListenableFuture<List<String>>>() {
}.getType();
assertThat(factory.get(bodyGeneric, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(new TypeToken<List<String>>() {
}.getType());
Type responseClass = new TypeToken<ListenableFuture<Response<String>>>() {
}.getType();
assertThat(factory.get(responseClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
Type responseWildcard = new TypeToken<ListenableFuture<Response<? extends String>>>() {
}.getType();
assertThat(factory.get(responseWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
Type resultClass = new TypeToken<ListenableFuture<Response<String>>>() {
}.getType();
assertThat(factory.get(resultClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
Type resultWildcard = new TypeToken<ListenableFuture<Response<? extends String>>>() {
}.getType();
assertThat(factory.get(resultWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
}
use of com.google.common.reflect.TypeToken in project retrofit by square.
the class Java8CallAdapterFactoryTest method responseType.
@Test
public void responseType() {
Type bodyClass = new TypeToken<CompletableFuture<String>>() {
}.getType();
assertThat(factory.get(bodyClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
Type bodyWildcard = new TypeToken<CompletableFuture<? extends String>>() {
}.getType();
assertThat(factory.get(bodyWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
Type bodyGeneric = new TypeToken<CompletableFuture<List<String>>>() {
}.getType();
assertThat(factory.get(bodyGeneric, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(new TypeToken<List<String>>() {
}.getType());
Type responseClass = new TypeToken<CompletableFuture<Response<String>>>() {
}.getType();
assertThat(factory.get(responseClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
Type responseWildcard = new TypeToken<CompletableFuture<Response<? extends String>>>() {
}.getType();
assertThat(factory.get(responseWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
Type resultClass = new TypeToken<CompletableFuture<Response<String>>>() {
}.getType();
assertThat(factory.get(resultClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
Type resultWildcard = new TypeToken<CompletableFuture<Response<? extends String>>>() {
}.getType();
assertThat(factory.get(resultWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
}
use of com.google.common.reflect.TypeToken in project azure-tools-for-java by Microsoft.
the class SparkSubmitModel method tryToCreateBatchSparkJob.
private void tryToCreateBatchSparkJob(@NotNull final IClusterDetail selectedClusterDetail) throws HDIException, IOException {
SparkBatchSubmission.getInstance().setCredentialsProvider(selectedClusterDetail.getHttpUserName(), selectedClusterDetail.getHttpPassword());
HttpResponse response = SparkBatchSubmission.getInstance().createBatchSparkJob(SparkSubmitHelper.getLivyConnectionURL(selectedClusterDetail), submissionParameter);
if (response.getCode() == 201 || response.getCode() == 200) {
HDInsightUtil.showInfoOnSubmissionMessageWindow(project, "Info : Submit to spark cluster successfully.");
postEventProperty.put("IsSubmitSucceed", "true");
String jobLink = selectedClusterDetail.isEmulator() ? ((EmulatorClusterDetail) selectedClusterDetail).getSparkHistoryEndpoint() : String.format("%s/sparkhistory", selectedClusterDetail.getConnectionUrl());
HDInsightUtil.getSparkSubmissionToolWindowManager(project).setHyperLinkWithText("See spark job view from ", jobLink, jobLink);
SparkSubmitResponse sparkSubmitResponse = new Gson().fromJson(response.getMessage(), new TypeToken<SparkSubmitResponse>() {
}.getType());
// Set submitted spark application id and http request info for stopping running application
HDInsightUtil.getSparkSubmissionToolWindowManager(project).setSparkApplicationStopInfo(selectedClusterDetail, sparkSubmitResponse.getId());
HDInsightUtil.getSparkSubmissionToolWindowManager(project).setStopButtonState(true);
HDInsightUtil.getSparkSubmissionToolWindowManager(project).getJobStatusManager().resetJobStateManager();
SparkSubmitHelper.getInstance().printRunningLogStreamingly(project, sparkSubmitResponse.getId(), selectedClusterDetail, postEventProperty);
} else {
HDInsightUtil.showErrorMessageOnSubmissionMessageWindow(project, String.format("Error : Failed to submit to spark cluster. error code : %d, reason : %s.", response.getCode(), response.getContent()));
postEventProperty.put("IsSubmitSucceed", "false");
postEventProperty.put("SubmitFailedReason", response.getContent());
AppInsightsClient.create(HDInsightBundle.message("SparkSubmissionButtonClickEvent"), null, postEventProperty);
}
}
use of com.google.common.reflect.TypeToken in project pratilipi by Pratilipi.
the class PratilipiDocUtil method updatePratilipiGoogleAnalyticsPageViews.
public static List<Long> updatePratilipiGoogleAnalyticsPageViews(int year, int month, int day) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
BlobAccessor blobAccessor = DataAccessorFactory.getBlobAccessor();
Gson gson = new Gson();
String dateStr = year + (month < 10 ? "-0" + month : "-" + month) + (day < 10 ? "-0" + day : "-" + day);
String fileName = "pratilipi-google-analytics/page-views/" + dateStr;
BlobEntry blobEntry = blobAccessor.getBlob(fileName);
if (blobEntry == null) {
try {
blobEntry = blobAccessor.newBlob(fileName, "{}".getBytes("UTF-8"), "application/json");
} catch (UnsupportedEncodingException e) {
logger.log(Level.SEVERE, e.getMessage());
throw new UnexpectedServerException();
}
}
@SuppressWarnings("serial") Map<String, Integer> oldPageViewsMap = gson.fromJson(new String(blobEntry.getData(), Charset.forName("UTF-8")), new TypeToken<Map<String, Integer>>() {
}.getType());
Map<String, Integer> newPageViewsMap = GoogleAnalyticsApi.getPageViews(dateStr);
Map<String, Integer> diffPageViewsMap = new HashMap<>();
for (Entry<String, Integer> entry : newPageViewsMap.entrySet()) if (!entry.getValue().equals(oldPageViewsMap.get(entry.getKey())))
diffPageViewsMap.put(entry.getKey(), entry.getValue());
Map<Long, Integer> pageViewsMap = new HashMap<>();
Map<Long, Integer> readPageViewsMap = new HashMap<>();
for (Entry<String, Integer> entry : diffPageViewsMap.entrySet()) {
String uri = entry.getKey();
if (!uri.startsWith("/read?id=")) {
if (uri.indexOf('?') != -1)
uri = uri.substring(0, uri.indexOf('?'));
Page page = dataAccessor.getPage(uri);
if (page != null && page.getType() == PageType.PRATILIPI) {
Long pratilpiId = page.getPrimaryContentId();
if (pageViewsMap.get(pratilpiId) == null)
pageViewsMap.put(pratilpiId, entry.getValue());
else
pageViewsMap.put(pratilpiId, pageViewsMap.get(pratilpiId) + entry.getValue());
}
} else {
// Reader
String patilipiIdStr = uri.indexOf('&') == -1 ? uri.substring("/read?id=".length()) : uri.substring("/read?id=".length(), uri.indexOf('&'));
try {
Long pratilpiId = Long.parseLong(patilipiIdStr);
if (readPageViewsMap.get(pratilpiId) == null)
readPageViewsMap.put(pratilpiId, entry.getValue());
else
readPageViewsMap.put(pratilpiId, readPageViewsMap.get(pratilpiId) + entry.getValue());
} catch (NumberFormatException e) {
logger.log(Level.SEVERE, "Exception while processing reader uri " + uri, e);
}
}
}
for (Entry<Long, Integer> entry : pageViewsMap.entrySet()) {
if (readPageViewsMap.get(entry.getKey()) == null) {
updatePratilipiGoogleAnalyticsPageViews(entry.getKey(), year, month, day, entry.getValue(), 0);
} else {
updatePratilipiGoogleAnalyticsPageViews(entry.getKey(), year, month, day, entry.getValue(), readPageViewsMap.get(entry.getKey()));
readPageViewsMap.remove(entry.getKey());
}
}
for (Entry<Long, Integer> entry : readPageViewsMap.entrySet()) updatePratilipiGoogleAnalyticsPageViews(entry.getKey(), year, month, day, 0, entry.getValue());
if (diffPageViewsMap.size() > 0) {
try {
blobEntry.setData(gson.toJson(newPageViewsMap).getBytes("UTF-8"));
blobAccessor.createOrUpdateBlob(blobEntry);
} catch (UnsupportedEncodingException e) {
logger.log(Level.SEVERE, e.getMessage());
throw new UnexpectedServerException();
}
}
ArrayList<Long> updatedPratilipiIdList = new ArrayList<>(pageViewsMap.size() + readPageViewsMap.size());
updatedPratilipiIdList.addAll(pageViewsMap.keySet());
updatedPratilipiIdList.addAll(readPageViewsMap.keySet());
return updatedPratilipiIdList;
}
Aggregations