LCOV - code coverage report
Current view: top level - server - ReviewerByEmailSet.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 12 14 85.7 %
Date: 2022-11-19 15:00:39 Functions: 8 10 80.0 %

          Line data    Source code
       1             : // Copyright (C) 2017 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;
      16             : 
      17             : import com.google.common.collect.ImmutableSet;
      18             : import com.google.common.collect.ImmutableTable;
      19             : import com.google.common.collect.Table;
      20             : import com.google.gerrit.entities.Address;
      21             : import com.google.gerrit.server.notedb.ReviewerStateInternal;
      22             : import java.time.Instant;
      23             : 
      24             : /**
      25             :  * Set of reviewers on a change that do not have a Gerrit account and were added by email instead.
      26             :  *
      27             :  * <p>A given account may appear in multiple states and at different timestamps. No reviewers with
      28             :  * state {@link ReviewerStateInternal#REMOVED} are ever exposed by this interface.
      29             :  */
      30             : public class ReviewerByEmailSet {
      31         103 :   private static final ReviewerByEmailSet EMPTY = new ReviewerByEmailSet(ImmutableTable.of());
      32             : 
      33             :   public static ReviewerByEmailSet fromTable(Table<ReviewerStateInternal, Address, Instant> table) {
      34         103 :     return new ReviewerByEmailSet(table);
      35             :   }
      36             : 
      37             :   public static ReviewerByEmailSet empty() {
      38         103 :     return EMPTY;
      39             :   }
      40             : 
      41             :   private final ImmutableTable<ReviewerStateInternal, Address, Instant> table;
      42             :   private ImmutableSet<Address> users;
      43             : 
      44         103 :   private ReviewerByEmailSet(Table<ReviewerStateInternal, Address, Instant> table) {
      45         103 :     this.table = ImmutableTable.copyOf(table);
      46         103 :   }
      47             : 
      48             :   public ImmutableSet<Address> all() {
      49          10 :     if (users == null) {
      50             :       // Idempotent and immutable, don't bother locking.
      51          10 :       users = ImmutableSet.copyOf(table.columnKeySet());
      52             :     }
      53          10 :     return users;
      54             :   }
      55             : 
      56             :   public ImmutableSet<Address> byState(ReviewerStateInternal state) {
      57         103 :     return table.row(state).keySet();
      58             :   }
      59             : 
      60             :   public ImmutableTable<ReviewerStateInternal, Address, Instant> asTable() {
      61         103 :     return table;
      62             :   }
      63             : 
      64             :   @Override
      65             :   public boolean equals(Object o) {
      66           1 :     return (o instanceof ReviewerByEmailSet) && table.equals(((ReviewerByEmailSet) o).table);
      67             :   }
      68             : 
      69             :   @Override
      70             :   public int hashCode() {
      71           0 :     return table.hashCode();
      72             :   }
      73             : 
      74             :   @Override
      75             :   public String toString() {
      76           0 :     return getClass().getSimpleName() + table;
      77             :   }
      78             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750