I am trying to create a table
class that extends ArrayList
. In it, I would like to be able to create a map
method that takes a lambda expression and returns a new table
with the mapped values. I would also like to do this with filter
. I use the map and filter a lot and I don't like typing out the whole thing over and over.
public abstract class Table<E extends Element> extends ArrayList<E> {
// a lot of other stuff.
public Table<E> map(/*WHAT DO I PUT HERE?*/ mapper) {
return this.stream().map(mapper).collect(/*WHAT DO I PUT HERE?*/);
}
public Table<E> filter(/*WHAT DO I PUT HERE?*/ predicate) {
return this.stream().filter(predicate).collect(/*WHAT DO I PUT HERE?*/);
}
}
I am still trying to figure out generics. Maybe there is a better way. I don't know. I have tried duplicating what is in the original code for the ArrayList
, but everything I try seems to create new problems.
WHAT DO I PUT HERE
you should provide your new logic for the new functionality that you are adding. – BerninaTable
is an abstract class, how would you collect into it? – SkiteList
is an interface, how wouldCollectors.toList
collect into it? – BeetCollectors.toList
uses theArrayList
-based collector while here I don't see any subclass to provide default logic – SkiteTable
has a lot of children and map should return the child table. – SchiroArrayList
is not a good idea. – Universityclass Table implements List
and useArrayList
under the hood. – Dante