Home | History | Annotate | Download | only in util
      1 /*
      2  * Copyright 2017 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.internal.telephony.util;
     18 
     19 import android.os.SystemClock;
     20 
     21 /**
     22  * A pair containing a value and an associated time stamp.
     23  *
     24  * @param <T> The type of the value.
     25  */
     26 public final class TimeStampedValue<T> {
     27 
     28     /** The value. */
     29     public final T mValue;
     30 
     31     /**
     32      * The value of {@link SystemClock#elapsedRealtime} or equivalent when value was
     33      * determined.
     34      */
     35     public final long mElapsedRealtime;
     36 
     37     public TimeStampedValue(T value, long elapsedRealtime) {
     38         this.mValue = value;
     39         this.mElapsedRealtime = elapsedRealtime;
     40     }
     41 
     42     @Override
     43     public boolean equals(Object o) {
     44         if (this == o) {
     45             return true;
     46         }
     47         if (o == null || getClass() != o.getClass()) {
     48             return false;
     49         }
     50 
     51         TimeStampedValue<?> that = (TimeStampedValue<?>) o;
     52 
     53         if (mElapsedRealtime != that.mElapsedRealtime) {
     54             return false;
     55         }
     56         return mValue != null ? mValue.equals(that.mValue) : that.mValue == null;
     57     }
     58 
     59     @Override
     60     public int hashCode() {
     61         int result = mValue != null ? mValue.hashCode() : 0;
     62         result = 31 * result + (int) (mElapsedRealtime ^ (mElapsedRealtime >>> 32));
     63         return result;
     64     }
     65 
     66     @Override
     67     public String toString() {
     68         return "TimeStampedValue{"
     69                 + "mValue=" + mValue
     70                 + ", elapsedRealtime=" + mElapsedRealtime
     71                 + '}';
     72     }
     73 }
     74