LCOV - code coverage report
Current view: top level - entities - NotifyConfig.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 26 29 89.7 %
Date: 2022-11-19 15:00:39 Functions: 11 12 91.7 %

          Line data    Source code
       1             : // Copyright (C) 2012 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 com.google.auto.value.AutoValue;
      18             : import com.google.auto.value.extension.memoized.Memoized;
      19             : import com.google.common.base.Strings;
      20             : import com.google.common.collect.ImmutableSet;
      21             : import com.google.gerrit.common.Nullable;
      22             : import java.util.EnumSet;
      23             : import java.util.Set;
      24             : 
      25             : @AutoValue
      26           4 : public abstract class NotifyConfig implements Comparable<NotifyConfig> {
      27           4 :   public enum Header {
      28           4 :     TO,
      29           4 :     CC,
      30           4 :     BCC
      31             :   }
      32             : 
      33         104 :   public enum NotifyType {
      34             :     // sort by name, except 'ALL' which should stay last
      35         104 :     ABANDONED_CHANGES,
      36         104 :     ALL_COMMENTS,
      37         104 :     NEW_CHANGES,
      38         104 :     NEW_PATCHSETS,
      39         104 :     SUBMITTED_CHANGES,
      40             : 
      41         104 :     ALL
      42             :   }
      43             : 
      44             :   public abstract String getName();
      45             : 
      46             :   public abstract ImmutableSet<NotifyType> getNotify();
      47             : 
      48             :   @Nullable
      49             :   public abstract String getFilter();
      50             : 
      51             :   @Nullable
      52             :   public abstract Header getHeader();
      53             : 
      54             :   public abstract ImmutableSet<GroupReference> getGroups();
      55             : 
      56             :   public abstract ImmutableSet<Address> getAddresses();
      57             : 
      58             :   public boolean isNotify(NotifyType type) {
      59           2 :     return getNotify().contains(type) || getNotify().contains(NotifyType.ALL);
      60             :   }
      61             : 
      62             :   public static Builder builder() {
      63           4 :     return new AutoValue_NotifyConfig.Builder()
      64           4 :         .setNotify(ImmutableSet.copyOf(EnumSet.of(NotifyType.ALL)));
      65             :   }
      66             : 
      67             :   @AutoValue.Builder
      68           4 :   public abstract static class Builder {
      69             :     public abstract Builder setName(String name);
      70             : 
      71             :     public abstract Builder setNotify(Set<NotifyType> newTypes);
      72             : 
      73             :     public abstract Builder setFilter(@Nullable String filter);
      74             : 
      75             :     public abstract Builder setHeader(Header hdr);
      76             : 
      77             :     public Builder addGroup(GroupReference group) {
      78           1 :       groupsBuilder().add(group);
      79           1 :       return this;
      80             :     }
      81             : 
      82             :     public Builder addAddress(Address address) {
      83           4 :       addressesBuilder().add(address);
      84           4 :       return this;
      85             :     }
      86             : 
      87             :     protected abstract ImmutableSet.Builder<GroupReference> groupsBuilder();
      88             : 
      89             :     protected abstract ImmutableSet.Builder<Address> addressesBuilder();
      90             : 
      91             :     protected abstract NotifyConfig autoBuild();
      92             : 
      93             :     protected abstract String getFilter();
      94             : 
      95             :     public NotifyConfig build() {
      96           4 :       if ("*".equals(getFilter())) {
      97           0 :         setFilter(null);
      98             :       } else {
      99           4 :         setFilter(Strings.emptyToNull(getFilter()));
     100             :       }
     101           4 :       return autoBuild();
     102             :     }
     103             :   }
     104             : 
     105             :   @Override
     106             :   public final int compareTo(NotifyConfig o) {
     107           2 :     return getName().compareTo(o.getName());
     108             :   }
     109             : 
     110             :   @Memoized
     111             :   @Override
     112             :   public int hashCode() {
     113           0 :     return getName().hashCode();
     114             :   }
     115             : 
     116             :   @Override
     117             :   public final boolean equals(Object obj) {
     118           1 :     if (obj instanceof NotifyConfig) {
     119           1 :       return compareTo((NotifyConfig) obj) == 0;
     120             :     }
     121           0 :     return false;
     122             :   }
     123             : }

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