Skip to content

Commit

Permalink
Replace Function<X, X> for UnaryOperator<X>
Browse files Browse the repository at this point in the history
Replace usages of Function<X, X> for UnaryOperator<X> for clarity.

#2021
  • Loading branch information
smcvb committed Aug 9, 2022
1 parent 3b30650 commit 3e061c7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
import java.time.Instant;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.UnaryOperator;

/**
* Interface describing a dead-lettered {@link Message} implementation of generic type {@code M}.
* <p>
* The time of storing the {@link #message()} is kept through {@link #enqueuedAt()}. The last time this letter was
* accessed on either {@link SequencedDeadLetterQueue#requeue(DeadLetter, Function)} or
* accessed on either {@link SequencedDeadLetterQueue#requeue(DeadLetter, UnaryOperator)} or
* {@link SequencedDeadLetterQueue#process(Function) processing}, is kept in {@link #lastTouched()}. Additional
* information on why the letter is enqueued can be found in the {@link #diagnostics() diagnostics}.
*
Expand Down Expand Up @@ -106,12 +107,12 @@ public interface DeadLetter<M extends Message<?>> {
* the given {@code diagnosticsBuilder}. The {@code diagnosticsBuilder} will be invoked with the diagnostics of this
* instance.
*
* @param diagnosticsBuilder The {@link Function lambda} constructing diagnostic {@link MetaData} to replace the
* {@code MetaData} of the {@link DeadLetter} under construction.
* @param diagnosticsBuilder The {@link UnaryOperator lambda} constructing diagnostic {@link MetaData} to replace
* the {@code MetaData} of the {@link DeadLetter} under construction.
* @return A copy of this {@link DeadLetter}, replacing the {@link DeadLetter#diagnostics()} with the result of the
* given {@code diagnosticsBuilder}.
*/
default DeadLetter<M> withDiagnostics(Function<MetaData, MetaData> diagnosticsBuilder) {
default DeadLetter<M> withDiagnostics(UnaryOperator<MetaData> diagnosticsBuilder) {
return withDiagnostics(diagnosticsBuilder.apply(this.diagnostics()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;

Expand Down Expand Up @@ -152,7 +153,7 @@ public void evict(DeadLetter<? extends M> letter) {
@Override
public void requeue(
@Nonnull DeadLetter<? extends M> letter,
@Nonnull Function<DeadLetter<? extends M>, DeadLetter<? extends M>> letterUpdater
@Nonnull UnaryOperator<DeadLetter<? extends M>> letterUpdater
) throws NoSuchDeadLetterException {
Optional<Map.Entry<String, Deque<DeadLetter<? extends M>>>> optionalSequence =
deadLetters.entrySet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.function.UnaryOperator;
import javax.annotation.Nonnull;

/**
Expand Down Expand Up @@ -94,15 +95,13 @@ default boolean enqueueIfPresent(
* {@link DeadLetter#diagnostics()}, depending on the given {@code letterUpdater}.
*
* @param letter The {@link DeadLetter dead-letter} to reenter in this queue.
* @param letterUpdater A {@link Function lambda} taking in the given {@code letter} and updating the entry for
* @param letterUpdater A {@link UnaryOperator lambda} taking in the given {@code letter} and updating the entry for
* requeueing. This may adjust the {@link DeadLetter#cause()} and
* {@link DeadLetter#diagnostics()}, for example.
* @throws NoSuchDeadLetterException Thrown if the given {@code letter} does not exist in the queue.
*/
void requeue(
@Nonnull DeadLetter<? extends M> letter,
@Nonnull Function<DeadLetter<? extends M>, DeadLetter<? extends M>> letterUpdater
) throws NoSuchDeadLetterException;
void requeue(@Nonnull DeadLetter<? extends M> letter,
@Nonnull UnaryOperator<DeadLetter<? extends M>> letterUpdater) throws NoSuchDeadLetterException;

/**
* Check whether there's a sequence of {@link DeadLetter dead-letters} for the given {@code sequenceIdentifier}.
Expand Down Expand Up @@ -174,10 +173,10 @@ void requeue(
* the sequence.
* <p>
* Uses the {@link EnqueueDecision} returned by the {@code processingTask} to decide whether to
* {@link #evict(DeadLetter)} or {@link #requeue(DeadLetter, Function)} a dead-letter from the selected sequence.
* The {@code processingTask} is invoked as long as letters are present in the selected sequence and the result of
* processing returns {@code false} for {@link EnqueueDecision#shouldEnqueue()} decision. The latter means the
* dead-letter should be evicted.
* {@link #evict(DeadLetter)} or {@link #requeue(DeadLetter, UnaryOperator)} a dead-letter from the selected
* sequence. The {@code processingTask} is invoked as long as letters are present in the selected sequence and the
* result of processing returns {@code false} for {@link EnqueueDecision#shouldEnqueue()} decision. The latter means
* the dead-letter should be evicted.
* <p>
* This operation protects against concurrent invocations of the {@code processingTask} on the filtered sequence.
* Doing so ensure enqueued messages are handled in order.
Expand All @@ -186,7 +185,7 @@ void requeue(
* {@code processingTask}.
* @param processingTask A function processing a {@link DeadLetter dead-letter} implementation. Returns a
* {@link EnqueueDecision} used to deduce whether to {@link #evict(DeadLetter)} or
* {@link #requeue(DeadLetter, Function)} the dead-letter.
* {@link #requeue(DeadLetter, UnaryOperator)} the dead-letter.
* @return {@code true} if an entire sequence of {@link DeadLetter dead-letters} was processed successfully,
* {@code false} otherwise. This means the {@code processingTask} processed all {@link DeadLetter dead-letters} of a
* sequence and the outcome was to evict each instance.
Expand All @@ -200,17 +199,17 @@ boolean process(@Nonnull Predicate<DeadLetter<? extends M>> sequenceFilter,
* entry.
* <p>
* Uses the {@link EnqueueDecision} returned by the {@code processingTask} to decide whether to
* {@link #evict(DeadLetter)} or {@link #requeue(DeadLetter, Function)} the dead-letter. The {@code processingTask}
* is invoked as long as letters are present in the selected sequence and the result of processing returns
* {@code false} for {@link EnqueueDecision#shouldEnqueue()} decision. The latter means the dead-letter should be
* evicted.
* {@link #evict(DeadLetter)} or {@link #requeue(DeadLetter, UnaryOperator)} the dead-letter. The
* {@code processingTask} is invoked as long as letters are present in the selected sequence and the result of
* processing returns {@code false} for {@link EnqueueDecision#shouldEnqueue()} decision. The latter means the
* dead-letter should be evicted.
* <p>
* This operation protects against concurrent invocations of the {@code processingTask} on the filtered sequence. *
* Doing so ensure enqueued messages are handled in order.
*
* @param processingTask A function processing a {@link DeadLetter dead-letter} implementation. Returns a
* {@link EnqueueDecision} used to deduce whether to {@link #evict(DeadLetter)} or
* {@link #requeue(DeadLetter, Function)} the dead-letter.
* {@link #requeue(DeadLetter, UnaryOperator)} the dead-letter.
* @return {@code true} if an entire sequence of {@link DeadLetter dead-letters} was processed successfully,
* {@code false} otherwise. This means the {@code processingTask} processed all {@link DeadLetter dead-letters} of a
* sequence and the outcome was to evict each instance.
Expand Down

0 comments on commit 3e061c7

Please sign in to comment.