1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License
15  */
16 
17 package com.android.dialer.spam.status;
18 
19 import android.support.annotation.Nullable;
20 import com.google.auto.value.AutoValue;
21 import com.google.common.base.Optional;
22 
23 /** Holds a boolean and long to represent spam status. */
24 @AutoValue
25 public abstract class SimpleSpamStatus implements SpamStatus {
26 
27   /** Returns a SimpleSpamStatus with the given boolean and timestamp. */
create(boolean isSpam, @Nullable Long timestampMillis)28   public static SimpleSpamStatus create(boolean isSpam, @Nullable Long timestampMillis) {
29     return builder()
30         .setSpam(isSpam)
31         .setTimestampMillis(timestampMillis)
32         .setSpamMetadata(SpamMetadata.empty())
33         .build();
34   }
35 
36   /** Returns a SimpleSpamStatus that's not marked as spam and has no timestamp. */
notSpam()37   public static SimpleSpamStatus notSpam() {
38     return create(false, null);
39   }
40 
builder()41   public static Builder builder() {
42     return new AutoValue_SimpleSpamStatus.Builder();
43   }
44 
45   /** Creates instances of SimpleSpamStatus. */
46   @AutoValue.Builder
47   public abstract static class Builder {
setSpam(boolean isSpam)48     public abstract Builder setSpam(boolean isSpam);
49 
setTimestampMillis(Optional<Long> timestamp)50     abstract Builder setTimestampMillis(Optional<Long> timestamp);
51 
setTimestampMillis(@ullable Long timestampMillis)52     public Builder setTimestampMillis(@Nullable Long timestampMillis) {
53       return setTimestampMillis(Optional.fromNullable(timestampMillis));
54     }
55 
setSpamMetadata(SpamMetadata spamMetadata)56     public abstract Builder setSpamMetadata(SpamMetadata spamMetadata);
57 
build()58     public abstract SimpleSpamStatus build();
59   }
60 }
61