Add limit parameter

This commit is contained in:
René Pfeuffer
2020-02-17 16:48:14 +01:00
parent d6fe305438
commit db540f5f02
4 changed files with 59 additions and 0 deletions

View File

@@ -300,6 +300,18 @@ public final class BrowseCommandBuilder
return this;
}
/**
* Limit the number of result files to <code>limit</code> entries.
*
* @param limit The maximal number of files this request shall return.
*
* @since 2.0.0
*/
public BrowseCommandBuilder setLimit(int limit) {
request.setLimit(limit);
return this;
}
private void updateCache(BrowserResult updatedResult) {
if (!disableCache) {
CacheKey key = new CacheKey(repository, request);

View File

@@ -191,6 +191,17 @@ public final class BrowseCommandRequest extends FileBaseCommandRequest
this.recursive = recursive;
}
/**
* Limit the number of result files to <code>limit</code> entries.
*
* @param limit The maximal number of files this request shall return.
*
* @since 2.0.0
*/
public void setLimit(int limit) {
this.limit = limit;
}
//~--- get methods ----------------------------------------------------------
/**
@@ -232,6 +243,15 @@ public final class BrowseCommandRequest extends FileBaseCommandRequest
return recursive;
}
/**
* Returns the limit for the number of result files.
*
* @since 2.0.0
*/
public int getLimit() {
return limit;
}
public void updateCache(BrowserResult update) {
if (updater != null) {
updater.accept(update);
@@ -249,6 +269,10 @@ public final class BrowseCommandRequest extends FileBaseCommandRequest
/** browse file objects recursive */
private boolean recursive = false;
/** Limit the number of result files to <code>limit</code> entries. */
private int limit = 1000;
// WARNING / TODO: This field creates a reverse channel from the implementation to the API. This will break
// whenever the API runs in a different process than the SPI (for example to run explicit hosts for git repositories).
private final transient Consumer<BrowserResult> updater;

View File

@@ -147,6 +147,10 @@ public abstract class FileBaseCommandRequest
this.revision = revision;
}
public void setLimit(int limit) {
this.limit = limit;
}
//~--- get methods ----------------------------------------------------------
/**
@@ -171,6 +175,10 @@ public abstract class FileBaseCommandRequest
return revision;
}
public int getLimit() {
return limit;
}
//~--- methods --------------------------------------------------------------
/**
@@ -208,4 +216,6 @@ public abstract class FileBaseCommandRequest
/** Field description */
private String revision;
private int limit;
}

View File

@@ -236,6 +236,19 @@ public class GitBrowseCommandTest extends AbstractGitCommandTestBase {
.containsExactly(of(42L));
}
@Test
public void testBrowseLimit() throws IOException {
BrowseCommandRequest request = new BrowseCommandRequest();
request.setLimit(2);
FileObject root = createCommand()
.getBrowserResult(request).getFile();
assertNotNull(root);
Collection<FileObject> foList = root.getChildren();
assertThat(foList).hasSize(2);
}
private FileObject findFile(Collection<FileObject> foList, String name) {
return foList.stream()
.filter(f -> name.equals(f.getName()))