@@ -26,6 +26,14 @@ public class AppenderChannel<T> implements Channel<List<T>> {
26
26
*/
27
27
@ FunctionalInterface
28
28
public interface RemoveIdentifier <T > {
29
+ /**
30
+ * Compares the specified element with the element at the given index.
31
+ *
32
+ * @param <T> the type of elements to compare
33
+ * @param element the element to be compared
34
+ * @param atIndex the index of the element to compare with
35
+ * @return a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
36
+ */
29
37
int compareTo (T element , int atIndex );
30
38
}
31
39
@@ -91,12 +99,30 @@ public List<T> apply(List<T> left, List<T> right) {
91
99
this .defaultProvider = defaultProvider ;
92
100
}
93
101
102
+ /**
103
+ * This method removes elements from a given list based on the specified {@link RemoveIdentifier}.
104
+ * It creates a copy of the original list, performs the removal operation, and returns an immutable view of the result.
105
+ *
106
+ * @param <T> The type of elements in the list.
107
+ * @param list The list from which elements will be removed.
108
+ * @param removeIdentifier An instance of {@link RemoveIdentifier} that defines how to identify elements for removal.
109
+ * @return An unmodifiable view of the modified list with specified elements removed.
110
+ */
94
111
private List <T > remove (List <T > list , RemoveIdentifier <T > removeIdentifier ) {
95
112
var result = new ArrayList <>(list );
96
113
removeFromList (result , removeIdentifier );
97
114
return unmodifiableList (result );
98
115
}
99
116
117
+ /**
118
+ * Removes an element from the list that matches the specified identifier.
119
+ *
120
+ * <p>This method iterates over the provided list and removes the first element for which the
121
+ * {@link RemoveIdentifier#compareTo} method returns zero.</p>
122
+ *
123
+ * @param result the list to be modified
124
+ * @param removeIdentifier the identifier used to find the element to remove
125
+ */
100
126
private void removeFromList (List <T > result , RemoveIdentifier <T > removeIdentifier ) {
101
127
for ( int i = 0 ; i < result .size (); i ++ ) {
102
128
if ( removeIdentifier .compareTo ( result .get (i ), i ) == 0 ) {
@@ -106,6 +132,11 @@ private void removeFromList(List<T> result, RemoveIdentifier<T> removeIdentifier
106
132
}
107
133
}
108
134
135
+ /**
136
+ * Represents a record for data removal operations with generic types.
137
+ *
138
+ * @param <T> the type of elements in the old values list
139
+ */
109
140
record RemoveData <T >( List <T > oldValues , List <?> newValues ) {
110
141
111
142
// copy constructor. make sure to copy the list to make them modifiable
@@ -115,6 +146,13 @@ record RemoveData<T>( List<T> oldValues, List<?> newValues) {
115
146
}
116
147
};
117
148
149
+ /**
150
+ * Evaluates the removal of identifiers from the new values list and updates the RemoveData object accordingly.
151
+ *
152
+ * @param oldValues a {@code List} of old values
153
+ * @param newValues a {@code List} of new values containing {@code RemoveIdentifier}s to be evaluated for removal
154
+ * @return a {@literal RemoveData<T>} object with updated old and new values after removing identifiers
155
+ */
118
156
@ SuppressWarnings ("unchecked" )
119
157
private RemoveData <T > evaluateRemoval (List <T > oldValues , List <?> newValues ) {
120
158
0 commit comments