Entry.java
4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package com.github.mikephil.charting.data;
import android.graphics.drawable.Drawable;
import android.os.Parcel;
import android.os.ParcelFormatException;
import android.os.Parcelable;
import com.github.mikephil.charting.utils.Utils;
/**
* Class representing one entry in the chart. Might contain multiple values.
* Might only contain a single value depending on the used constructor.
*
* @author Philipp Jahoda
*/
public class Entry extends BaseEntry implements Parcelable {
/** the x value */
private float x = 0f;
public Entry() {
}
/**
* A Entry represents one single entry in the chart.
*
* @param x the x value
* @param y the y value (the actual value of the entry)
*/
public Entry(float x, float y) {
super(y);
this.x = x;
}
/**
* A Entry represents one single entry in the chart.
*
* @param x the x value
* @param y the y value (the actual value of the entry)
* @param data Spot for additional data this Entry represents.
*/
public Entry(float x, float y, Object data) {
super(y, data);
this.x = x;
}
/**
* A Entry represents one single entry in the chart.
*
* @param x the x value
* @param y the y value (the actual value of the entry)
* @param icon icon image
*/
public Entry(float x, float y, Drawable icon) {
super(y, icon);
this.x = x;
}
/**
* A Entry represents one single entry in the chart.
*
* @param x the x value
* @param y the y value (the actual value of the entry)
* @param icon icon image
* @param data Spot for additional data this Entry represents.
*/
public Entry(float x, float y, Drawable icon, Object data) {
super(y, icon, data);
this.x = x;
}
/**
* Returns the x-value of this Entry object.
*
* @return
*/
public float getX() {
return x;
}
/**
* Sets the x-value of this Entry object.
*
* @param x
*/
public void setX(float x) {
this.x = x;
}
/**
* returns an exact copy of the entry
*
* @return
*/
public Entry copy() {
Entry e = new Entry(x, getY(), getData());
return e;
}
/**
* Compares value, xIndex and data of the entries. Returns true if entries
* are equal in those points, false if not. Does not check by hash-code like
* it's done by the "equals" method.
*
* @param e
* @return
*/
public boolean equalTo(Entry e) {
if (e == null)
return false;
if (e.getData() != this.getData())
return false;
if (Math.abs(e.x - this.x) > Utils.FLOAT_EPSILON)
return false;
if (Math.abs(e.getY() - this.getY()) > Utils.FLOAT_EPSILON)
return false;
return true;
}
/**
* returns a string representation of the entry containing x-index and value
*/
@Override
public String toString() {
return "Entry, x: " + x + " y: " + getY();
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeFloat(this.x);
dest.writeFloat(this.getY());
if (getData() != null) {
if (getData() instanceof Parcelable) {
dest.writeInt(1);
dest.writeParcelable((Parcelable) this.getData(), flags);
} else {
throw new ParcelFormatException("Cannot parcel an Entry with non-parcelable data");
}
} else {
dest.writeInt(0);
}
}
protected Entry(Parcel in) {
this.x = in.readFloat();
this.setY(in.readFloat());
if (in.readInt() == 1) {
this.setData(in.readParcelable(Object.class.getClassLoader()));
}
}
public static final Parcelable.Creator<Entry> CREATOR = new Parcelable.Creator<Entry>() {
public Entry createFromParcel(Parcel source) {
return new Entry(source);
}
public Entry[] newArray(int size) {
return new Entry[size];
}
};
}