package com.atlassian.stash.internal.commit.graph.cache;

import com.atlassian.bitbucket.repository.Repository;

import java.io.OutputStream;

/**
 * @since 2.11
 */
public abstract class AbstractCacheTraversalJob implements Runnable {

    protected final int priority;
    protected final Repository repository;
    protected final OutputStream outputStream;

    protected AbstractCacheTraversalJob(int priority, Repository repository, OutputStream outputStream) {
        this.priority = priority;
        this.repository = repository;
        this.outputStream = outputStream;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof AbstractCacheTraversalJob) {
            AbstractCacheTraversalJob other = (AbstractCacheTraversalJob) obj;
            return this.repository.equals(other.repository) && this.outputStream == other.outputStream;
        }
        return false;
    }

    public int getPriority() {
        return priority;
    }

    @Override
    public int hashCode() {
        return 31 * repository.hashCode() + outputStream.hashCode();
    }
}
