1 /* 2 * Copyright (C) 2024 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.federatedcompute.services.data; 18 19 import android.annotation.NonNull; 20 21 import com.android.ondevicepersonalization.internal.util.AnnotationValidations; 22 import com.android.ondevicepersonalization.internal.util.DataClass; 23 24 /** Contains the details of a training task history. */ 25 @DataClass(genBuilder = true, genEqualsHashCode = true) 26 public class TaskHistory { 27 /** The job id of this federated compute job. */ 28 @NonNull private int mJobId; 29 30 /** The name of the federated compute population. */ 31 @NonNull private String mPopulationName; 32 33 /** 34 * The name of the task within the population. One population may have multiple tasks. The task 35 * name can be used to uniquely identify the job. 36 */ 37 @NonNull private String mTaskId; 38 39 // The timestamp when device uploads training result to servers done. 40 @NonNull private long mContributionTime; 41 42 // The latest round number that device contribute training result successfully. The round number 43 // is 44 // returned by federated compute server when assigning task to device. 45 @NonNull private long mContributionRound = 0; 46 47 // The total number that device has participate in the training per task per population. 48 @NonNull private long mTotalParticipation = 0; 49 50 // Code below generated by codegen v1.0.23. 51 // 52 // DO NOT MODIFY! 53 // CHECKSTYLE:OFF Generated code 54 // 55 // To regenerate run: 56 // $ codegen 57 // $ANDROID_BUILD_TOP/packages/modules/OnDevicePersonalization/federatedcompute/src/com/android/federatedcompute/services/data/TaskHistory.java 58 // 59 // To exclude the generated code from IntelliJ auto-formatting enable (one-time): 60 // Settings > Editor > Code Style > Formatter Control 61 // @formatter:off 62 63 @DataClass.Generated.Member TaskHistory( @onNull int jobId, @NonNull String populationName, @NonNull String taskId, @NonNull long contributionTime, @NonNull long contributionRound, @NonNull long totalParticipation)64 /* package-private */ TaskHistory( 65 @NonNull int jobId, 66 @NonNull String populationName, 67 @NonNull String taskId, 68 @NonNull long contributionTime, 69 @NonNull long contributionRound, 70 @NonNull long totalParticipation) { 71 this.mJobId = jobId; 72 AnnotationValidations.validate(NonNull.class, null, mJobId); 73 this.mPopulationName = populationName; 74 AnnotationValidations.validate(NonNull.class, null, mPopulationName); 75 this.mTaskId = taskId; 76 AnnotationValidations.validate(NonNull.class, null, mTaskId); 77 this.mContributionTime = contributionTime; 78 AnnotationValidations.validate(NonNull.class, null, mContributionTime); 79 this.mContributionRound = contributionRound; 80 AnnotationValidations.validate(NonNull.class, null, mContributionRound); 81 this.mTotalParticipation = totalParticipation; 82 AnnotationValidations.validate(NonNull.class, null, mTotalParticipation); 83 84 // onConstructed(); // You can define this method to get a callback 85 } 86 87 /** The job id of this federated compute job. */ 88 @DataClass.Generated.Member getJobId()89 public @NonNull int getJobId() { 90 return mJobId; 91 } 92 93 /** The name of the federated compute population. */ 94 @DataClass.Generated.Member getPopulationName()95 public @NonNull String getPopulationName() { 96 return mPopulationName; 97 } 98 99 /** 100 * The name of the task within the population. One population may have multiple tasks. The task 101 * name can be used to uniquely identify the job. 102 */ 103 @DataClass.Generated.Member getTaskId()104 public @NonNull String getTaskId() { 105 return mTaskId; 106 } 107 108 @DataClass.Generated.Member getContributionTime()109 public @NonNull long getContributionTime() { 110 return mContributionTime; 111 } 112 113 @DataClass.Generated.Member getContributionRound()114 public @NonNull long getContributionRound() { 115 return mContributionRound; 116 } 117 118 @DataClass.Generated.Member getTotalParticipation()119 public @NonNull long getTotalParticipation() { 120 return mTotalParticipation; 121 } 122 123 @Override 124 @DataClass.Generated.Member equals(@ndroid.annotation.Nullable Object o)125 public boolean equals(@android.annotation.Nullable Object o) { 126 // You can override field equality logic by defining either of the methods like: 127 // boolean fieldNameEquals(TaskHistory other) { ... } 128 // boolean fieldNameEquals(FieldType otherValue) { ... } 129 130 if (this == o) return true; 131 if (o == null || getClass() != o.getClass()) return false; 132 @SuppressWarnings("unchecked") 133 TaskHistory that = (TaskHistory) o; 134 //noinspection PointlessBooleanExpression 135 return true 136 && mJobId == that.mJobId 137 && java.util.Objects.equals(mPopulationName, that.mPopulationName) 138 && java.util.Objects.equals(mTaskId, that.mTaskId) 139 && mContributionTime == that.mContributionTime 140 && mContributionRound == that.mContributionRound 141 && mTotalParticipation == that.mTotalParticipation; 142 } 143 144 @Override 145 @DataClass.Generated.Member hashCode()146 public int hashCode() { 147 // You can override field hashCode logic by defining methods like: 148 // int fieldNameHashCode() { ... } 149 150 int _hash = 1; 151 _hash = 31 * _hash + mJobId; 152 _hash = 31 * _hash + java.util.Objects.hashCode(mPopulationName); 153 _hash = 31 * _hash + java.util.Objects.hashCode(mTaskId); 154 _hash = 31 * _hash + Long.hashCode(mContributionTime); 155 _hash = 31 * _hash + Long.hashCode(mContributionRound); 156 _hash = 31 * _hash + Long.hashCode(mTotalParticipation); 157 return _hash; 158 } 159 160 /** A builder for {@link TaskHistory} */ 161 @SuppressWarnings("WeakerAccess") 162 @DataClass.Generated.Member 163 public static class Builder { 164 165 private @NonNull int mJobId; 166 private @NonNull String mPopulationName; 167 private @NonNull String mTaskId; 168 private @NonNull long mContributionTime; 169 private @NonNull long mContributionRound; 170 private @NonNull long mTotalParticipation; 171 172 private long mBuilderFieldsSet = 0L; 173 Builder()174 public Builder() {} 175 176 /** The job id of this federated compute job. */ 177 @DataClass.Generated.Member setJobId(@onNull int value)178 public @NonNull Builder setJobId(@NonNull int value) { 179 checkNotUsed(); 180 mBuilderFieldsSet |= 0x1; 181 mJobId = value; 182 return this; 183 } 184 185 /** The name of the federated compute population. */ 186 @DataClass.Generated.Member setPopulationName(@onNull String value)187 public @NonNull Builder setPopulationName(@NonNull String value) { 188 checkNotUsed(); 189 mBuilderFieldsSet |= 0x2; 190 mPopulationName = value; 191 return this; 192 } 193 194 /** 195 * The name of the task within the population. One population may have multiple tasks. The 196 * task name can be used to uniquely identify the job. 197 */ 198 @DataClass.Generated.Member setTaskId(@onNull String value)199 public @NonNull Builder setTaskId(@NonNull String value) { 200 checkNotUsed(); 201 mBuilderFieldsSet |= 0x4; 202 mTaskId = value; 203 return this; 204 } 205 206 @DataClass.Generated.Member setContributionTime(@onNull long value)207 public @NonNull Builder setContributionTime(@NonNull long value) { 208 checkNotUsed(); 209 mBuilderFieldsSet |= 0x8; 210 mContributionTime = value; 211 return this; 212 } 213 214 @DataClass.Generated.Member setContributionRound(@onNull long value)215 public @NonNull Builder setContributionRound(@NonNull long value) { 216 checkNotUsed(); 217 mBuilderFieldsSet |= 0x10; 218 mContributionRound = value; 219 return this; 220 } 221 222 @DataClass.Generated.Member setTotalParticipation(@onNull long value)223 public @NonNull Builder setTotalParticipation(@NonNull long value) { 224 checkNotUsed(); 225 mBuilderFieldsSet |= 0x20; 226 mTotalParticipation = value; 227 return this; 228 } 229 230 /** Builds the instance. This builder should not be touched after calling this! */ build()231 public @NonNull TaskHistory build() { 232 checkNotUsed(); 233 mBuilderFieldsSet |= 0x40; // Mark builder used 234 235 if ((mBuilderFieldsSet & 0x10) == 0) { 236 mContributionRound = 0; 237 } 238 if ((mBuilderFieldsSet & 0x20) == 0) { 239 mTotalParticipation = 0; 240 } 241 TaskHistory o = 242 new TaskHistory( 243 mJobId, 244 mPopulationName, 245 mTaskId, 246 mContributionTime, 247 mContributionRound, 248 mTotalParticipation); 249 return o; 250 } 251 checkNotUsed()252 private void checkNotUsed() { 253 if ((mBuilderFieldsSet & 0x40) != 0) { 254 throw new IllegalStateException( 255 "This Builder should not be reused. Use a new Builder instance instead"); 256 } 257 } 258 } 259 260 // @formatter:on 261 // End of generated code 262 263 } 264