<commit_before>/*
 * Copyright 2015 the original author or authors.
 *
 * 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 io.atomix.copycat.server.state;

import io.atomix.catalyst.util.Assert;
import io.atomix.copycat.server.storage.Log;

/**
 * Cluster member state.
 *
 * @author <a href="http://github.com/kuujo"><NAME></a>
 */
class MemberState {
  private Member member;
  private long term;
  private long version;
  private long snapshotIndex;
  private int snapshotOffset;
  private long matchIndex;
  private long nextIndex;
  private long commitTime;
  private long commitStartTime;
  private int failures;

  public MemberState(Member member) {
    this.member = Assert.notNull(member, "member");
  }

  /**
   * Resets the member state.
   */
  void resetState(Log log) {
    matchIndex = 0;
    nextIndex = log.lastIndex() + 1;
    commitTime = 0;
    commitStartTime = 0;
    failures = 0;
  }

  /**
   * Returs the member.
   *
   * @return The member.
   */
  public Member getMember() {
    return member;
  }

  /**
   * Sets the member.
   *
   * @param member The member.
   * @return The member state.
   */
  MemberState setMember(Member member) {
    this.member = Assert.notNull(member, "member");
    return this;
  }

  /**
   * Returns the member term.
   *
   * @return The member term.
   */
  long getTerm() {
    return term;
  }

  /**
   * Sets the member term.
   *
   * @param term The member term.
   * @return The member state.
   */
  MemberState setTerm(long term) {
    this.term = term;
    return this;
  }

  /**
   * Returns the member configuration version.
   *
   * @return The member configuration version.
   */
  long getVersion() {
    return version;
  }

  /**
   * Sets the member version.
   *
   * @param version The member version.
   * @return The member state.
   */
  MemberState setVersion(long version) {
    this.version = version;
    return this;
  }

  /**
   * Returns the member's snapshot index.
   *
   * @return The member's snapshot index.
   */
  long getSnapshotIndex() {
    return snapshotIndex;
  }

  /**
   * Sets the member's snapshot index.
   *
   * @param snapshotIndex The member's snapshot index.
   * @return The member state.
   */
  MemberState setSnapshotIndex(long snapshotIndex) {
    this.snapshotIndex = snapshotIndex;
    return this;
  }

  /**
   * Returns the member's snapshot offset.
   *
   * @return The member's snapshot offset.
   */
  int getSnapshotOffset() {
    return snapshotOffset;
  }

  /**
   * Sets the member's snapshot offset.
   *
   * @param snapshotOffset The member's snapshot offset.
   * @return The member state.
   */
  MemberState setSnapshotOffset(int snapshotOffset) {
    this.snapshotOffset = snapshotOffset;
    return this;
  }

  /**
   * Returns the member's match index.
   *
   * @return The member's match index.
   */
  long getMatchIndex() {
    return matchIndex;
  }

  /**
   * Sets the member's match index.
   *
   * @param matchIndex The member's match index.
   * @return The member state.
   */
  MemberState setMatchIndex(long matchIndex) {
    this.matchIndex = Assert.argNot(matchIndex, matchIndex < this.matchIndex, "matchIndex cannot be decreased");
    return this;
  }

  /**
   * Returns the member's next index.
   *
   * @return The member's next index.
   */
  long getNextIndex() {
    return nextIndex;
  }

  /**
   * Sets the member's next index.
   *
   * @param nextIndex The member's next index.
   * @return The member state.
   */
  MemberState setNextIndex(long nextIndex) {
    this.nextIndex = Assert.argNot(nextIndex, nextIndex <= matchIndex, "nextIndex cannot be less than or equal to matchIndex");
    return this;
  }

  /**
   * Returns the member commit time.
   *
   * @return The member commit time.
   */
  long getCommitTime() {
    return commitTime;
  }

  /**
   * Sets the member commit time.
   *
   * @param commitTime The member commit time.
   * @return The member state.
   */
  MemberState setCommitTime(long commitTime) {
    this.commitTime = commitTime;
    return this;
  }<commit_msg>Remove argument checks for nextIndex and matchIndex per member to allow members to respond with correct indexes.<commit_after>/*
 * Copyright 2015 the original author or authors.
 *
 * 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 io.atomix.copycat.server.state;

import io.atomix.catalyst.util.Assert;
import io.atomix.copycat.server.storage.Log;

/**
 * Cluster member state.
 *
 * @author <a href="http://github.com/kuujo"><NAME></a>
 */
class MemberState {
  private Member member;
  private long term;
  private long version;
  private long snapshotIndex;
  private int snapshotOffset;
  private long matchIndex;
  private long nextIndex;
  private long commitTime;
  private long commitStartTime;
  private int failures;

  public MemberState(Member member) {
    this.member = Assert.notNull(member, "member");
  }

  /**
   * Resets the member state.
   */
  void resetState(Log log) {
    matchIndex = 0;
    nextIndex = log.lastIndex() + 1;
    commitTime = 0;
    commitStartTime = 0;
    failures = 0;
  }

  /**
   * Returs the member.
   *
   * @return The member.
   */
  public Member getMember() {
    return member;
  }

  /**
   * Sets the member.
   *
   * @param member The member.
   * @return The member state.
   */
  MemberState setMember(Member member) {
    this.member = Assert.notNull(member, "member");
    return this;
  }

  /**
   * Returns the member term.
   *
   * @return The member term.
   */
  long getTerm() {
    return term;
  }

  /**
   * Sets the member term.
   *
   * @param term The member term.
   * @return The member state.
   */
  MemberState setTerm(long term) {
    this.term = term;
    return this;
  }

  /**
   * Returns the member configuration version.
   *
   * @return The member configuration version.
   */
  long getVersion() {
    return version;
  }

  /**
   * Sets the member version.
   *
   * @param version The member version.
   * @return The member state.
   */
  MemberState setVersion(long version) {
    this.version = version;
    return this;
  }

  /**
   * Returns the member's snapshot index.
   *
   * @return The member's snapshot index.
   */
  long getSnapshotIndex() {
    return snapshotIndex;
  }

  /**
   * Sets the member's snapshot index.
   *
   * @param snapshotIndex The member's snapshot index.
   * @return The member state.
   */
  MemberState setSnapshotIndex(long snapshotIndex) {
    this.snapshotIndex = snapshotIndex;
    return this;
  }

  /**
   * Returns the member's snapshot offset.
   *
   * @return The member's snapshot offset.
   */
  int getSnapshotOffset() {
    return snapshotOffset;
  }

  /**
   * Sets the member's snapshot offset.
   *
   * @param snapshotOffset The member's snapshot offset.
   * @return The member state.
   */
  MemberState setSnapshotOffset(int snapshotOffset) {
    this.snapshotOffset = snapshotOffset;
    return this;
  }

  /**
   * Returns the member's match index.
   *
   * @return The member's match index.
   */
  long getMatchIndex() {
    return matchIndex;
  }

  /**
   * Sets the member's match index.
   *
   * @param matchIndex The member's match index.
   * @return The member state.
   */
  MemberState setMatchIndex(long matchIndex) {
    this.matchIndex = Assert.argNot(matchIndex, matchIndex < 0, "matchIndex cannot be less than 0");
    return this;
  }

  /**
   * Returns the member's next index.
   *
   * @return The member's next index.
   */
  long getNextIndex() {
    return nextIndex;
  }

  /**
   * Sets the member's next index.
   *
   * @param nextIndex The member's next index.
   * @return The member state.
   */
  MemberState setNextIndex(long nextIndex) {
    this.nextIndex = Assert.argNot(nextIndex, nextIndex <= 0, "nextIndex cannot be less than or equal to 0");
    return this;
  }

  /**
   * Returns the member commit time.
   *
   * @return The member commit time.
   */
  long getCommitTime() {
    return commitTime;
  }

  /**
   * Sets the member commit time.
   *
   * @param commitTime The member commit time.
   * @return The member state.
   */
  MemberState setCommitTime(long commitTime) {
    this.commitTime = commitTime;
    return this;
  }
{'fraction_non_alphanumeric': 0.10353398897654814, 'fraction_numerical': 0.0032421917216038042, 'mean_word_length': 2.697163403915302, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7151370', 'n_tokens_mistral': 2826, 'n_tokens_neox': 2736, 'n_words': 916}