LCOV - code coverage report
Current view: top level - entities - AttentionSetUpdate.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 6 6 100.0 %
Date: 2022-11-19 15:00:39 Functions: 4 4 100.0 %

          Line data    Source code
       1             : // Copyright (C) 2020 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.gerrit.common.Nullable;
      19             : import com.google.gerrit.extensions.api.changes.AttentionSetInput;
      20             : import java.time.Instant;
      21             : 
      22             : /**
      23             :  * A single update to the attention set. To reconstruct the attention set these instances are parsed
      24             :  * in reverse chronological order. Since each update contains all required information and
      25             :  * invalidates all previous state, only the most recent record is relevant for each user.
      26             :  *
      27             :  * <p>See {@link AttentionSetInput} for the representation in the API.
      28             :  */
      29             : @AutoValue
      30          74 : public abstract class AttentionSetUpdate {
      31             : 
      32             :   /** Users can be added to or removed from the attention set. */
      33          74 :   public enum Operation {
      34          74 :     ADD,
      35          74 :     REMOVE
      36             :   }
      37             : 
      38             :   /**
      39             :    * The time at which this status was set. This is null for instances to be written because the
      40             :    * timestamp in the commit message will be used.
      41             :    */
      42             :   @Nullable
      43             :   public abstract Instant timestamp();
      44             : 
      45             :   /** The user included in or excluded from the attention set. */
      46             :   public abstract Account.Id account();
      47             : 
      48             :   /** Indicates whether the user is added to or removed from the attention set. */
      49             :   public abstract Operation operation();
      50             : 
      51             :   /** A short human readable reason that explains this status (e.g. "manual"). */
      52             :   public abstract String reason();
      53             : 
      54             :   /**
      55             :    * Create an instance from data read from NoteDB. This includes the timestamp taken from the
      56             :    * commit.
      57             :    */
      58             :   public static AttentionSetUpdate createFromRead(
      59             :       Instant timestamp, Account.Id account, Operation operation, String reason) {
      60          52 :     return new AutoValue_AttentionSetUpdate(timestamp, account, operation, reason);
      61             :   }
      62             : 
      63             :   /**
      64             :    * Create an instance to be written to NoteDB. This has no timestamp because the timestamp of the
      65             :    * commit will be used.
      66             :    */
      67             :   public static AttentionSetUpdate createForWrite(
      68             :       Account.Id account, Operation operation, String reason) {
      69          74 :     return new AutoValue_AttentionSetUpdate(null, account, operation, reason);
      70             :   }
      71             : }

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