Skip to content

Commit

Permalink
refactor: adds Node constructors
Browse files Browse the repository at this point in the history
work on #39
  • Loading branch information
bsorrentino committed Nov 25, 2024
1 parent 14fc442 commit 63dd250
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
17 changes: 17 additions & 0 deletions core-jdk8/src/main/java/org/bsc/langgraph4j/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ class Node<State extends AgentState> {

AsyncNodeActionWithConfig<State> actionWithConfig;

public Node( String id ) {
this.id = id;
this.action = null;
this.actionWithConfig = null;

}
public Node( String id, AsyncNodeAction<State> action ) {
this.id = id;
this.action = action;
this.actionWithConfig = null;
}
public Node( String id, AsyncNodeActionWithConfig<State> actionWithConfig ) {
this.id = id;
this.action = null;
this.actionWithConfig = actionWithConfig;

}
/**
* Checks if this node is equal to another object.
*
Expand Down
6 changes: 3 additions & 3 deletions core-jdk8/src/main/java/org/bsc/langgraph4j/StateGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public StateGraph<State> addNode(String id, AsyncNodeAction<State> action) throw
if (Objects.equals(id, END)) {
throw Errors.invalidNodeIdentifier.exception(END);
}
Node<State> node = new Node<State>(id, action, null);
Node<State> node = new Node<State>(id, action);

if (nodes.contains(node)) {
throw Errors.duplicateNodeError.exception(id);
Expand All @@ -217,7 +217,7 @@ public StateGraph<State> addNode(String id, AsyncNodeActionWithConfig<State> act
if (Objects.equals(id, END)) {
throw Errors.invalidNodeIdentifier.exception(END);
}
Node<State> node = new Node<State>(id, null, actionWithConfig);
Node<State> node = new Node<State>(id, actionWithConfig);

if (nodes.contains(node)) {
throw Errors.duplicateNodeError.exception(id);
Expand Down Expand Up @@ -292,7 +292,7 @@ public StateGraph<State> addConditionalEdges(String sourceId, AsyncEdgeAction<St
* @return a new fake node
*/
private Node<State> nodeById(String id) {
return new Node<>(id, null, null);
return new Node<>(id);
}

/**
Expand Down

0 comments on commit 63dd250

Please sign in to comment.