/**
 * Copyright 2013-2014 David Rusek <dave dot rusek at gmail dot com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.robotninjas.barge.api;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;

import javax.annotation.concurrent.Immutable;
import java.util.Collections;
import java.util.List;

/**
 */
@Immutable
public class AppendEntries {

  private final long prevLogIndex;
  private final long prevLogTerm;
  private final List<Entry> entriesList;
  private final long term;
  private final String leaderId;
  private final long commitIndex;


  public AppendEntries(long term, String leaderId, long prevLogIndex, long prevLogTerm, long commitIndex, List<Entry> entries) {
    this.term = term;
    this.leaderId = leaderId;
    this.prevLogIndex = prevLogIndex;
    this.prevLogTerm = prevLogTerm;
    this.commitIndex = commitIndex;
    this.entriesList = ImmutableList.copyOf(entries);
  }

  public long getPrevLogIndex() {
    return prevLogIndex;
  }

  public long getPrevLogTerm() {
    return prevLogTerm;
  }

  public List<Entry> getEntriesList() {
    return entriesList;
  }

  public long getTerm() {
    return term;
  }

  public String getLeaderId() {
    return leaderId;
  }

  public long getCommitIndex() {
    return commitIndex;
  }

  public static Builder newBuilder() {
    return new Builder();
  }

  public long getEntriesCount() {
    return entriesList.size();
  }

  public static AppendEntries getDefaultInstance() {
    return new AppendEntries(0, "", 0, 0, 0, Collections.<Entry>emptyList());
  }

  public static class Builder {
    private long term;
    private String leaderId;
    private long prevLogIndex;
    private long prevLogTerm;
    private long commitIndex;
    private List<Entry> entries = Lists.newArrayList();

    public Builder setTerm(long term) {
      this.term = term;
      return this;
    }

    public Builder setLeaderId(String leaderId) {
      this.leaderId = leaderId;
      return this;
    }

    public Builder setPrevLogIndex(long prevLogIndex) {
      this.prevLogIndex = prevLogIndex;
      return this;
    }

    public Builder setPrevLogTerm(long prevLogTerm) {
      this.prevLogTerm = prevLogTerm;
      return this;
    }

    public Builder setCommitIndex(long commitIndex) {
      this.commitIndex = commitIndex;
      return this;
    }

    public Builder addAllEntries(List<Entry> entries) {
      this.entries.addAll(entries);
      return this;
    }

    public AppendEntries build() {
      return new AppendEntries(term, leaderId, prevLogIndex, prevLogTerm, commitIndex, entries);
    }

    public Builder addEntry(Entry entry) {
      this.entries.add(entry);
      return this;
    }
  }
}

@@ -660,16 +660,55 @@
 e.api;%0A%0A
+import com.google.common.base.Objects;%0A
 import c
@@ -1988,32 +1988,1184 @@
 st.size();%0A  %7D%0A%0A
+  @Override%0A  public boolean equals(Object o) %7B%0A    if (!(o instanceof AppendEntries)) return false;%0A%0A    AppendEntries that = (AppendEntries) o;%0A%0A    return Objects.equal(entriesList,that.entriesList)%0A      && commitIndex == that.commitIndex%0A      && prevLogIndex == that.prevLogIndex%0A      && prevLogTerm == that.prevLogTerm%0A      && term == that.term%0A      && Objects.equal(leaderId, that.leaderId);%0A  %7D%0A%0A  @Override%0A  public int hashCode() %7B%0A    int result = (int) (prevLogIndex %5E (prevLogIndex %3E%3E%3E 32));%0A    result = 31 * result + (int) (prevLogTerm %5E (prevLogTerm %3E%3E%3E 32));%0A    result = 31 * result + entriesList.hashCode();%0A    result = 31 * result + (int) (term %5E (term %3E%3E%3E 32));%0A    result = 31 * result + leaderId.hashCode();%0A    result = 31 * result + (int) (commitIndex %5E (commitIndex %3E%3E%3E 32));%0A    return result;%0A  %7D%0A%0A  @Override%0A  public String toString() %7B%0A    return Objects.toStringHelper(this)%0A      .add(%22prevLogIndex%22, prevLogIndex)%0A      .add(%22prevLogTerm%22, prevLogTerm)%0A      .add(%22entriesList%22, entriesList)%0A      .add(%22term%22, term)%0A      .add(%22leaderId%22, leaderId)%0A      .add(%22commitIndex%22, commitIndex)%0A      .toString();%0A  %7D%0A%0A
   public static 

implement properly equals/hashcode/toString