• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 android.federatedcompute.common;
18 
19 import android.annotation.Nullable;
20 import android.os.Parcelable;
21 
22 import com.android.internal.util.Preconditions;
23 import com.android.ondevicepersonalization.internal.util.DataClass;
24 
25 /**
26  * Training interval settings.
27  *
28  * @hide
29  */
30 @DataClass(genBuilder = true, genEqualsHashCode = true)
31 public final class TrainingInterval implements Parcelable {
32     /**
33      * The scheduling modes for a task. Recurrent tasks will be rescheduled after each run. One-off
34      * task will not be rescheduled if the task succeeds.
35      */
36     public static final int SCHEDULING_MODE_RECURRENT = 1;
37 
38     public static final int SCHEDULING_MODE_ONE_TIME = 2;
39 
40     @SchedulingMode private int mSchedulingMode;
41 
42     private long mMinimumIntervalMillis = 0L;
43 
44     // Code below generated by codegen v1.0.23.
45     //
46     // DO NOT MODIFY!
47     // CHECKSTYLE:OFF Generated code
48     //
49     // To regenerate run:
50     // $ codegen
51     // $ANDROID_BUILD_TOP/packages/modules/OnDevicePersonalization/framework/java/android/ondevicepersonalization/federatedcompute/TrainingInterval.java
52     //
53     // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
54     //   Settings > Editor > Code Style > Formatter Control
55     // @formatter:off
56 
57     @android.annotation.IntDef(
58             prefix = "SCHEDULING_MODE_",
59             value = {SCHEDULING_MODE_RECURRENT, SCHEDULING_MODE_ONE_TIME})
60     @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE)
61     @DataClass.Generated.Member
62     public @interface SchedulingMode {}
63 
64     @DataClass.Generated.Member
schedulingModeToString(@chedulingMode int value)65     public static String schedulingModeToString(@SchedulingMode int value) {
66         switch (value) {
67             case SCHEDULING_MODE_RECURRENT:
68                 return "SCHEDULING_MODE_RECURRENT";
69             case SCHEDULING_MODE_ONE_TIME:
70                 return "SCHEDULING_MODE_ONE_TIME";
71             default:
72                 return Integer.toHexString(value);
73         }
74     }
75 
76     @DataClass.Generated.Member
TrainingInterval( @chedulingMode int schedulingMode, long minimumIntervalMillis)77     /* package-private */ TrainingInterval(
78             @SchedulingMode int schedulingMode, long minimumIntervalMillis) {
79         this.mSchedulingMode = schedulingMode;
80 
81         if (!(mSchedulingMode == SCHEDULING_MODE_RECURRENT)
82                 && !(mSchedulingMode == SCHEDULING_MODE_ONE_TIME)) {
83             throw new java.lang.IllegalArgumentException(
84                     "schedulingMode was "
85                             + mSchedulingMode
86                             + " but must be one of: "
87                             + "SCHEDULING_MODE_RECURRENT("
88                             + SCHEDULING_MODE_RECURRENT
89                             + "), "
90                             + "SCHEDULING_MODE_ONE_TIME("
91                             + SCHEDULING_MODE_ONE_TIME
92                             + ")");
93         }
94         Preconditions.checkArgument(
95                 schedulingMode != SCHEDULING_MODE_RECURRENT || minimumIntervalMillis > 0,
96                 "Recurrent jobs cannot have non-positive minimal interval.");
97 
98         this.mMinimumIntervalMillis = minimumIntervalMillis;
99 
100         // onConstructed(); // You can define this method to get a callback
101     }
102 
103     @DataClass.Generated.Member
getSchedulingMode()104     public @SchedulingMode int getSchedulingMode() {
105         return mSchedulingMode;
106     }
107 
108     @DataClass.Generated.Member
getMinimumIntervalMillis()109     public long getMinimumIntervalMillis() {
110         return mMinimumIntervalMillis;
111     }
112 
113     @Override
114     @DataClass.Generated.Member
equals(@ullable Object o)115     public boolean equals(@Nullable Object o) {
116         // You can override field equality logic by defining either of the methods like:
117         // boolean fieldNameEquals(TrainingInterval other) { ... }
118         // boolean fieldNameEquals(FieldType otherValue) { ... }
119 
120         if (this == o) return true;
121         if (o == null || getClass() != o.getClass()) return false;
122         @SuppressWarnings("unchecked")
123         TrainingInterval that = (TrainingInterval) o;
124         //noinspection PointlessBooleanExpression
125         return true
126                 && mSchedulingMode == that.mSchedulingMode
127                 && mMinimumIntervalMillis == that.mMinimumIntervalMillis;
128     }
129 
130     @Override
131     @DataClass.Generated.Member
hashCode()132     public int hashCode() {
133         // You can override field hashCode logic by defining methods like:
134         // int fieldNameHashCode() { ... }
135 
136         int _hash = 1;
137         _hash = 31 * _hash + mSchedulingMode;
138         _hash = 31 * _hash + Long.hashCode(mMinimumIntervalMillis);
139         return _hash;
140     }
141 
142     @Override
143     @DataClass.Generated.Member
writeToParcel(@ndroid.annotation.NonNull android.os.Parcel dest, int flags)144     public void writeToParcel(@android.annotation.NonNull android.os.Parcel dest, int flags) {
145         // You can override field parcelling by defining methods like:
146         // void parcelFieldName(Parcel dest, int flags) { ... }
147 
148         dest.writeInt(mSchedulingMode);
149         dest.writeLong(mMinimumIntervalMillis);
150     }
151 
152     @Override
153     @DataClass.Generated.Member
describeContents()154     public int describeContents() {
155         return 0;
156     }
157 
158     /** @hide */
159     @SuppressWarnings({"unchecked", "RedundantCast"})
160     @DataClass.Generated.Member
TrainingInterval(@ndroid.annotation.NonNull android.os.Parcel in)161     /* package-private */ TrainingInterval(@android.annotation.NonNull android.os.Parcel in) {
162         // You can override field unparcelling by defining methods like:
163         // static FieldType unparcelFieldName(Parcel in) { ... }
164 
165         int schedulingMode = in.readInt();
166         long minimumIntervalMillis = in.readLong();
167 
168         this.mSchedulingMode = schedulingMode;
169 
170         if (!(mSchedulingMode == SCHEDULING_MODE_RECURRENT)
171                 && !(mSchedulingMode == SCHEDULING_MODE_ONE_TIME)) {
172             throw new java.lang.IllegalArgumentException(
173                     "schedulingMode was "
174                             + mSchedulingMode
175                             + " but must be one of: "
176                             + "SCHEDULING_MODE_RECURRENT("
177                             + SCHEDULING_MODE_RECURRENT
178                             + "), "
179                             + "SCHEDULING_MODE_ONE_TIME("
180                             + SCHEDULING_MODE_ONE_TIME
181                             + ")");
182         }
183 
184         this.mMinimumIntervalMillis = minimumIntervalMillis;
185 
186         // onConstructed(); // You can define this method to get a callback
187     }
188 
189     @DataClass.Generated.Member
190     public static final @android.annotation.NonNull Parcelable.Creator<TrainingInterval> CREATOR =
191             new Parcelable.Creator<TrainingInterval>() {
192                 @Override
193                 public TrainingInterval[] newArray(int size) {
194                     return new TrainingInterval[size];
195                 }
196 
197                 @Override
198                 public TrainingInterval createFromParcel(
199                         @android.annotation.NonNull android.os.Parcel in) {
200                     return new TrainingInterval(in);
201                 }
202             };
203 
204     /** A builder for {@link TrainingInterval} */
205     @SuppressWarnings("WeakerAccess")
206     @DataClass.Generated.Member
207     public static final class Builder {
208 
209         private @SchedulingMode int mSchedulingMode;
210         private long mMinimumIntervalMillis;
211 
212         private long mBuilderFieldsSet = 0L;
213 
Builder()214         public Builder() {}
215 
216         @DataClass.Generated.Member
setSchedulingMode(@chedulingMode int value)217         public @android.annotation.NonNull Builder setSchedulingMode(@SchedulingMode int value) {
218             checkNotUsed();
219             mBuilderFieldsSet |= 0x1;
220             mSchedulingMode = value;
221             return this;
222         }
223 
224         @DataClass.Generated.Member
setMinimumIntervalMillis(long value)225         public @android.annotation.NonNull Builder setMinimumIntervalMillis(long value) {
226             checkNotUsed();
227             mBuilderFieldsSet |= 0x2;
228             mMinimumIntervalMillis = value;
229             return this;
230         }
231 
232         /** Builds the instance. This builder should not be touched after calling this! */
build()233         public @android.annotation.NonNull TrainingInterval build() {
234             checkNotUsed();
235             mBuilderFieldsSet |= 0x4; // Mark builder used
236 
237             if ((mBuilderFieldsSet & 0x2) == 0) {
238                 mMinimumIntervalMillis = 0L;
239             }
240             TrainingInterval o = new TrainingInterval(mSchedulingMode, mMinimumIntervalMillis);
241             return o;
242         }
243 
checkNotUsed()244         private void checkNotUsed() {
245             if ((mBuilderFieldsSet & 0x4) != 0) {
246                 throw new IllegalStateException(
247                         "This Builder should not be reused. Use a new Builder instance instead");
248             }
249         }
250     }
251 
252     // @formatter:on
253     // End of generated code
254 
255 }
256