All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.eg.agent.android.harvest.HttpErrorResponseList Maven / Gradle / Ivy

The newest version!
package com.eg.agent.android.harvest;


import com.eg.agent.android.harvest.type.ArrayTransformer;
import com.eg.google.gson.JsonArray;

import java.util.Collection;
import java.util.concurrent.CopyOnWriteArrayList;

public class HttpErrorResponseList extends ArrayTransformer {
    private final Collection httpErrors = new CopyOnWriteArrayList();

    public void addHttpError(HttpErrorResponse httpError) {
        synchronized (httpError) {
            for (HttpErrorResponse error : this.httpErrors) {
                if (httpError.getHash().equals(error.getHash())) {
                    error.incrementCount();
                    return;
                }
            }
            this.httpErrors.add(httpError);
        }
    }

    public synchronized void removeHttpError(HttpErrorResponse error) {
        this.httpErrors.remove(error);
    }

    public void clear() {
        this.httpErrors.clear();
    }

    public JsonArray asJsonArray() {
        JsonArray array = new JsonArray();
        for (HttpErrorResponse httpError : this.httpErrors) {
            array.add(httpError.asJson());
        }
        return array;
    }

    public Collection getHttpErrors() {
        return this.httpErrors;
    }

    public int count() {
        return this.httpErrors.size();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy