T - the type of values contained in the column this table points topublic class ObjectTable<T> extends Table<T>
Table specialized for model objects.
Using reflection, it provides more functionality for expanding and filtering based on attributes and associations.| Constructor and Description |
|---|
ObjectTable(java.lang.String colName,
T... start) |
ObjectTable(T... start) |
| Modifier and Type | Method and Description |
|---|---|
void |
addColumn(java.lang.String columnName,
java.util.function.Function<java.util.LinkedHashMap<java.lang.String,java.lang.Object>,java.lang.Object> function)
Deprecated.
since 1.2; use
Table.derive(String, Function) instead |
ObjectTable<T> |
dropColumns(java.lang.String... columnNames)
Removes all given columns from the underlying data structure and ensures no duplicate rows exist afterwards.
|
<U> ObjectTable<U> |
expand(java.lang.String columnName,
java.util.function.Function<? super T,? extends U> function)
Creates a new column with the given name by applying the given function to each object in the column pointed to by
this table.
|
<U> ObjectTable<U> |
expandAll(java.lang.String columnName,
java.util.function.Function<? super T,? extends java.util.Collection<? extends U>> function)
Creates a new column with the given name by applying the given function to each object in the column pointed to by
this table, and flattening the result.
|
<U> Table<U> |
expandAttribute(java.lang.String newColumnName,
java.lang.String attrName)
Creates a new column by expanding the given attribute from cells of the column this table points to.
|
BooleanTable |
expandBoolean(java.lang.String newColumnName,
java.lang.String attrName)
Equivalent to:
|
doubleTable |
expandDouble(java.lang.String newColumnName,
java.lang.String attrName)
Equivalent to:
|
floatTable |
expandFloat(java.lang.String newColumnName,
java.lang.String attrName)
Equivalent to:
|
intTable |
expandInt(java.lang.String newColumnName,
java.lang.String attrName)
Equivalent to:
|
<U> ObjectTable<U> |
expandLink(java.lang.String newColumnName,
java.lang.String linkName)
Creates a new column by expanding the given link from the cells of the column this table points to.
|
longTable |
expandLong(java.lang.String newColumnName,
java.lang.String attrName)
Equivalent to:
|
StringTable |
expandString(java.lang.String newColumnName,
java.lang.String attrName)
Equivalent to:
|
ObjectTable<T> |
filter(java.util.function.Predicate<? super T> predicate)
Removes all rows from this table for which the predicate returned
false when passed the cell value of the
column this table points to. |
ObjectTable<T> |
filterRow(java.util.function.Predicate<java.util.LinkedHashMap<java.lang.String,java.lang.Object>> predicate)
Deprecated.
since 1.2; use
Table.filterRows(Predicate) instead |
org.fulib.yaml.ReflectorMap |
getReflectorMap() |
ObjectTable<T> |
hasLink(java.lang.String linkName,
ObjectTable<?> otherTable)
Removes all rows where the cell value does not have the named link to the cell value of the other table in the
same row.
|
ObjectTable<T> |
selectColumns(java.lang.String... columnNames)
Removes all columns from the underlying data structure except the given ones, and ensures no duplicate rows exist
afterwards.
|
ObjectTable<T> |
setColumnMap(java.util.LinkedHashMap<java.lang.String,java.lang.Integer> columnMap)
Deprecated.
since 1.2; for internal use only
|
ObjectTable<T> |
setColumnName(java.lang.String columnName)
Deprecated.
since 1.2; set via the constructor and not meant to be changed afterward
|
void |
setReflectorMap(org.fulib.yaml.ReflectorMap reflectorMap) |
ObjectTable<T> |
setTable(java.util.ArrayList<java.util.ArrayList<java.lang.Object>> table)
Deprecated.
since 1.2; for internal use only
|
java.util.LinkedHashSet<T> |
toSet() |
as, copy, derive, deriveAll, filterRows, getColumnMap, getColumnName, getTable, iterator, rowCount, stream, toList, toString@SafeVarargs public ObjectTable(T... start)
@SafeVarargs
public ObjectTable(java.lang.String colName,
T... start)
public org.fulib.yaml.ReflectorMap getReflectorMap()
public void setReflectorMap(org.fulib.yaml.ReflectorMap reflectorMap)
public ObjectTable<T> hasLink(java.lang.String linkName, ObjectTable<?> otherTable)
otherTable to check for self-associations.
Essentially equivalent to:
this.filterRows(row -> {
Object source = row.get(this.getColumn());
Object target = row.get(otherTable.getColumn());
Object linkValue = source.get<linkName>(); // via reflection
return linkValue == target || linkValue instanceof Collection && ((Collection) linkValue).contains(other);
});
linkName - the name of the property on this table's objectsotherTable - the table pointing to the column with link targetsTable.filterRows(Predicate)public <U> ObjectTable<U> expandLink(java.lang.String newColumnName, java.lang.String linkName)
null do not create a row.
Essentially equivalent to:
this.expandAll(newColumnName, source -> {
final Object target = source.get<linkName>(); // via reflection
if (target instanceof Collection) {
return target;
}
else if (target == null) {
return Collections.emptyList();
}
else {
return Collections.singleton(target);
}
}
U - the type of the target objectsnewColumnName - the name of the new columnlinkName - the name of the property to expandexpandAll(String, Function)public <U> Table<U> expandAttribute(java.lang.String newColumnName, java.lang.String attrName)
Essentially equivalent to:
this.expand(newColumnName, start -> {
return start.get<attrName>(); // via reflection
});
U - the type of the attributenewColumnName - the name of the new columnattrName - the name of the attribute to expandexpand(String, Function)public doubleTable expandDouble(java.lang.String newColumnName, java.lang.String attrName)
this.expandAttribute(newColumnName, attrName).as(doubleTable.class);
newColumnName - the name of the new columnattrName - the name of the attribute to expandexpandAttribute(String, String)public floatTable expandFloat(java.lang.String newColumnName, java.lang.String attrName)
this.expandAttribute(newColumnName, attrName).as(floatTable.class);
newColumnName - the name of the new columnattrName - the name of the attribute to expandexpandAttribute(String, String)public intTable expandInt(java.lang.String newColumnName, java.lang.String attrName)
this.expandAttribute(newColumnName, attrName).as(intTable.class);
newColumnName - the name of the new columnattrName - the name of the attribute to expandexpandAttribute(String, String)public longTable expandLong(java.lang.String newColumnName, java.lang.String attrName)
this.expandAttribute(newColumnName, attrName).as(longTable.class);
newColumnName - the name of the new columnattrName - the name of the attribute to expandexpandAttribute(String, String)public StringTable expandString(java.lang.String newColumnName, java.lang.String attrName)
this.expandAttribute(newColumnName, attrName).as(StringTable.class);
newColumnName - the name of the new columnattrName - the name of the attribute to expandexpandAttribute(String, String)public BooleanTable expandBoolean(java.lang.String newColumnName, java.lang.String attrName)
this.expandAttribute(newColumnName, attrName).as(BooleanTable.class);
newColumnName - the name of the new columnattrName - the name of the attribute to expandexpandAttribute(String, String)public <U> ObjectTable<U> expand(java.lang.String columnName, java.util.function.Function<? super T,? extends U> function)
TableExample:
Table<Integer> a = new Table<>("A", 1, 2, 3);
Table<Integer> b = a.expand("B", i -> i * 2);
| A | B |
|---|---|
| 1 | 2 |
| 2 | 4 |
| 3 | 6 |
public <U> ObjectTable<U> expandAll(java.lang.String columnName, java.util.function.Function<? super T,? extends java.util.Collection<? extends U>> function)
TableExample:
Table<Integer> a = new Table<>("A", 1, 2);
Table<Integer> b = a.expandAll("B", i -> Arrays.asList(i + 10, i + 20));
| A | B |
|---|---|
| 1 | 11 |
| 1 | 21 |
| 2 | 12 |
| 2 | 22 |
public ObjectTable<T> selectColumns(java.lang.String... columnNames)
TableIllegalArgumentException is
thrown and no changes are made. Note the original order of columns is unaffected by the order of the given names.
After this operation, table instances with the same underlying data that pointed to a columns not part of the given ones will throw an exception when operated on in any way that accesses their corresponding column.
Example:
Table<String> names = new StringTable("Alice", "Bob", "Charlie", "alice");
Table<String> uppercase = names.expand("uppercase", String::toUpperCase);
Table<String> lowercase = names.expand("lowercase", String::toLowerCase);
| A | uppercase | lowercase |
|---|---|---|
| Alice | ALICE | alice |
| Bob | BOB | bob |
| Charlie | CHARLIE | charlie |
| alice | ALICE | alice |
names.selectColumns("uppercase", "lowercase");
| uppercase | lowercase |
|---|---|
| ALICE | alice |
| BOB | bob |
| CHARLIE | charlie |
names.toList(); // throws IllegalStateException
selectColumns in class Table<T>columnNames - the names of columns to retainpublic ObjectTable<T> dropColumns(java.lang.String... columnNames)
TableAfter this operation, table instances with the same underlying data that pointed to one of these columns will throw an exception when operated on in any way that accesses their corresponding column.
Example:
Table<String> names = new StringTable("Alice", "Bob", "Charlie", "alice");
Table<String> uppercase = names.expand("uppercase", String::toUpperCase);
Table<String> lowercase = names.expand("lowercase", String::toLowerCase);
| A | uppercase | lowercase |
|---|---|---|
| Alice | ALICE | alice |
| Bob | BOB | bob |
| Charlie | CHARLIE | charlie |
| alice | ALICE | alice |
names.dropColumns(names.getColumnName());
| uppercase | lowercase |
|---|---|
| ALICE | alice |
| BOB | bob |
| CHARLIE | charlie |
names.toList(); // throws IllegalStateException
dropColumns in class Table<T>columnNames - the names of columns to droppublic ObjectTable<T> filter(java.util.function.Predicate<? super T> predicate)
Tablefalse when passed the cell value of the
column this table points to.
Example:
final Table<Integer> numbers = new Table<>("A", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
numbers.filter(i -> i % 2 == 0);
| A |
|---|
| 2 |
| 4 |
| 6 |
| 8 |
| 10 |
public java.util.LinkedHashSet<T> toSet()
@Deprecated public ObjectTable<T> setColumnName(java.lang.String columnName)
columnName - the name of the column this table should point to@Deprecated public ObjectTable<T> setTable(java.util.ArrayList<java.util.ArrayList<java.lang.Object>> table)
table - the list of rows@Deprecated public ObjectTable<T> setColumnMap(java.util.LinkedHashMap<java.lang.String,java.lang.Integer> columnMap)
columnMap - the map from column name to index in the lists that make up rows@Deprecated
public void addColumn(java.lang.String columnName,
java.util.function.Function<java.util.LinkedHashMap<java.lang.String,java.lang.Object>,java.lang.Object> function)
Table.derive(String, Function) insteadTable.derive(String, Function), except it has stricter requirements on the parameter type of the
predicate and does not return a table pointing to the new column.columnName - the name of the new columnfunction - the function that computes a value for the new columnTable.derive(String, Function)@Deprecated public ObjectTable<T> filterRow(java.util.function.Predicate<java.util.LinkedHashMap<java.lang.String,java.lang.Object>> predicate)
Table.filterRows(Predicate) insteadTable.filterRows(Predicate), except it has stricter requirements on the parameter type of the
predicate.predicate - the predicate that determines which rows should be keptTable.filterRows(Predicate)