<commit_before>package in.testpress.testpress.core;

import android.accounts.AccountsException;
import android.accounts.OperationCanceledException;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collections;
import java.util.List;

import javax.inject.Inject;

import in.testpress.testpress.Injector;
import in.testpress.testpress.TestpressServiceProvider;
import in.testpress.testpress.authenticator.LogoutService;
import in.testpress.testpress.models.Exam;
import in.testpress.testpress.models.TestpressApiResponse;
import in.testpress.testpress.ui.MainActivity;
import retrofit.RetrofitError;


public class ExamPager extends ResourcePager<Exam> {
    String subclass;
    TestpressApiResponse<Exam> response;

    @Inject protected TestpressServiceProvider serviceProvider;
    @Inject protected LogoutService logoutService;

    public ExamPager(String subclass, TestpressService service) {
        super(service);
        this.subclass = subclass;
        Injector.inject(this);
    }

    @Override
    public ResourcePager<Exam> clear() {
        response = null;
        return super.clear();
    }

    @Override
    protected Object getId(Exam resource) {
        return resource.getId();
    }

    @Override
    public List<Exam> getItems(int page, int size) throws RetrofitError {
        String url = null;
        if (response == null) {
            if (subclass.equals("available")) {
                url = Constants.Http.URL_AVAILABLE_EXAMS_FRAG;
            } else if (subclass.equals("upcoming")) {
                url = Constants.Http.URL_UPCOMING_EXAMS_FRAG;
            } else if (subclass.equals("history")) {
                url = Constants.Http.URL_HISTORY_EXAMS_FRAG;
            } else {
                url = Constants.Http.URL_AVAILABLE_EXAMS_FRAG;
            }
        } else {
            try {
                URL full = new URL(response.getNext());
                url = full.getFile().substring(1);
            } catch (MalformedURLException e) {
                e.printStackTrace();
                url = null;
            }

        }
        if (url != null) {
            try {
                response = service.getExams(url, queryParams);
                return response.getResults();
            }
            catch (Exception e) {
                if((e.getMessage()).equals("403 FORBIDDEN")) {
                   serviceProvider.invalidateAuthToken();
                   logoutService.logout(new Runnable() {
                       @Override
                       public void run() {
                           Intent intent = activity.getIntent();
                           activity.finish();
                           activity.startActivity(intent);
                       }
                   });
                }
               else return null;
            }
        }
        return Collections.emptyList();
    }

    @Override<commit_msg>Fix compilation error due to revert.<commit_after>package in.testpress.testpress.core;

import android.accounts.AccountsException;
import android.accounts.OperationCanceledException;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collections;
import java.util.List;

import javax.inject.Inject;

import in.testpress.testpress.Injector;
import in.testpress.testpress.TestpressServiceProvider;
import in.testpress.testpress.authenticator.LogoutService;
import in.testpress.testpress.models.Exam;
import in.testpress.testpress.models.TestpressApiResponse;
import in.testpress.testpress.ui.MainActivity;
import retrofit.RetrofitError;


public class ExamPager extends ResourcePager<Exam> {
    String subclass;
    TestpressApiResponse<Exam> response;

    @Inject protected TestpressServiceProvider serviceProvider;
    @Inject protected LogoutService logoutService;

    public ExamPager(String subclass, TestpressService service) {
        super(service);
        this.subclass = subclass;
        Injector.inject(this);
    }

    @Override
    public ResourcePager<Exam> clear() {
        response = null;
        return super.clear();
    }

    @Override
    protected Object getId(Exam resource) {
        return resource.getId();
    }

    @Override
    public List<Exam> getItems(int page, int size) throws RetrofitError {
        String url = null;
        if (response == null) {
            if (subclass.equals("available")) {
                url = Constants.Http.URL_AVAILABLE_EXAMS_FRAG;
            } else if (subclass.equals("upcoming")) {
                url = Constants.Http.URL_UPCOMING_EXAMS_FRAG;
            } else if (subclass.equals("history")) {
                url = Constants.Http.URL_HISTORY_EXAMS_FRAG;
            } else {
                url = Constants.Http.URL_AVAILABLE_EXAMS_FRAG;
            }
        } else {
            try {
                URL full = new URL(response.getNext());
                url = full.getFile().substring(1);
            } catch (MalformedURLException e) {
                e.printStackTrace();
                url = null;
            }

        }
        if (url != null) {
            try {
                response = service.getExams(url, queryParams);
                return response.getResults();
            }
            catch (Exception e) {
                if((e.getMessage()).equals("403 FORBIDDEN")) {
                    throw e;
                } else {
                    return null;
                }
            }
        }
        return Collections.emptyList();
    }

    @Override
{'fraction_non_alphanumeric': 0.09297520661157024, 'fraction_numerical': 0.0013774104683195593, 'mean_word_length': 2.094832179009057, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '3631088', 'n_tokens_mistral': 1613, 'n_tokens_neox': 1555, 'n_words': 312}