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 com.android.telephony.statslib; 18 19 import android.util.StatsEvent; 20 21 import java.util.Objects; 22 23 /** AtomsPulledTestInfo class */ 24 public class AtomsPulledTestInfo extends AtomsPulled { 25 26 /** atom #1 : test atom #1 type */ 27 private int mType; 28 29 /** atom #2 : test atom #2 count */ 30 private int mCount; 31 32 /** Constructor of AtomsTestInfo */ AtomsPulledTestInfo()33 public AtomsPulledTestInfo() {} 34 35 /** Constructor of AtomsPulledTestInfo */ AtomsPulledTestInfo(int type, int count)36 public AtomsPulledTestInfo(int type, int count) { 37 mType = type; 38 mCount = count; 39 } 40 41 /** 42 * Copy Constructor of AtomsPulledTestInfo 43 * 44 * @param info The info param to copy from. 45 */ AtomsPulledTestInfo(AtomsPulledTestInfo info)46 public AtomsPulledTestInfo(AtomsPulledTestInfo info) { 47 mType = info.mType; 48 mCount = info.mCount; 49 } 50 51 /** 52 * Write the atom information to be recorded to the builder according to the type in order. 53 * 54 * @param builder Builder class for StatsEvent Builder object. 55 */ 56 @Override build(StatsEvent.Builder builder)57 public void build(StatsEvent.Builder builder) { 58 builder.writeInt(mType); // atom #1 59 builder.writeInt(mCount); // atom #2 60 } 61 62 /** Return atom id defined in proto. */ 63 @Override getStatsId()64 public int getStatsId() { 65 return 700; 66 } 67 68 /** Return copy of the AtomsTestInfo */ 69 @Override copy()70 public AtomsPulled copy() { 71 return new AtomsPulledTestInfo(this); 72 } 73 74 @Override getDimension()75 public String getDimension() { 76 return Integer.toString(mType); 77 } 78 accumulate(AtomsPulled info)79 public void accumulate(AtomsPulled info) { 80 if (!(info instanceof AtomsPulledTestInfo)) { 81 return; 82 } 83 AtomsPulledTestInfo atomsPulledTestInfo = (AtomsPulledTestInfo) info; 84 this.mCount += atomsPulledTestInfo.getCount(); 85 } 86 getType()87 public int getType() { 88 return mType; 89 } 90 setType(int type)91 public void setType(int type) { 92 mType = type; 93 } 94 getCount()95 public int getCount() { 96 return mCount; 97 } 98 setCount(int count)99 public void setCount(int count) { 100 mCount = count; 101 } 102 103 @Override toString()104 public String toString() { 105 return "AtomsPulledTestInfo{" + "mType=" + mType + ", mCount=" + mCount + '}'; 106 } 107 108 @Override equals(Object o)109 public boolean equals(Object o) { 110 if (this == o) return true; 111 if (!(o instanceof AtomsPulledTestInfo)) return false; 112 AtomsPulledTestInfo that = (AtomsPulledTestInfo) o; 113 return mType == that.mType && mCount == that.mCount; 114 } 115 116 @Override hashCode()117 public int hashCode() { 118 return Objects.hash(mType, mCount); 119 } 120 } 121