Skip to content

Commit

Permalink
refactor: make AppendableValueRW serializable
Browse files Browse the repository at this point in the history
work on #11
  • Loading branch information
bsorrentino committed Aug 7, 2024
1 parent 1564efc commit a49decf
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package org.bsc.langgraph4j.state;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.*;

import static java.util.Collections.unmodifiableList;
Expand All @@ -10,8 +14,8 @@
*
* @param <T> the type of the value
*/
public class AppendableValueRW<T> implements AppendableValue<T> {
private final List<T> values;
public class AppendableValueRW<T> implements AppendableValue<T>, Externalizable {
private List<T> values;

/**
* Constructs an AppendableValueRW with the given initial collection of values.
Expand Down Expand Up @@ -100,4 +104,14 @@ public Optional<T> lastMinus(int n) {
public String toString() {
return String.valueOf(values);
}

@Override
public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject(values);
}

@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
values = (List<T>) in.readObject();
}
}

0 comments on commit a49decf

Please sign in to comment.