Skip to content

Commit

Permalink
add getter
Browse files Browse the repository at this point in the history
  • Loading branch information
duncpro committed Aug 15, 2022
1 parent 53d9315 commit 7073904
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
11 changes: 5 additions & 6 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = "com.duncpro"
version = "1.0-SNAPSHOT-10"
version = "1.0-SNAPSHOT-11"

repositories {
mavenCentral()
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/duncpro/jroute/router/Router.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ default void add(String routeString, E endpoint) throws RouteConflictException {
*/
Set<PositionedEndpoint<E>> getAllEndpoints(Route prefix);

/**
* Returns the endpoint which exists at the given {@link Route} (if any).
*/
Optional<E> getEndpoint(Route at);

/**
* @throws RouteConflictException if the given endpoint conflicts with a pre-existing endpoint within the router.
*/
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/duncpro/jroute/router/TreeRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public Set<PositionedEndpoint<E>> getAllEndpoints(Route prefix) {
.orElse(Collections.emptySet());
}

@Override
public Optional<E> getEndpoint(Route at) {
return findNode(at).flatMap(RouteTreeNode::getEndpoint);
}

private Optional<RouteTreeNode<E>> findNode(Route route) {
RouteTreeNode<E> prefixNode = rootRoute;

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/duncpro/jroute/util/DelegatingRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ public E getOrAdd(Route route, Supplier<E> endpointFactory) {
public Set<PositionedEndpoint<E>> getAllEndpoints(Route prefix) {
return underlyingRouter.getAllEndpoints(prefix);
}

@Override
public Optional<E> getEndpoint(Route at) {
return underlyingRouter.getEndpoint(at);
}
}

0 comments on commit 7073904

Please sign in to comment.