Line data Source code
1 : // Copyright (C) 2018 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.entities; 16 : 17 : import static com.google.common.base.Preconditions.checkState; 18 : 19 : import com.google.auto.value.AutoValue; 20 : import com.google.common.base.CharMatcher; 21 : 22 : /** Describes a submit record requirement. Contains the requirement name and a description. */ 23 : @AutoValue 24 : @AutoValue.CopyAnnotations 25 5 : public abstract class LegacySubmitRequirement { 26 5 : private static final CharMatcher TYPE_MATCHER = 27 5 : CharMatcher.inRange('a', 'z') 28 5 : .or(CharMatcher.inRange('A', 'Z')) 29 5 : .or(CharMatcher.inRange('0', '9')) 30 5 : .or(CharMatcher.anyOf("-_")); 31 : 32 : @AutoValue.Builder 33 5 : public abstract static class Builder { 34 : public abstract Builder setType(String value); 35 : 36 : public abstract Builder setFallbackText(String value); 37 : 38 : public LegacySubmitRequirement build() { 39 5 : LegacySubmitRequirement requirement = autoBuild(); 40 5 : checkState( 41 5 : validateType(requirement.type()), 42 : "LegacySubmitRequirement's type contains non alphanumerical symbols."); 43 5 : return requirement; 44 : } 45 : 46 : abstract LegacySubmitRequirement autoBuild(); 47 : } 48 : 49 : /** Requirement description and explanation of what it does */ 50 : public abstract String fallbackText(); 51 : 52 : /** Requirement name */ 53 : public abstract String type(); 54 : 55 : public static Builder builder() { 56 5 : return new AutoValue_LegacySubmitRequirement.Builder(); 57 : } 58 : 59 : private static boolean validateType(String type) { 60 5 : return TYPE_MATCHER.matchesAllOf(type); 61 : } 62 : }