import java.util.Collections;
import java.util.List;
import java.util.Map;
+import javax.annotation.Nonnull;
/**
* The response to a GetOnDemandRaftState message.
private Map<String, String> peerAddresses = Collections.emptyMap();
private Map<String, Boolean> peerVotingStates = Collections.emptyMap();
- private OnDemandRaftState() {
+ protected OnDemandRaftState() {
}
public static Builder builder() {
return customRaftPolicyClassName;
}
- public static class Builder {
- private final OnDemandRaftState stats = new OnDemandRaftState();
+ public abstract static class AbstractBuilder<T extends AbstractBuilder<T>> {
+ @SuppressWarnings("unchecked")
+ protected T self() {
+ return (T) this;
+ }
+
+ @Nonnull
+ protected abstract OnDemandRaftState state();
- public Builder lastLogIndex(long value) {
- stats.lastLogIndex = value;
- return this;
+ public T lastLogIndex(long value) {
+ state().lastLogIndex = value;
+ return self();
}
- public Builder lastLogTerm(long value) {
- stats.lastLogTerm = value;
- return this;
+ public T lastLogTerm(long value) {
+ state().lastLogTerm = value;
+ return self();
}
- public Builder currentTerm(long value) {
- stats.currentTerm = value;
- return this;
+ public T currentTerm(long value) {
+ state().currentTerm = value;
+ return self();
}
- public Builder commitIndex(long value) {
- stats.commitIndex = value;
- return this;
+ public T commitIndex(long value) {
+ state().commitIndex = value;
+ return self();
}
- public Builder lastApplied(long value) {
- stats.lastApplied = value;
- return this;
+ public T lastApplied(long value) {
+ state().lastApplied = value;
+ return self();
}
- public Builder lastIndex(long value) {
- stats.lastIndex = value;
- return this;
+ public T lastIndex(long value) {
+ state().lastIndex = value;
+ return self();
}
- public Builder lastTerm(long value) {
- stats.lastTerm = value;
- return this;
+ public T lastTerm(long value) {
+ state().lastTerm = value;
+ return self();
}
- public Builder snapshotIndex(long value) {
- stats.snapshotIndex = value;
- return this;
+ public T snapshotIndex(long value) {
+ state().snapshotIndex = value;
+ return self();
}
- public Builder snapshotTerm(long value) {
- stats.snapshotTerm = value;
- return this;
+ public T snapshotTerm(long value) {
+ state().snapshotTerm = value;
+ return self();
}
- public Builder replicatedToAllIndex(long value) {
- stats.replicatedToAllIndex = value;
- return this;
+ public T replicatedToAllIndex(long value) {
+ state().replicatedToAllIndex = value;
+ return self();
}
- public Builder inMemoryJournalDataSize(long value) {
- stats.inMemoryJournalDataSize = value;
- return this;
+ public T inMemoryJournalDataSize(long value) {
+ state().inMemoryJournalDataSize = value;
+ return self();
}
- public Builder inMemoryJournalLogSize(long value) {
- stats.inMemoryJournalLogSize = value;
- return this;
+ public T inMemoryJournalLogSize(long value) {
+ state().inMemoryJournalLogSize = value;
+ return self();
}
- public Builder leader(String value) {
- stats.leader = value;
- return this;
+ public T leader(String value) {
+ state().leader = value;
+ return self();
}
- public Builder raftState(String value) {
- stats.raftState = value;
- return this;
+ public T raftState(String value) {
+ state().raftState = value;
+ return self();
}
- public Builder votedFor(String value) {
- stats.votedFor = value;
- return this;
+ public T votedFor(String value) {
+ state().votedFor = value;
+ return self();
}
- public Builder isVoting(boolean isVoting) {
- stats.isVoting = isVoting;
- return this;
+ public T isVoting(boolean isVoting) {
+ state().isVoting = isVoting;
+ return self();
}
- public Builder followerInfoList(List<FollowerInfo> followerInfoList) {
- stats.followerInfoList = followerInfoList;
- return this;
+ public T followerInfoList(List<FollowerInfo> followerInfoList) {
+ state().followerInfoList = followerInfoList;
+ return self();
}
- public Builder peerAddresses(Map<String, String> peerAddresses) {
- stats.peerAddresses = peerAddresses;
- return this;
+ public T peerAddresses(Map<String, String> peerAddresses) {
+ state().peerAddresses = peerAddresses;
+ return self();
}
- public Builder peerVotingStates(Map<String, Boolean> peerVotingStates) {
- stats.peerVotingStates = ImmutableMap.copyOf(peerVotingStates);
- return this;
+ public T peerVotingStates(Map<String, Boolean> peerVotingStates) {
+ state().peerVotingStates = ImmutableMap.copyOf(peerVotingStates);
+ return self();
}
- public Builder isSnapshotCaptureInitiated(boolean value) {
- stats.isSnapshotCaptureInitiated = value;
- return this;
+ public T isSnapshotCaptureInitiated(boolean value) {
+ state().isSnapshotCaptureInitiated = value;
+ return self();
}
- public Builder customRaftPolicyClassName(String className) {
- stats.customRaftPolicyClassName = className;
- return this;
+ public T customRaftPolicyClassName(String className) {
+ state().customRaftPolicyClassName = className;
+ return self();
}
public OnDemandRaftState build() {
- return stats;
+ return state();
+ }
+ }
+
+ public static class Builder extends AbstractBuilder<Builder> {
+ private final OnDemandRaftState state = new OnDemandRaftState();
+
+ @Override
+ protected OnDemandRaftState state() {
+ return state;
}
}
}