package meerkat.bulletinboard;

import com.google.protobuf.Int64Value;

/**
 * Created by Arbel Deutsch Peled on 16-Jun-16.
 * Single-server implementation of the BatchIdentifier interface
 */
final class SingleServerBatchIdentifier implements AsyncBulletinBoardClient.BatchIdentifier {

    private final Int64Value batchId;

    private int length;

    public SingleServerBatchIdentifier(Int64Value batchId) {
        this.batchId = batchId;
        length = 0;
    }

    public SingleServerBatchIdentifier(long batchId) {
        this(Int64Value.newBuilder().setValue(batchId).build());
    }

    public Int64Value getBatchId() {
        return batchId;
    }

    /**
     * Overrides the existing length with the new one only if the new length is longer
     * @param newLength
     */
    public void setLength(int newLength) {
        if (newLength > length) {
            length = newLength;
        }
    }

    public int getLength() {
        return length;
    }

}
