Skip to content

Separated Endpoint related objects from bigger PR#25

Open
Laukkala wants to merge 2 commits into
teragrep:mainfrom
Laukkala:19_endpoints
Open

Separated Endpoint related objects from bigger PR#25
Laukkala wants to merge 2 commits into
teragrep:mainfrom
Laukkala:19_endpoints

Conversation

@Laukkala
Copy link
Copy Markdown

This PR is separated from #4 to make code review more manageable.
Note that this PR by itself will likely contain references to objects that are not present in this PR. Please refer to PR #4, which contains all objects, in case you need to see how some objects interact.

This PR contains endpoint objects, which define what procedures nbs_01 executes when a request for some operation is received.
closes #19

@Laukkala Laukkala self-assigned this Jan 15, 2026
@Laukkala Laukkala requested a review from MoonBow-1 January 16, 2026 05:19
Copy link
Copy Markdown

@MoonBow-1 MoonBow-1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides the comments, endpoint tests seem to be extending AbstractNotebookServerTest, abstracting a lot of behavior behind the inheritance.

Also the tests seem to be integration tests, where the AbstractNotebookServerTest makes actual HTTP requests to the endpoints, instead of creating HTTPRequest parameters to the methods that are tested.

import java.util.Objects;

// Finds a given Directory and returns its own name and the names of its children in JSON format based on a given Identifier.
public final class FindDirectoryEndPoint implements HTTPEndPoint {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in the class/file name, should be FindDirectoryEndpoint

// Interface for a Delegate, that inspects a Request object, and returns either a true or a false value according to implementation details.
public abstract interface Delegate {

public abstract boolean resolve(HTTPRequest request);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parameter can be final

import com.teragrep.nbs_01.protocols.http.HTTPResponse;

// Endpoint that delegates the request to one of a collection of Endpoints based on the result of a Delegate
public class DelegatingEndpoint implements HTTPEndPoint {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class should be final

Comment on lines +62 to +68
public DoAllKeysExistDelegate(final String key) {
this.keys = Arrays.asList(key);
}

public DoAllKeysExistDelegate(final List<String> keys) {
this.keys = keys;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be the primary constructor:

public DoAllKeysExistDelegate(final List<String> keys) {
    this.keys = keys;
}

Secondary constructor be changed from:

public DoAllKeysExistDelegate(final String key) {
    this.keys = Arrays.asList(key);
}

to:

public DoAllKeysExistDelegate(final String key) {
    this(
        Collections.singletonList(key)
    );
}

This also changes the static method used to create the List from Arrays.asList to Collections.singletonList. The singletonList method returns an immutable List instead of an modifiable List that the asList method returns.

try {
title = request.title();
}
catch (MalformedRequestException e) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exception can be final

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Endpoints

2 participants