Line data Source code
1 : // Copyright (C) 2022 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 : package com.google.gerrit.entities; 15 : 16 : /** 17 : * A human-readable change size bucket. 18 : * 19 : * <p>Should be kept in sync with 20 : * polygerrit-ui/app/elements/change-list/gr-change-list-item/gr-change-list-item.ts 21 : */ 22 0 : public class ChangeSizeBucket { 23 : 24 : /** 25 : * The upper bounds for the different size buckets. 26 : * 27 : * <p>Same as gr-change-list-item.ts::ChangeSize. 28 : */ 29 104 : private enum BucketThresholds { 30 104 : XS(10), 31 104 : SMALL(50), 32 104 : MEDIUM(250), 33 104 : LARGE(1000); 34 : 35 : public final long delta; 36 : 37 104 : BucketThresholds(long delta) { 38 104 : this.delta = delta; 39 104 : } 40 : } 41 : 42 : /** 43 : * Gets the correlative size bucket for the given change delta. 44 : * 45 : * <p>Same as gr-change-list-item.ts::computeChangeSize(). 46 : * 47 : * @param delta the total number of changed lines (additions+deletions) of the change. 48 : * @return a short human-readable size bucket. 49 : */ 50 : public static String getChangeSizeBucket(long delta) { 51 104 : if (delta == 0) { 52 1 : return "NoOp"; 53 104 : } else if (delta < BucketThresholds.XS.delta) { 54 70 : return "XS"; 55 89 : } else if (delta < BucketThresholds.SMALL.delta) { 56 89 : return "S"; 57 5 : } else if (delta < BucketThresholds.MEDIUM.delta) { 58 4 : return "M"; 59 2 : } else if (delta < BucketThresholds.LARGE.delta) { 60 1 : return "L"; 61 : } 62 2 : return "XL"; 63 : } 64 : }