<commit_before>package {{{packagename}}}.tasks.{{{message.serviceNameLower}}};

import android.os.AsyncTask;
import android.os.Build;

import {{{staticPackage}}}.utils.ResponseInfo;
import {{{staticPackage}}}.logic.OnLoadingListener;
import {{{staticPackage}}}.logic.ServiceException;
import {{{staticPackage}}}.logic.TaskListener;

import {{{packagename}}}.logic.{{{message.service}}}Logic;
import {{{packagename}}}.model.dto.{{{message.request.name}}};
import {{{packagename}}}.model.dto.{{{message.response.name}}};

/**
 * {{{message.method}}} AsyncTask
 *
 * @author Service Generator
 * 
 * Generated Class - DO NOT MODIFY
 */
public class {{{message.methodUpperCase}}}Task {

    private OnLoadingListener onLoadingListener;
    private TaskListener<{{{message.request.name}}},{{{message.response.name}}}> taskListener;
    private {{{message.methodUpperCase}}}InnerTask innerTask;

    private {{{message.methodUpperCase}}}Task() {
    }

    public static {{{message.methodUpperCase}}}Task build() {
        return new {{{message.methodUpperCase}}}Task();
    }

    public {{{message.methodUpperCase}}}Task loadingListener(OnLoadingListener listener) {
        this.onLoadingListener = listener;
        return this;
    }

    public {{{message.methodUpperCase}}}InnerTask getInnerTask() {
        return innerTask;
    }

    public void execute({{{message.request.name}}} request) {

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.DONUT) {
            throw new UnsupportedOperationException("This class can only be used on API 4 and newer.");
        }
        innerTask = new {{{message.methodUpperCase}}}InnerTask(taskListener, onLoadingListener);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            innerTask.execute(request);
        } else {
            innerTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, request);
        }
    }

    public void execute({{{message.request.name}}} request, TaskListener<{{{message.request.name}}}, {{{message.response.name}}}> listener) {
        this.taskListener = listener;
        this.execute(request);
    }

    public class {{{message.methodUpperCase}}}InnerTaskResponse {
        private ResponseInfo responseInfo;
        private {{{message.request.name}}} request;
        private {{{message.response.name}}} response;
        private Exception exception;

        public {{{message.methodUpperCase}}}InnerTaskResponse({{{message.request.name}}} request) {
            this.request = request;
        }

        public ResponseInfo getResponseInfo() {
            return responseInfo;
        }

        public void setResponseInfo(ResponseInfo responseInfo) {
            this.responseInfo = responseInfo;
        }

        public {{{message.request.name}}} getRequest() {
            return request;
        }

        public void setRequest({{{message.request.name}}} request) {
            this.request = request;
        }

        public {{{message.response.name}}} getResponse() {
            return response;
        }

        public void setResponse({{{message.response.name}}} response) {
            this.response = response;
        }

        public Exception getException() {
            return exception;
        }

        public void setException(Exception exception) {
            this.exception = exception;
        }
    }

    public class {{{message.methodUpperCase}}}InnerTask extends AsyncTask<{{{message.request.name}}},Integer, {{{message.methodUpperCase}}}InnerTaskResponse> {

        private TaskListener<{{{message.request.name}}},{{{message.response.name}}}> taskListener;
        private OnLoadingListener serviceWorkingListener;

        public {{{message.methodUpperCase}}}InnerTask(TaskListener<{{{message.request.name}}},{{{message.response.name}}}> taskListener, OnLoadingListener serviceWorkingListener) {
            this.taskListener = taskListener;
            this.serviceWorkingListener = serviceWorkingListener;
        }

        @Override
        protected {{{message.methodUpperCase}}}InnerTaskResponse doInBackground({{{message.request.name}}}... params) {
            final {{{message.request.name}}} request = params[0];

            {{{message.methodUpperCase}}}InnerTaskResponse taskResponse = new {{{message.methodUpperCase}}}InnerTaskResponse(request);
            ResponseInfo responseInfo = new ResponseInfo();
            taskResponse.setResponseInfo(responseInfo);

            try {
                final {{{message.response.name}}} response = {{{message.service}}}Logic.getInstance().{{{message.method}}}(request, responseInfo);
                taskResponse.setResponse(response);
            } catch (ServiceException e) {
                e.printStackTrace();
                taskResponse.setException(e);
            }
            return taskResponse;
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            if (serviceWorkingListener != null) {
                serviceWorkingListener.onLoadingStarted();
            }
        }

        @Override
        protected void onPostExecute({{{message.methodUpperCase}}}InnerTaskResponse response) {
            super.onPostExecute(response);

            if (taskListener != null) {

                if (response.getException() != null) {
                    taskListener.onServiceError(response.getRequest(), response.getException());
                } else {
                    taskListener.onServiceResponse(response.getRequest(), response.getResponse(), response.getResponseInfo());
                }
            }

            if (serviceWorkingListener != null) {
                serviceWorkingListener.onLoadingFinished();
            }
        }
    }

}


<commit_msg>Added a background-thread calling check to the execute method for tasks<commit_after>package {{{packagename}}}.tasks.{{{message.serviceNameLower}}};

import android.os.AsyncTask;
import android.os.Build;
import android.os.Looper;

import {{{staticPackage}}}.utils.ResponseInfo;
import {{{staticPackage}}}.logic.OnLoadingListener;
import {{{staticPackage}}}.logic.ServiceException;
import {{{staticPackage}}}.logic.TaskListener;

import {{{packagename}}}.logic.{{{message.service}}}Logic;
import {{{packagename}}}.model.dto.{{{message.request.name}}};
import {{{packagename}}}.model.dto.{{{message.response.name}}};

/**
 * {{{message.method}}} AsyncTask
 *
 * @author Service Generator
 * 
 * Generated Class - DO NOT MODIFY
 */
public class {{{message.methodUpperCase}}}Task {

    private OnLoadingListener onLoadingListener;
    private TaskListener<{{{message.request.name}}},{{{message.response.name}}}> taskListener;
    private {{{message.methodUpperCase}}}InnerTask innerTask;

    private {{{message.methodUpperCase}}}Task() {
    }

    public static {{{message.methodUpperCase}}}Task build() {
        return new {{{message.methodUpperCase}}}Task();
    }

    public {{{message.methodUpperCase}}}Task loadingListener(OnLoadingListener listener) {
        this.onLoadingListener = listener;
        return this;
    }

    public {{{message.methodUpperCase}}}InnerTask getInnerTask() {
        return innerTask;
    }

    public void execute({{{message.request.name}}} request) {

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.DONUT) {
            throw new UnsupportedOperationException("This class can only be used on API 4 and newer.");
        }

        if (Thread.currentThread() != Looper.getMainLooper().getThread()) {
            throw new IllegalStateException("This method should be called from the main Thread");
        }

        innerTask = new {{{message.methodUpperCase}}}InnerTask(taskListener, onLoadingListener);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            innerTask.execute(request);
        } else {
            innerTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, request);
        }
    }

    public void execute({{{message.request.name}}} request, TaskListener<{{{message.request.name}}}, {{{message.response.name}}}> listener) {
        this.taskListener = listener;
        this.execute(request);
    }

    public class {{{message.methodUpperCase}}}InnerTaskResponse {
        private ResponseInfo responseInfo;
        private {{{message.request.name}}} request;
        private {{{message.response.name}}} response;
        private Exception exception;

        public {{{message.methodUpperCase}}}InnerTaskResponse({{{message.request.name}}} request) {
            this.request = request;
        }

        public ResponseInfo getResponseInfo() {
            return responseInfo;
        }

        public void setResponseInfo(ResponseInfo responseInfo) {
            this.responseInfo = responseInfo;
        }

        public {{{message.request.name}}} getRequest() {
            return request;
        }

        public void setRequest({{{message.request.name}}} request) {
            this.request = request;
        }

        public {{{message.response.name}}} getResponse() {
            return response;
        }

        public void setResponse({{{message.response.name}}} response) {
            this.response = response;
        }

        public Exception getException() {
            return exception;
        }

        public void setException(Exception exception) {
            this.exception = exception;
        }
    }

    public class {{{message.methodUpperCase}}}InnerTask extends AsyncTask<{{{message.request.name}}},Integer, {{{message.methodUpperCase}}}InnerTaskResponse> {

        private TaskListener<{{{message.request.name}}},{{{message.response.name}}}> taskListener;
        private OnLoadingListener serviceWorkingListener;

        public {{{message.methodUpperCase}}}InnerTask(TaskListener<{{{message.request.name}}},{{{message.response.name}}}> taskListener, OnLoadingListener serviceWorkingListener) {
            this.taskListener = taskListener;
            this.serviceWorkingListener = serviceWorkingListener;
        }

        @Override
        protected {{{message.methodUpperCase}}}InnerTaskResponse doInBackground({{{message.request.name}}}... params) {
            final {{{message.request.name}}} request = params[0];

            {{{message.methodUpperCase}}}InnerTaskResponse taskResponse = new {{{message.methodUpperCase}}}InnerTaskResponse(request);
            ResponseInfo responseInfo = new ResponseInfo();
            taskResponse.setResponseInfo(responseInfo);

            try {
                final {{{message.response.name}}} response = {{{message.service}}}Logic.getInstance().{{{message.method}}}(request, responseInfo);
                taskResponse.setResponse(response);
            } catch (ServiceException e) {
                e.printStackTrace();
                taskResponse.setException(e);
            }
            return taskResponse;
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            if (serviceWorkingListener != null) {
                serviceWorkingListener.onLoadingStarted();
            }
        }

        @Override
        protected void onPostExecute({{{message.methodUpperCase}}}InnerTaskResponse response) {
            super.onPostExecute(response);

            if (taskListener != null) {

                if (response.getException() != null) {
                    taskListener.onServiceError(response.getRequest(), response.getException());
                } else {
                    taskListener.onServiceResponse(response.getRequest(), response.getResponse(), response.getResponseInfo());
                }
            }

            if (serviceWorkingListener != null) {
                serviceWorkingListener.onLoadingFinished();
            }
        }
    }

}



{'fraction_non_alphanumeric': 0.12826603325415678, 'fraction_numerical': 0.00033932813030200206, 'mean_word_length': 2.793114543114543, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7140775', 'n_tokens_mistral': 3025, 'n_tokens_neox': 2907, 'n_words': 532}