Skip to content

Commit 666c253

Browse files
committed
docs: update javadoc
1 parent 0d9ddfa commit 666c253

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

core/src/main/java/org/bsc/langgraph4j/state/AppenderChannel.java

+38
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ public class AppenderChannel<T> implements Channel<List<T>> {
2626
*/
2727
@FunctionalInterface
2828
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+
*/
2937
int compareTo(T element, int atIndex );
3038
}
3139

@@ -91,12 +99,30 @@ public List<T> apply(List<T> left, List<T> right) {
9199
this.defaultProvider = defaultProvider;
92100
}
93101

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+
*/
94111
private List<T> remove(List<T> list, RemoveIdentifier<T> removeIdentifier ) {
95112
var result = new ArrayList<>(list);
96113
removeFromList(result, removeIdentifier);
97114
return unmodifiableList(result);
98115
}
99116

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+
*/
100126
private void removeFromList(List<T> result, RemoveIdentifier<T> removeIdentifier ) {
101127
for( int i = 0; i < result.size(); i++ ) {
102128
if( removeIdentifier.compareTo( result.get(i), i ) == 0 ) {
@@ -106,6 +132,11 @@ private void removeFromList(List<T> result, RemoveIdentifier<T> removeIdentifier
106132
}
107133
}
108134

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+
*/
109140
record RemoveData<T>( List<T> oldValues, List<?> newValues) {
110141

111142
// copy constructor. make sure to copy the list to make them modifiable
@@ -115,6 +146,13 @@ record RemoveData<T>( List<T> oldValues, List<?> newValues) {
115146
}
116147
};
117148

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+
*/
118156
@SuppressWarnings("unchecked")
119157
private RemoveData<T> evaluateRemoval(List<T> oldValues, List<?> newValues ) {
120158

core/src/main/java/org/bsc/langgraph4j/state/RemoveByHash.java

+21-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,33 @@
22

33
import java.util.Objects;
44

5+
/**
6+
* Represents a record that implements the {@link AppenderChannel.RemoveIdentifier<T>} interface.
7+
*
8+
* @param <T> the type of the value to be associated with this RemoveByHash instance
9+
*/
510
public record RemoveByHash<T>(T value ) implements AppenderChannel.RemoveIdentifier<T> {
11+
/**
12+
* Compares the hash code of this object with another element at a specific index.
13+
*
14+
* @param <T> the type parameter of the element to compare with
15+
* @param element the element to compare with
16+
* @param atIndex the index of the element in the context (ignored in comparison)
17+
* @return the difference between the hash codes of this object and the given element
18+
*/
619
@Override
720
public int compareTo(T element, int atIndex) {
821
return Objects.hashCode(value) - Objects.hashCode(element);
922
}
1023

24+
/**
25+
* Creates a new {@code RemoveByHash} instance with the specified value.
26+
*
27+
* @param <T> the type of the value
28+
* @param value the value to store in the {@code RemoveByHash}
29+
* @return a new {@code RemoveByHash} instance
30+
*/
1131
public static <T> RemoveByHash<T> of ( T value ) {
1232
return new RemoveByHash<>(value);
1333
}
14-
}
34+
}

0 commit comments

Comments
 (0)