2 * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.cluster.raft;
11 * Immutable implementation of ElectionTerm.
13 * @author Thomas Pantelis
15 public class ImmutableElectionTerm implements ElectionTerm {
16 private final long currentTerm;
17 private final String votedFor;
19 private ImmutableElectionTerm(long currentTerm, String votedFor) {
20 this.currentTerm = currentTerm;
21 this.votedFor = votedFor;
25 public long getCurrentTerm() {
30 public String getVotedFor() {
35 public void update(long currentTerm, String votedFor) {
36 throw new UnsupportedOperationException();
40 public void updateAndPersist(long currentTerm, String votedFor) {
41 throw new UnsupportedOperationException();
45 public String toString() {
46 return "ImmutableElectionTerm [currentTerm=" + currentTerm + ", votedFor=" + votedFor + "]";
49 public static ElectionTerm copyOf(ElectionTerm from) {
50 return new ImmutableElectionTerm(from.getCurrentTerm(), from.getVotedFor());