use of com.vaadin.flow.internal.change.EmptyChange in project flow by vaadin.
the class ElementData method collectChanges.
@Override
public void collectChanges(Consumer<NodeChange> collector) {
List<NodeChange> changes = new ArrayList<>(1);
super.collectChanges(changes::add);
Serializable[] previousValue;
Serializable tracker = getNode().getChangeTracker(this, () -> null);
if (tracker instanceof Serializable[]) {
previousValue = (Serializable[]) tracker;
} else {
previousValue = new Serializable[2];
}
NodeChange change = changes.get(0);
if (change instanceof MapPutChange) {
if (!Objects.equals(previousValue[0], getTag())) {
collector.accept(new MapPutChange(this, getKey(), getTag()));
}
if (!Objects.equals(previousValue[1], getPayload())) {
collector.accept(new MapPutChange(this, NodeProperties.PAYLOAD, getPayload()));
}
} else if (change instanceof EmptyChange) {
collector.accept(change);
}
}
use of com.vaadin.flow.internal.change.EmptyChange in project flow by vaadin.
the class NodeValue method collectChanges.
@Override
public void collectChanges(Consumer<NodeChange> collector) {
Serializable originalValue = getNode().getChangeTracker(this, () -> null);
assert originalValue != null;
if (originalValue == NULL_MARKER) {
originalValue = null;
}
if (!Objects.equals(originalValue, this.value)) {
collector.accept(new MapPutChange(this, getKey(), value));
} else if (!isPopulated) {
collector.accept(new EmptyChange(this));
}
isPopulated = true;
}
use of com.vaadin.flow.internal.change.EmptyChange in project flow by vaadin.
the class NodeList method collectChanges.
@Override
public void collectChanges(Consumer<NodeChange> collector) {
// This map contains items wrapped by AbstractListChanges as keys and
// index in the following allChanges list as a value (it allows to get
// AbstractListChange by the index)
Map<Object, Integer> indices = new IdentityHashMap<>();
// This list contains all changes in the tracker. These changes will be
// modified: each "remove" change following by a corresponding "add"
// will be replaced by null and "add" will be adjusted. Indeces in
// changes in between will be adjusted
List<AbstractListChange<T>> allChanges = new ArrayList<>();
int index = 0;
for (AbstractListChange<T> change : getChangeTracker()) {
if (change instanceof ListRemoveChange<?>) {
// the remove change => find an appropriate "add" event, adjust
// it and adjust everything in between
adjustChanges(index, (ListRemoveChange<T>) change, indices, allChanges);
} else if (change instanceof ListAddChange<?>) {
allChanges.add(change);
int i = index;
// put all items into "indeces" as keys and "index" as a value
// so that the "change" can be retrieved from the "allChanges"
// by the index
((ListAddChange<T>) change).getNewItems().forEach(item -> indices.put(item, i));
} else if (change instanceof ListClearChange<?>) {
allChanges.add(change);
} else {
assert false : "AbstractListChange has only three subtypes: add, remove and clear";
}
index++;
}
List<AbstractListChange<T>> changes = allChanges.stream().filter(this::acceptChange).collect(Collectors.toList());
if (isPopulated) {
changes.forEach(collector);
} else {
if (changes.isEmpty()) {
collector.accept(new EmptyChange(this));
} else {
changes.forEach(collector);
}
isPopulated = true;
}
}
use of com.vaadin.flow.internal.change.EmptyChange in project flow by vaadin.
the class NodeMap method collectChanges.
@Override
public void collectChanges(Consumer<NodeChange> collector) {
boolean hasChanges = false;
for (Entry<String, Serializable> entry : getChangeTracker().entrySet()) {
String key = entry.getKey();
Serializable value = entry.getValue();
boolean containsNow = values != null && values.containsKey(key);
boolean containedEarlier = value != REMOVED_MARKER;
if (containedEarlier && !containsNow) {
collector.accept(new MapRemoveChange(this, key));
hasChanges = true;
} else if (containsNow) {
Object currentValue = values.get(key);
if (!containedEarlier || !Objects.equals(value, currentValue)) {
// New or changed value
collector.accept(new MapPutChange(this, key, currentValue));
hasChanges = true;
}
}
}
if (!isPopulated) {
if (!hasChanges) {
collector.accept(new EmptyChange(this));
}
isPopulated = true;
}
}
Aggregations