20
20
import java .util .Collection ;
21
21
import java .util .Collections ;
22
22
import java .util .List ;
23
+ import java .util .stream .Collectors ;
23
24
24
25
25
26
public abstract class Dataset <T extends Dataset <T , O >, O >
26
27
{
27
- protected final List <O > data = new ArrayList <>();
28
+ protected final List <Object > data = new ArrayList <>();
28
29
29
30
/**
30
31
* @return an unmodifiable view of the data held in this {@code Dataset}, never {@code null}
31
32
*/
32
- public List <O > getData ()
33
+ public List <Object > getData ()
33
34
{
34
35
return Collections .unmodifiableList (this .data );
35
36
}
36
37
37
38
/**
38
- * Sets the backing data list to the argument, replacing any data already added or set
39
- *
40
- * @param data The data to plot in a line
39
+ * @return an unmodifiable view of the data held in this {@code Dataset}, never {@code null}
41
40
*/
42
- public T setData (final Collection <O > data )
41
+ public <X > List <X > getData (final Class <X > filterClazz )
42
+ {
43
+ return this .data .stream ()
44
+ .filter (filterClazz ::isInstance )
45
+ .map (filterClazz ::cast )
46
+ .collect (Collectors .toUnmodifiableList ());
47
+ }
48
+
49
+ /**
50
+ * @see #setData(Collection)
51
+ */
52
+ public T setDataUnchecked (final Collection <?> data )
43
53
{
44
54
this .clearData ();
45
55
if (data != null )
@@ -54,14 +64,28 @@ public T setData(final Collection<O> data)
54
64
*
55
65
* @param data The data to plot in a line
56
66
*/
67
+ public T setData (final Collection <O > data )
68
+ {
69
+ return this .setDataUnchecked (data );
70
+ }
71
+
72
+ /**
73
+ * @see #setData(Object[])
74
+ */
75
+ public T setDataUnchecked (final Object ... data )
76
+ {
77
+ return this .setDataUnchecked (Arrays .asList (data ));
78
+ }
79
+
80
+ /**
81
+ * Sets the backing data list to the argument, replacing any data already added or set
82
+ *
83
+ * @param data The data to plot in a line
84
+ */
85
+ @ SuppressWarnings ("unchecked" ) // Works fine
57
86
public T setData (final O ... data )
58
87
{
59
- this .clearData ();
60
- if (data != null )
61
- {
62
- this .data .addAll (Arrays .asList (data ));
63
- }
64
- return this .self ();
88
+ return this .setData (Arrays .asList (data ));
65
89
}
66
90
67
91
/**
@@ -73,6 +97,15 @@ public T clearData()
73
97
return this .self ();
74
98
}
75
99
100
+ /**
101
+ * @see #addData(Object)
102
+ */
103
+ public T addDataUnchecked (final Object data )
104
+ {
105
+ this .data .add (data );
106
+ return this .self ();
107
+ }
108
+
76
109
/**
77
110
* Add the data point to this {@code Dataset}
78
111
*
@@ -81,8 +114,7 @@ public T clearData()
81
114
*/
82
115
public T addData (final O data )
83
116
{
84
- this .data .add (data );
85
- return this .self ();
117
+ return this .addDataUnchecked (data );
86
118
}
87
119
88
120
@ SuppressWarnings ("unchecked" )
0 commit comments