1 /*
2  * Copyright (C) 2016 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.ahat.heapdump;
18 
19 public class FieldValue implements Diffable<FieldValue> {
20   private final String mName;
21   private final String mType;
22   private final Value mValue;
23   private FieldValue mBaseline;
24   private final boolean mIsPlaceHolder;
25 
FieldValue(String name, String type, Value value)26   public FieldValue(String name, String type, Value value) {
27     mName = name;
28     mType = type;
29     mValue = value;
30     mBaseline = this;
31     mIsPlaceHolder = false;
32   }
33 
34   /**
35    * Construct a place holder FieldValue
36    */
FieldValue(FieldValue baseline)37   private FieldValue(FieldValue baseline) {
38     mName = baseline.mName;
39     mType = baseline.mType;
40     mValue = Value.getBaseline(baseline.mValue);
41     mBaseline = baseline;
42     mIsPlaceHolder = true;
43   }
44 
newPlaceHolderFieldValue(FieldValue baseline)45   static FieldValue newPlaceHolderFieldValue(FieldValue baseline) {
46     FieldValue field = new FieldValue(baseline);
47     baseline.setBaseline(field);
48     return field;
49   }
50 
51   /**
52    * Returns the name of the field.
53    */
getName()54   public String getName() {
55     return mName;
56   }
57 
58   /**
59    * Returns a description of the type of the field.
60    */
getType()61   public String getType() {
62     return mType;
63   }
64 
65   /**
66    * Returns the value of this field.
67    */
getValue()68   public Value getValue() {
69     return mValue;
70   }
71 
setBaseline(FieldValue baseline)72   public void setBaseline(FieldValue baseline) {
73     mBaseline = baseline;
74   }
75 
getBaseline()76   @Override public FieldValue getBaseline() {
77     return mBaseline;
78   }
79 
isPlaceHolder()80   @Override public boolean isPlaceHolder() {
81     return mIsPlaceHolder;
82   }
83 }
84