"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "flow-data/src/main/java/com/vaadin/flow/data/provider/hierarchy/HierarchyMapper.java" between
vaadin-flow-4.0.5.tar.gz and vaadin-flow-4.0.6.tar.gz

About: Vaadin flow is a Java framework binding Vaadin web components to Java.

HierarchyMapper.java  (vaadin-flow-4.0.5):HierarchyMapper.java  (vaadin-flow-4.0.6)
skipping to change at line 66 skipping to change at line 66
// childMap is only used for finding parents of items and clean up on // childMap is only used for finding parents of items and clean up on
// removing children of expanded nodes. // removing children of expanded nodes.
private Map<T, Set<T>> childMap = new HashMap<>(); private Map<T, Set<T>> childMap = new HashMap<>();
private Map<Object, T> parentIdMap = new HashMap<>(); private Map<Object, T> parentIdMap = new HashMap<>();
private final HierarchicalDataProvider<T, F> provider; private final HierarchicalDataProvider<T, F> provider;
private F filter; private F filter;
private List<QuerySortOrder> backEndSorting; private List<QuerySortOrder> backEndSorting;
private Comparator<T> inMemorySorting; private Comparator<T> inMemorySorting;
private Set<Object> expandedItemIds = new HashSet<>(); private Map<Object, T> expandedItems = new HashMap<>();
/** /**
* Constructs a new HierarchyMapper. * Constructs a new HierarchyMapper.
* *
* @param provider * @param provider
* the hierarchical data provider for this mapper * the hierarchical data provider for this mapper
*/ */
public HierarchyMapper(HierarchicalDataProvider<T, F> provider) { public HierarchyMapper(HierarchicalDataProvider<T, F> provider) {
this.provider = provider; this.provider = provider;
} }
skipping to change at line 135 skipping to change at line 135
* *
* @param item * @param item
* the item to test * the item to test
* @return {@code true} if item is expanded; {@code false} if not * @return {@code true} if item is expanded; {@code false} if not
*/ */
public boolean isExpanded(T item) { public boolean isExpanded(T item) {
if (item == null) { if (item == null) {
// Root nodes are always visible. // Root nodes are always visible.
return true; return true;
} }
return expandedItemIds.contains(getDataProvider().getId(item)); return expandedItems.containsKey(getDataProvider().getId(item));
} }
/** /**
* Expands the given item. * Expands the given item.
* *
* @param item * @param item
* the item to expand * the item to expand
* @return {@code true} if this method expanded the item, {@code false} * @return {@code true} if this method expanded the item, {@code false}
* otherwise * otherwise
*/ */
skipping to change at line 180 skipping to change at line 180
* whether this method expanded the item. * whether this method expanded the item.
* *
* @param item * @param item
* the item to expand * the item to expand
* @return {@code true} if this method expanded the item, {@code false} * @return {@code true} if this method expanded the item, {@code false}
* otherwise * otherwise
*/ */
private boolean doExpand(T item) { private boolean doExpand(T item) {
boolean expanded = false; boolean expanded = false;
if (!isExpanded(item) && hasChildren(item)) { if (!isExpanded(item) && hasChildren(item)) {
expandedItemIds.add(getDataProvider().getId(item)); expandedItems.put(getDataProvider().getId(item), item);
expanded = true; expanded = true;
} }
return expanded; return expanded;
} }
/** /**
* Collapses the given item. * Collapses the given item.
* *
* @param item * @param item
* the item to collapse * the item to collapse
* @return {@code true} if item has been collapsed, * @return {@code true} if item has been collapsed,
* {@code false} if item is empty or already collapsed * {@code false} if item is empty or already collapsed
*/ */
public boolean collapse(T item) { public boolean collapse(T item) {
if (item == null) { if (item == null) {
return false; return false;
} }
if (isExpanded(item)) { if (isExpanded(item)) {
expandedItemIds.remove(getDataProvider().getId(item)); expandedItems.remove(getDataProvider().getId(item));
return true; return true;
} }
return false; return false;
} }
/** /**
* Collapses the given item. * Collapses the given item.
* *
* @param item * @param item
* the item to collapse * the item to collapse
skipping to change at line 222 skipping to change at line 222
* *
* @return range of rows removed by collapsing the item * @return range of rows removed by collapsing the item
*/ */
public Range collapse(T item, Integer position) { public Range collapse(T item, Integer position) {
Range removedRows = Range.withLength(0, 0); Range removedRows = Range.withLength(0, 0);
if (isExpanded(item)) { if (isExpanded(item)) {
if (position != null) { if (position != null) {
removedRows = Range.withLength(position + 1, removedRows = Range.withLength(position + 1,
(int) getHierarchy(item, false).count()); (int) getHierarchy(item, false).count());
} }
expandedItemIds.remove(getDataProvider().getId(item)); expandedItems.remove(getDataProvider().getId(item));
} }
return removedRows; return removedRows;
} }
/** /**
* Gets the current in-memory sorting. * Gets the current in-memory sorting.
* *
* @return the in-memory sorting * @return the in-memory sorting
*/ */
public Comparator<T> getInMemorySorting() { public Comparator<T> getInMemorySorting() {
skipping to change at line 443 skipping to change at line 443
Iterator<Entry<T, Set<T>>> iterator = childMap.entrySet().iterator(); Iterator<Entry<T, Set<T>>> iterator = childMap.entrySet().iterator();
Set<T> invalidatedChildren = new HashSet<>(); Set<T> invalidatedChildren = new HashSet<>();
while (iterator.hasNext()) { while (iterator.hasNext()) {
Entry<T, Set<T>> entry = iterator.next(); Entry<T, Set<T>> entry = iterator.next();
T key = entry.getKey(); T key = entry.getKey();
if (key != null && getDataProvider().getId(key).equals(id)) { if (key != null && getDataProvider().getId(key).equals(id)) {
invalidatedChildren.addAll(entry.getValue()); invalidatedChildren.addAll(entry.getValue());
iterator.remove(); iterator.remove();
} }
} }
expandedItemIds.remove(id); expandedItems.remove(id);
invalidatedChildren.stream().map(getDataProvider()::getId) invalidatedChildren.stream().map(getDataProvider()::getId)
.forEach(x -> { .forEach(x -> {
removeChildren(x); removeChildren(x);
parentIdMap.remove(x); parentIdMap.remove(x);
}); });
} }
/** /**
* Finds the current index of given object. This is based on a search in * Finds the current index of given object. This is based on a search in
* flattened version of the hierarchy. * flattened version of the hierarchy.
skipping to change at line 619 skipping to change at line 619
boolean includeParent) { boolean includeParent) {
boolean parentIncluded = includeParent && parent != null; boolean parentIncluded = includeParent && parent != null;
Stream<T> parentStream = parentIncluded ? Stream.of(parent) Stream<T> parentStream = parentIncluded ? Stream.of(parent)
: Stream.empty(); : Stream.empty();
return Stream.concat(parentStream, children); return Stream.concat(parentStream, children);
} }
public void destroyAllData() { public void destroyAllData() {
childMap.clear(); childMap.clear();
parentIdMap.clear(); parentIdMap.clear();
expandedItemIds.clear(); expandedItems.clear();
} }
/** /**
* Returns true if there is any expanded items. * Returns true if there is any expanded items.
* *
* @return {@code true} if there is any expanded items. * @return {@code true} if there is any expanded items.
*/ */
public boolean hasExpandedItems() { public boolean hasExpandedItems() {
return !expandedItemIds.isEmpty(); return !expandedItems.isEmpty();
} }
} }
 End of changes. 8 change blocks. 
8 lines changed or deleted 8 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)