minor updates to branch

This commit is contained in:
Jonathan Shook
2020-04-08 02:23:19 -05:00
parent 4abf54a3a7
commit d8b3e6214c
4 changed files with 36 additions and 39 deletions

View File

@@ -272,7 +272,7 @@ public class NBCLIScenarioParser {
List<Content<?>> activities = NBIO.all() List<Content<?>> activities = NBIO.all()
.prefix(SEARCH_IN) .prefix(SEARCH_IN)
.name(".*\\.yaml") .extension("yaml")
.list(); .list();
List<Path> yamlPathList = activities.stream().map(Content::asPath).collect(Collectors.toList()); List<Path> yamlPathList = activities.stream().map(Content::asPath).collect(Collectors.toList());

View File

@@ -45,51 +45,51 @@ public class NBIO implements NBPathsAPI.Facets {
} }
@Override @Override
public NBPathsAPI.ForPrefix localContent() { public NBPathsAPI.GetPrefix localContent() {
this.resolver = URIResolvers.inFS().inCP(); this.resolver = URIResolvers.inFS().inCP();
return this; return this;
} }
@Override @Override
public NBPathsAPI.ForPrefix remoteContent() { public NBPathsAPI.GetPrefix remoteContent() {
this.resolver = URIResolvers.inURLs(); this.resolver = URIResolvers.inURLs();
return this; return this;
} }
@Override @Override
public NBPathsAPI.ForPrefix internalContent() { public NBPathsAPI.GetPrefix internalContent() {
this.resolver = URIResolvers.inClasspath(); this.resolver = URIResolvers.inClasspath();
return this; return this;
} }
@Override @Override
public NBPathsAPI.ForPrefix fileContent() { public NBPathsAPI.GetPrefix fileContent() {
this.resolver = URIResolvers.inFS(); this.resolver = URIResolvers.inFS();
return this; return this;
} }
@Override @Override
public NBPathsAPI.ForPrefix allContent() { public NBPathsAPI.GetPrefix allContent() {
this.resolver = URIResolvers.inFS().inCP().inURLs(); this.resolver = URIResolvers.inFS().inCP().inURLs();
return this; return this;
} }
@Override @Override
public NBPathsAPI.ForPrefix prefix(String... searchPaths) { public NBPathsAPI.GetPrefix prefix(String... searchPaths) {
ArrayList<String> addingPaths = new ArrayList<>(this.prefixes); ArrayList<String> addingPaths = new ArrayList<>(this.prefixes);
addingPaths.addAll(Arrays.asList(searchPaths)); addingPaths.addAll(Arrays.asList(searchPaths));
return new NBIO(resolver, addingPaths, names, extensions); return new NBIO(resolver, addingPaths, names, extensions);
} }
@Override @Override
public NBPathsAPI.ForName name(String... searchNames) { public NBPathsAPI.GetExtension name(String... searchNames) {
ArrayList<String> addingNames = new ArrayList<>(this.names); ArrayList<String> addingNames = new ArrayList<>(this.names);
addingNames.addAll(Arrays.asList(searchNames)); addingNames.addAll(Arrays.asList(searchNames));
return new NBIO(resolver, prefixes, addingNames, extensions); return new NBIO(resolver, prefixes, addingNames, extensions);
} }
@Override @Override
public NBPathsAPI.ForExtension extension(String... extensions) { public NBPathsAPI.DoSearch extension(String... extensions) {
ArrayList<String> addingExtensions = new ArrayList<>(this.extensions); ArrayList<String> addingExtensions = new ArrayList<>(this.extensions);
for (String addingExtension : extensions) { for (String addingExtension : extensions) {
addingExtensions.add(dotExtension(addingExtension)); addingExtensions.add(dotExtension(addingExtension));
@@ -102,7 +102,7 @@ public class NBIO implements NBPathsAPI.Facets {
* *
* @return a builder * @return a builder
*/ */
public static NBPathsAPI.ForPrefix all() { public static NBPathsAPI.GetPrefix all() {
return new NBIO().allContent(); return new NBIO().allContent();
} }
@@ -111,7 +111,7 @@ public class NBIO implements NBPathsAPI.Facets {
* *
* @return a builder * @return a builder
*/ */
public static NBPathsAPI.ForPrefix classpath() { public static NBPathsAPI.GetPrefix classpath() {
return new NBIO().internalContent(); return new NBIO().internalContent();
} }
@@ -120,7 +120,7 @@ public class NBIO implements NBPathsAPI.Facets {
* *
* @return a builder * @return a builder
*/ */
public static NBPathsAPI.ForPrefix fs() { public static NBPathsAPI.GetPrefix fs() {
return new NBIO().fileContent(); return new NBIO().fileContent();
} }
@@ -129,7 +129,7 @@ public class NBIO implements NBPathsAPI.Facets {
* *
* @return a builder * @return a builder
*/ */
public static NBPathsAPI.ForPrefix local() { public static NBPathsAPI.GetPrefix local() {
return new NBIO().localContent(); return new NBIO().localContent();
} }
@@ -138,7 +138,7 @@ public class NBIO implements NBPathsAPI.Facets {
* *
* @return a builder * @return a builder
*/ */
public static NBPathsAPI.ForPrefix remote() { public static NBPathsAPI.GetPrefix remote() {
return new NBIO().remoteContent(); return new NBIO().remoteContent();
} }

View File

@@ -2,81 +2,80 @@ package io.nosqlbench.nb.api.content.fluent;
import io.nosqlbench.nb.api.content.Content; import io.nosqlbench.nb.api.content.Content;
import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
public interface NBPathsAPI { public interface NBPathsAPI {
public static interface Facets extends public static interface Facets extends
WantsSpaces, ForPrefix, WantsContentName, ForName, ForExtension {} GetSource, GetPrefix, GetName, GetExtension, DoSearch {}
public static interface WantsSpaces { public static interface GetSource {
/** /**
* Only provide content from the class path and the local filesystem. * Only provide content from the class path and the local filesystem.
* @return this builder * @return this builder
*/ */
ForPrefix localContent(); GetPrefix localContent();
/** /**
* Only return content from remote URLs. If the user is providing non-URL content * Only return content from remote URLs. If the user is providing non-URL content
* in this context, it is an error. Throw an error in that case. * in this context, it is an error. Throw an error in that case.
* @return this builder * @return this builder
*/ */
ForPrefix remoteContent(); GetPrefix remoteContent();
/** /**
* Only return content from the runtime classpath, internal resources that are bundled, * Only return content from the runtime classpath, internal resources that are bundled,
* and do not return content on the file system. * and do not return content on the file system.
* @return this builder * @return this builder
*/ */
ForPrefix internalContent(); GetPrefix internalContent();
/** /**
* Only return content from the filesystem, but not remote URLs nor internal bundled resources. * Only return content from the filesystem, but not remote URLs nor internal bundled resources.
* @return this builder * @return this builder
*/ */
ForPrefix fileContent(); GetPrefix fileContent();
/** /**
* Return content from everywhere, from remote URls, or from the file system and then the internal * Return content from everywhere, from remote URls, or from the file system and then the internal
* bundled content if not found in the file system first. * bundled content if not found in the file system first.
* @return this builder * @return this builder
*/ */
ForPrefix allContent(); GetPrefix allContent();
} }
public static interface ForPrefix extends WantsContentName { public static interface GetPrefix extends GetName {
/** /**
* Each of the prefix paths will be searched if the resource is not found with the exact * Each of the prefix paths will be searched if the resource is not found with the exact
* path given. * path given.
* @param prefixPaths A list of paths to include in the search * @param prefixPaths A list of paths to include in the search
* @return this builder * @return this builder
*/ */
WantsContentName prefix(String... prefixPaths); GetName prefix(String... prefixPaths);
} }
public static interface WantsContentName { public static interface GetName extends GetExtension {
/** /**
* Provide the names of the resources to be resolved. More than one resource may be provided. * Provide the names of the resources to be resolved. More than one resource may be provided.
* @param name The name of the resource to load * @param name The name of the resource to load
* @return this builder * @return this builder
*/ */
ForName name(String... name); GetExtension name(String... name);
} }
public static interface ForName extends ForExtension { public static interface GetExtension extends DoSearch {
/** /**
* provide a list of optional file extensions which should be considered. If the content is * provide a list of optional file extensions which should be considered. If the content is
* not found under the provided name, then each of the extensios is tried in order. * not found under the provided name, then each of the extensios is tried in order.
* @param extensions The extension names to try * @param extensions The extension names to try
* @return this builder * @return this builder
*/ */
ForExtension extension(String... extensions); DoSearch extension(String... extensions);
} }
public static interface ForExtension { public static interface DoSearch {
/** /**
* Return the result of resolving the resource. * Return the result of resolving the resource.
* @return an optional {@code Content<?>} element. * @return an optional {@code Content<?>} element.
@@ -92,8 +91,6 @@ public interface NBPathsAPI {
List<Content<?>> list(); List<Content<?>> list();
Optional<Content<?>> maybeOne();
/** /**
* Find exactly one source of content under the search parameters given. * Find exactly one source of content under the search parameters given.
* It is an error if you find none, or more than one. * It is an error if you find none, or more than one.

View File

@@ -69,10 +69,10 @@ public class NBIOTest {
@Test @Test
public void testLoadCsv1Classpath() { public void testLoadCsv1Classpath() {
NBPathsAPI.ForPrefix forSourceType = NBIO.classpath(); NBPathsAPI.GetPrefix forSourceType = NBIO.classpath();
NBPathsAPI.WantsContentName nesteddir1 = forSourceType.prefix("nesteddir1"); NBPathsAPI.GetName nesteddir1 = forSourceType.prefix("nesteddir1");
NBPathsAPI.ForName forName = nesteddir1.name("nesteddir2/testcsv1"); NBPathsAPI.GetExtension getExtension = nesteddir1.name("nesteddir2/testcsv1");
NBPathsAPI.ForExtension forCsvExtension = forName.extension(".csv"); NBPathsAPI.DoSearch forCsvExtension = getExtension.extension(".csv");
Optional<Content<?>> testcsv1 = forCsvExtension.first(); Optional<Content<?>> testcsv1 = forCsvExtension.first();
assertThat(testcsv1).isNotPresent(); assertThat(testcsv1).isNotPresent();
@@ -80,10 +80,10 @@ public class NBIOTest {
@Test @Test
public void testLoadCsv1Filesystem() { public void testLoadCsv1Filesystem() {
NBPathsAPI.ForPrefix forSourceType = NBIO.fs(); NBPathsAPI.GetPrefix forSourceType = NBIO.fs();
NBPathsAPI.WantsContentName nesteddir1 = forSourceType.prefix("target/test-classes/nesteddir1"); NBPathsAPI.GetName nesteddir1 = forSourceType.prefix("target/test-classes/nesteddir1");
NBPathsAPI.ForName forName = nesteddir1.name("nesteddir2/testcsv1"); NBPathsAPI.GetExtension getExtension = nesteddir1.name("nesteddir2/testcsv1");
NBPathsAPI.ForExtension forCsvExtension = forName.extension(".csv"); NBPathsAPI.DoSearch forCsvExtension = getExtension.extension(".csv");
Optional<Content<?>> testcsv1 = forCsvExtension.first(); Optional<Content<?>> testcsv1 = forCsvExtension.first();
assertThat(testcsv1).isNotPresent(); assertThat(testcsv1).isNotPresent();