Skip to content

Commit

Permalink
Fixes gone reference handling
Browse files Browse the repository at this point in the history
  • Loading branch information
reinhapa committed May 14, 2024
1 parent 2c5b318 commit a8a6829
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.WeakHashMap;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
Expand Down Expand Up @@ -178,7 +179,7 @@ private static TriggerStates initStates(final Txn txn) {
return new TriggerStates();
}

public record TransactionCleanUp(Txn txn, Consumer<Txn> consumer) implements TxnListener {
public record TransactionCleanUp(Txn txn, Consumer<Txn> consumer) implements TxnListener {
@Override
public void commit() {
consumer.accept(txn);
Expand All @@ -195,33 +196,37 @@ public TriggerStates() {
super(new ArrayDeque<>());
}

Optional<Deque<TriggerState>> states() {
return Optional.ofNullable(get());
}

public Iterator<TriggerState> descendingIterator() {
return get().descendingIterator();
return states().map(Deque::descendingIterator).orElseGet(Collections::emptyIterator);
}

public boolean isEmpty() {
return get().isEmpty();
return states().map(Deque::isEmpty).orElse(true);
}

public int size() {
return get().size();
return states().map(Deque::size).orElse(0);
}

public Iterator<TriggerState> iterator() {
return get().iterator();
return states().map(Deque::iterator).orElseGet(Collections::emptyIterator);
}

public TriggerState peekFirst() {
return get().peekFirst();
return states().map(Deque::peekFirst).orElse(null);
}

public void addFirst(TriggerState newState) {
get().addFirst(newState);
states().ifPresent(states -> states.addFirst(newState));
}
}

public record TriggerState(Trigger trigger, TriggerPhase triggerPhase, TriggerEvent triggerEvent, XmldbURI src,
@Nullable XmldbURI dst, boolean possiblyCyclic) {
@Nullable XmldbURI dst, boolean possiblyCyclic) {

@Override
public String toString() {
Expand Down

0 comments on commit a8a6829

Please sign in to comment.