• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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.adservices.data.topics;
18 
19 import android.annotation.NonNull;
20 import android.app.adservices.topics.TopicParcel;
21 
22 import com.android.internal.annotations.Immutable;
23 
24 import com.google.auto.value.AutoValue;
25 
26 import java.util.Objects;
27 
28 /**
29  * POJO Represents a Topic.
30  *
31  * @hide
32  */
33 @Immutable
34 @AutoValue
35 public abstract class Topic {
36 
37     /**
38      * @return an Integer represents the topic details
39      */
getTopic()40     public abstract int getTopic();
41 
42     /**
43      * @return the taxonomy version number
44      */
getTaxonomyVersion()45     public abstract long getTaxonomyVersion();
46 
47     /**
48      * @return the model version number
49      */
getModelVersion()50     public abstract long getModelVersion();
51 
52     /**
53      * @return generic builder
54      */
55     @NonNull
builder()56     public static Builder builder() {
57         return new AutoValue_Topic.Builder();
58     }
59 
60     /**
61      * Creates an instance of Topic
62      *
63      * @param topic topic details
64      * @param taxonomyVersion taxonomy version number
65      * @param modelVersion model version number
66      * @return an instance of Topic
67      */
68     @NonNull
create( int topic, long taxonomyVersion, long modelVersion)69     public static Topic create(
70             int topic,
71             long taxonomyVersion,
72             long modelVersion) {
73         Objects.requireNonNull(topic);
74 
75         return builder().setTopic(topic)
76                 .setTaxonomyVersion(taxonomyVersion)
77                 .setModelVersion(modelVersion).build();
78     }
79 
80     /**
81      * Builder for {@link Topic}
82      */
83     @AutoValue.Builder
84     public abstract static class Builder {
85         /** Set Topic */
setTopic(int topic)86         public abstract Builder setTopic(int topic);
87 
88         /** Set Taxonomy Version */
setTaxonomyVersion(long taxonomyVersion)89         public abstract Builder setTaxonomyVersion(long taxonomyVersion);
90 
91         /** Set Model Version */
setModelVersion(long modelVersion)92         public abstract Builder setModelVersion(long modelVersion);
93 
94         /** Build a Topic instance */
95         @NonNull
build()96         public abstract Topic build();
97     }
98 
99     /**
100      * Return the parcel for this topic.
101      *
102      * @hide
103      */
104     @NonNull
convertTopicToTopicParcel()105     public TopicParcel convertTopicToTopicParcel() {
106         return new TopicParcel.Builder()
107                 .setTopicId(getTopic())
108                 .setTaxonomyVersion(getTaxonomyVersion())
109                 .setModelVersion(getModelVersion())
110                 .build();
111     }
112 }
113