Line data Source code
1 : // Copyright (C) 2013 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.server.notedb; 16 : 17 : import com.google.gerrit.extensions.client.ReviewerState; 18 : import java.util.Arrays; 19 : import org.eclipse.jgit.revwalk.FooterKey; 20 : 21 : /** State of a reviewer on a change. */ 22 103 : public enum ReviewerStateInternal { 23 : /** The user has contributed at least one nonzero vote on the change. */ 24 103 : REVIEWER("Reviewer", ReviewerState.REVIEWER), 25 : 26 : /** The reviewer was added to the change, but has not voted. */ 27 103 : CC("CC", ReviewerState.CC), 28 : 29 : /** The user was previously a reviewer on the change, but was removed. */ 30 103 : REMOVED("Removed", ReviewerState.REMOVED); 31 : 32 : public static ReviewerStateInternal fromReviewerState(ReviewerState state) { 33 47 : return ReviewerStateInternal.values()[state.ordinal()]; 34 : } 35 : 36 : static { 37 103 : boolean ok = true; 38 103 : if (ReviewerStateInternal.values().length != ReviewerState.values().length) { 39 0 : ok = false; 40 : } 41 103 : for (int i = 0; i < ReviewerStateInternal.values().length; i++) { 42 103 : ok &= ReviewerState.values()[i].equals(ReviewerStateInternal.values()[i].state); 43 : } 44 103 : if (!ok) { 45 0 : throw new IllegalStateException( 46 : "Mismatched reviewer state mapping: " 47 0 : + Arrays.asList(ReviewerStateInternal.values()) 48 : + " != " 49 0 : + Arrays.asList(ReviewerState.values())); 50 : } 51 103 : } 52 : 53 : private final String footer; 54 : private final ReviewerState state; 55 : 56 103 : ReviewerStateInternal(String footer, ReviewerState state) { 57 103 : this.footer = footer; 58 103 : this.state = state; 59 103 : } 60 : 61 : FooterKey getFooterKey() { 62 103 : return new FooterKey(footer); 63 : } 64 : 65 : FooterKey getByEmailFooterKey() { 66 103 : return new FooterKey(footer + "-email"); 67 : } 68 : 69 : public ReviewerState asReviewerState() { 70 75 : return state; 71 : } 72 : }