<commit_before>//
//  ApiHelper.java
//  blogwt
//
//  Created by billy1380 on 1 Aug 2013.
//  Copyright © 2013 WillShex Limited. All rights reserved.
//
package com.willshex.blogwt.client.helper;

import static com.google.gwt.user.client.Window.Location.getHost;

import com.google.gwt.core.shared.GWT;
import com.willshex.blogwt.client.DefaultEventBus;
import com.willshex.blogwt.client.api.blog.BlogService;
import com.willshex.blogwt.client.api.download.DownloadService;
import com.willshex.blogwt.client.api.page.PageService;
import com.willshex.blogwt.client.api.search.SearchService;
import com.willshex.blogwt.client.api.user.UserService;
import com.willshex.blogwt.shared.api.Request;
import com.willshex.blogwt.shared.api.datatype.DataType;
import com.willshex.blogwt.shared.api.validation.ApiError;
import com.willshex.gson.web.service.client.event.CallFailureEventHandler;
import com.willshex.gson.web.service.client.event.CallStartEventHandler;
import com.willshex.gson.web.service.client.event.CallSuccessEventHandler;
import com.willshex.gson.web.service.shared.Error;

/**
 * @author billy1380
 * 
 */
public class ApiHelper {

	public static final String ACCESS_CODE = "2bfe5f0e-9138-401c-8619-9a66f6367c9a";
	public static final String HOST = getHost();
	public static final String BASE_URL = "//" + HOST + "/";
	public static final String BLOG_END_POINT = BASE_URL + "blog";
	public static final String USER_END_POINT = BASE_URL + "user";
	public static final String PAGE_END_POINT = BASE_URL + "page";
	public static final String SEARCH_END_POINT = BASE_URL + "search";
	public static final String UPLOAD_END_POINT = BASE_URL + "upload";
	public static final String DOWNLOAD_END_POINT = BASE_URL + "download";

	static {
		DefaultEventBus.get().addHandler(CallStartEventHandler.TYPE,
				(origin, name, i, handle) -> {
					GWT.log("Calling " + origin.getUrl() + "." + name
							+ " with input [" + i + "].");
				});
		DefaultEventBus.get().addHandler(CallSuccessEventHandler.TYPE,
				(origin, name, i, o) -> {
					GWT.log("Call to " + origin.getUrl() + "." + name
							+ " with input [" + i + "] succeeded with output ["
							+ o + "].");
				});
		DefaultEventBus.get()
				.addHandler(CallFailureEventHandler.TYPE,
						(origin, name, i, caught) -> GWT.log(
								"Call to " + origin.getUrl() + "." + name
										+ " with input [" + i + "] failed.",
								caught));
	}

	public static BlogService createBlogClient () {
		BlogService service = new BlogService();
		service.setUrl(BLOG_END_POINT);
		service.setBus(DefaultEventBus.get());
		return service;
	}

	public static UserService createUserClient () {
		UserService service = new UserService();
		service.setUrl(USER_END_POINT);
		service.setBus(DefaultEventBus.get());
		return service;
	}

	public static PageService createPageClient () {
		PageService service = new PageService();
		service.setUrl(PAGE_END_POINT);
		service.setBus(DefaultEventBus.get());
		return service;
	}

	public static SearchService createSearchClient () {
		SearchService service = new SearchService();
		service.setUrl(SEARCH_END_POINT);
		service.setBus(DefaultEventBus.get());
		return service;
	}

	public static DownloadService createDownloadClient () {
		DownloadService service = new DownloadService();
		service.setUrl(DOWNLOAD_END_POINT);
		service.setBus(DefaultEventBus.get());
		return service;
	}

	public static <T extends Request> T setAccessCode (T input) {
		input.accessCode = ACCESS_CODE;
		return input;
	}

	/**
	 * @param error
	 * @param apiError
	 * @return
	 */
	public static boolean isError (Error error, ApiError apiError) {
		return error != null && error.code != null
				&& error.code.intValue() == apiError.getCode();
	}

	public static <T extends DataType> T dataType (T instance, Long id) {
		instance.id(id);
		return instance;
	}

}<commit_msg>create copy of data type with id only<commit_after>//
//  ApiHelper.java
//  blogwt
//
//  Created by billy1380 on 1 Aug 2013.
//  Copyright © 2013 WillShex Limited. All rights reserved.
//
package com.willshex.blogwt.client.helper;

import static com.google.gwt.user.client.Window.Location.getHost;

import com.google.gwt.core.shared.GWT;
import com.willshex.blogwt.client.DefaultEventBus;
import com.willshex.blogwt.client.api.blog.BlogService;
import com.willshex.blogwt.client.api.download.DownloadService;
import com.willshex.blogwt.client.api.page.PageService;
import com.willshex.blogwt.client.api.search.SearchService;
import com.willshex.blogwt.client.api.user.UserService;
import com.willshex.blogwt.shared.api.Request;
import com.willshex.blogwt.shared.api.datatype.DataType;
import com.willshex.blogwt.shared.api.validation.ApiError;
import com.willshex.gson.web.service.client.event.CallFailureEventHandler;
import com.willshex.gson.web.service.client.event.CallStartEventHandler;
import com.willshex.gson.web.service.client.event.CallSuccessEventHandler;
import com.willshex.gson.web.service.shared.Error;

/**
 * @author billy1380
 * 
 */
public class ApiHelper {

	public static final String ACCESS_CODE = "2bfe5f0e-9138-401c-8619-9a66f6367c9a";
	public static final String HOST = getHost();
	public static final String BASE_URL = "//" + HOST + "/";
	public static final String BLOG_END_POINT = BASE_URL + "blog";
	public static final String USER_END_POINT = BASE_URL + "user";
	public static final String PAGE_END_POINT = BASE_URL + "page";
	public static final String SEARCH_END_POINT = BASE_URL + "search";
	public static final String UPLOAD_END_POINT = BASE_URL + "upload";
	public static final String DOWNLOAD_END_POINT = BASE_URL + "download";

	static {
		DefaultEventBus.get().addHandler(CallStartEventHandler.TYPE,
				(origin, name, i, handle) -> {
					GWT.log("Calling " + origin.getUrl() + "." + name
							+ " with input [" + i + "].");
				});
		DefaultEventBus.get().addHandler(CallSuccessEventHandler.TYPE,
				(origin, name, i, o) -> {
					GWT.log("Call to " + origin.getUrl() + "." + name
							+ " with input [" + i + "] succeeded with output ["
							+ o + "].");
				});
		DefaultEventBus.get()
				.addHandler(CallFailureEventHandler.TYPE,
						(origin, name, i, caught) -> GWT.log(
								"Call to " + origin.getUrl() + "." + name
										+ " with input [" + i + "] failed.",
								caught));
	}

	public static BlogService createBlogClient () {
		BlogService service = new BlogService();
		service.setUrl(BLOG_END_POINT);
		service.setBus(DefaultEventBus.get());
		return service;
	}

	public static UserService createUserClient () {
		UserService service = new UserService();
		service.setUrl(USER_END_POINT);
		service.setBus(DefaultEventBus.get());
		return service;
	}

	public static PageService createPageClient () {
		PageService service = new PageService();
		service.setUrl(PAGE_END_POINT);
		service.setBus(DefaultEventBus.get());
		return service;
	}

	public static SearchService createSearchClient () {
		SearchService service = new SearchService();
		service.setUrl(SEARCH_END_POINT);
		service.setBus(DefaultEventBus.get());
		return service;
	}

	public static DownloadService createDownloadClient () {
		DownloadService service = new DownloadService();
		service.setUrl(DOWNLOAD_END_POINT);
		service.setBus(DefaultEventBus.get());
		return service;
	}

	public static <T extends Request> T setAccessCode (T input) {
		input.accessCode = ACCESS_CODE;
		return input;
	}

	/**
	 * @param error
	 * @param apiError
	 * @return
	 */
	public static boolean isError (Error error, ApiError apiError) {
		return error != null && error.code != null
				&& error.code.intValue() == apiError.getCode();
	}

	public static <T extends DataType> T dataType (T instance, Long id) {
		instance.id(id);
		return instance;
	}

	public static <T extends DataType> T idOnly (T forCall, T full) {
		forCall.id = full.id;
		return forCall;
	}
}
{'fraction_non_alphanumeric': 0.1257011728709842, 'fraction_numerical': 0.009943906170321265, 'mean_word_length': 4.120757180156658, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '936440', 'n_tokens_mistral': 2808, 'n_tokens_neox': 2537, 'n_words': 556}