use of java.util.function.BiPredicate in project jena by apache.
the class AbstractRunnerFiles method getFiles.
protected final List<String> getFiles(String directory, Set<String> includes, Set<String> excludes) {
Path src = Path.of(directory);
BiPredicate<Path, BasicFileAttributes> predicate = (path, attr) -> attr.isRegularFile() && path.toString().endsWith(".shex");
List<String> files = new ArrayList<>();
if (includes.isEmpty()) {
try {
Files.find(src, 1, predicate).filter(p -> !excludes.contains(p.getFileName().toString())).sorted().map(Path::toString).forEach(files::add);
} catch (IOException e) {
e.printStackTrace();
}
} else {
includes.forEach(fn -> files.add(fn));
}
return files;
}
use of java.util.function.BiPredicate in project groovy by apache.
the class StaticTypeCheckingVisitor method getLiteralResultType.
/**
* For "{@code List<Type> x = [...]}" or "{@code Set<Type> y = [...]}", etc.
* the literal may be composed of sub-types of {@code Type}. In these cases,
* {@code ArrayList<Type>} is an appropriate result type for the expression.
*/
private static ClassNode getLiteralResultType(final ClassNode targetType, final ClassNode sourceType, final ClassNode baseType) {
ClassNode resultType = sourceType.equals(baseType) ? sourceType : GenericsUtils.parameterizeType(sourceType, baseType.getPlainNodeReference());
if (targetType.getGenericsTypes() != null && !GenericsUtils.buildWildcardType(targetType).isCompatibleWith(resultType)) {
BiPredicate<GenericsType, GenericsType> isEqualOrSuper = (target, source) -> {
if (target.isCompatibleWith(source.getType())) {
return true;
}
if (!target.isPlaceholder() && !target.isWildcard()) {
return GenericsUtils.buildWildcardType(getCombinedBoundType(target)).isCompatibleWith(source.getType());
}
return false;
};
GenericsType[] lgt = targetType.getGenericsTypes(), rgt = resultType.getGenericsTypes();
if (IntStream.range(0, lgt.length).allMatch(i -> isEqualOrSuper.test(lgt[i], rgt[i]))) {
resultType = GenericsUtils.parameterizeType(targetType, baseType.getPlainNodeReference());
}
}
return resultType;
}
use of java.util.function.BiPredicate in project suite by stupidsing.
the class ServerMain method handler.
private Handler handler() {
BiPredicate<String, String> authenticate = (username, password) -> //
Defaults.secrets().prove(Suite.substitute("auth .0 .1", new Str(username), new Str(password)));
Fun2<String, String, List<String>> authenticateRoles = (username, password) -> {
return authenticate.test(username, password) ? List.of("role") : null;
};
var sseHeaders = new Header(//
PerMap.<String, PerList<String>>empty().put("Cache-Control", //
PerList.of("no-cache")).put("Content-Type", PerList.of("text/event-stream")));
Handler handlerDump = request -> Response.of(Pull.from(//
"" + //
"<html>" + "<br/>method = " + //
request.method + "<br/>server = " + //
request.server + "<br/>paths = " + //
request.paths + "<br/>attrs = " + //
HttpHeaderUtil.getAttrs(request.query) + "<br/>headers = " + //
request.headers + "</html>"));
Handler handlerSse = request -> Response.ofWriter(Http.S200, sseHeaders, write -> {
new Object() {
private int i = 8;
private void dispatch() {
sleep.sink2(1000l, () -> {
if (0 < i--) {
var event = "event: number\ndata: { \"i\": " + i + " }\n\n";
write.f(Bytes.of(event.getBytes(Utf8.charset)));
dispatch();
} else
write.f(null);
});
}
}.dispatch();
});
Handler handlerStatus = request -> {
var cfg = new TradeCfgImpl();
var summarize = Summarize.of(cfg);
var sbs = summarize.summarize(trade -> trade.strategy);
return Response.of(Pull.from("<pre>" + sbs.log + new TreeMap<>(sbs.pnlByKey) + "</pre>"));
};
var hh = new HttpHandle();
var hhsa = new HttpHandleSessionAuth();
var hhta = new HttpHandleTokenAuth();
return hh.routeByPath(//
PerMap.<String, Handler>empty().put("api", //
hhta.applyFilter("role", hh.serveText("in good shape"))).put("hello", //
hh.serveText("hello world")).put("html", //
hh.serveDir(Paths.get(FileUtil.suiteDir() + "/src/main/html"))).put("path", //
hh.serveDir(Tmp.root)).put("site", //
hhsa.getHandler(authenticate, handlerDump)).put("sse", //
handlerSse).put("status", //
handlerStatus).put("token", hh.routeByMethod(//
PerMap.<String, Handler>empty().put("PATCH", //
hhta.refreshToken(authenticateRoles)).put("POST", hhta.getToken(authenticateRoles)))));
}
use of java.util.function.BiPredicate in project Payara by payara.
the class ModelInvariantsTest method addKeyValueIgnoresNull.
@Test
public void addKeyValueIgnoresNull() {
BiPredicate<Extensible<?>, String> hasExtension = (obj, key) -> obj.getExtensions().containsKey(key);
assertAddIgnoresNull(new CallbackImpl(), Callback::addPathItem, Callback::hasPathItem);
assertAddIgnoresNull(new CallbackImpl(), Callback::addExtension, hasExtension);
assertAddIgnoresNull(new ExampleImpl(), Example::addExtension, hasExtension);
assertAddIgnoresNull(new HeaderImpl(), Header::addExample, (obj, key) -> obj.getExamples().containsKey(key));
assertAddIgnoresNull(new HeaderImpl(), Header::addExtension, hasExtension);
assertAddIgnoresNull(new ContactImpl(), Contact::addExtension, hasExtension);
assertAddIgnoresNull(new InfoImpl(), Info::addExtension, hasExtension);
assertAddIgnoresNull(new LicenseImpl(), License::addExtension, hasExtension);
assertAddIgnoresNull(new LinkImpl(), Link::addParameter, (obj, key) -> obj.getParameters().containsKey(key));
assertAddIgnoresNull(new LinkImpl(), Link::addExtension, hasExtension);
assertAddIgnoresNull(new ContentImpl(), Content::addMediaType, Content::hasMediaType);
assertAddIgnoresNull(new DiscriminatorImpl(), Discriminator::addMapping, (obj, key) -> obj.getMapping().containsKey(key));
assertAddIgnoresNull(new EncodingImpl(), Encoding::addHeader, (obj, key) -> obj.getHeaders().containsKey(key));
assertAddIgnoresNull(new EncodingImpl(), Encoding::addExtension, hasExtension);
assertAddIgnoresNull(new MediaTypeImpl(), MediaType::addEncoding, (obj, key) -> obj.getEncoding().containsKey(key));
assertAddIgnoresNull(new MediaTypeImpl(), MediaType::addExample, (obj, key) -> obj.getExamples().containsKey(key));
assertAddIgnoresNull(new MediaTypeImpl(), MediaType::addExtension, hasExtension);
assertAddIgnoresNull(new SchemaImpl(), Schema::addProperty, (obj, key) -> obj.getProperties().containsKey(key));
assertAddIgnoresNull(new SchemaImpl(), Schema::addExtension, hasExtension);
assertAddIgnoresNull(new XMLImpl(), XML::addExtension, hasExtension);
assertAddIgnoresNull(new ParameterImpl(), Parameter::addExample, (obj, key) -> obj.getExamples().containsKey(key));
assertAddIgnoresNull(new ParameterImpl(), Parameter::addExtension, hasExtension);
assertAddIgnoresNull(new RequestBodyImpl(), RequestBody::addExtension, hasExtension);
assertAddIgnoresNull(new APIResponseImpl(), APIResponse::addHeader, (obj, key) -> obj.getHeaders().containsKey(key));
assertAddIgnoresNull(new APIResponseImpl(), APIResponse::addLink, (obj, key) -> obj.getLinks().containsKey(key));
assertAddIgnoresNull(new APIResponseImpl(), APIResponse::addExtension, hasExtension);
assertAddIgnoresNull(new APIResponsesImpl(), APIResponses::addAPIResponse, APIResponses::hasAPIResponse);
assertAddIgnoresNull(new APIResponsesImpl(), APIResponses::addExtension, hasExtension);
assertAddIgnoresNull(new OAuthFlowImpl(), OAuthFlow::addExtension, hasExtension);
assertAddIgnoresNull(new OAuthFlowsImpl(), OAuthFlows::addExtension, hasExtension);
assertAddIgnoresNull(new SecuritySchemeImpl(), SecurityScheme::addExtension, hasExtension);
assertAddIgnoresNull(new ServerImpl(), Server::addExtension, hasExtension);
assertAddIgnoresNull(new ServerVariableImpl(), ServerVariable::addExtension, hasExtension);
assertAddIgnoresNull(new TagImpl(), Tag::addExtension, hasExtension);
assertAddIgnoresNull(new ComponentsImpl(), Components::addCallback, (obj, key) -> obj.getCallbacks().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addExample, (obj, key) -> obj.getExamples().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addHeader, (obj, key) -> obj.getHeaders().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addLink, (obj, key) -> obj.getLinks().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addParameter, (obj, key) -> obj.getParameters().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addRequestBody, (obj, key) -> obj.getRequestBodies().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addResponse, (obj, key) -> obj.getResponses().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addSchema, (obj, key) -> obj.getSchemas().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addSecurityScheme, (obj, key) -> obj.getSecuritySchemes().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addExtension, hasExtension);
assertAddIgnoresNull(new ExternalDocumentationImpl(), ExternalDocumentation::addExtension, hasExtension);
assertAddIgnoresNull(new OpenAPIImpl(), OpenAPI::addExtension, hasExtension);
assertAddIgnoresNull(new OperationImpl(), Operation::addCallback, (obj, key) -> obj.getCallbacks().containsKey(key));
assertAddIgnoresNull(new OperationImpl(), Operation::addExtension, hasExtension);
assertAddIgnoresNull(new PathItemImpl(), PathItem::addExtension, hasExtension);
assertAddIgnoresNull(new PathsImpl(), Paths::addPathItem, Paths::hasPathItem);
assertAddIgnoresNull(new PathsImpl(), Paths::addExtension, hasExtension);
}
use of java.util.function.BiPredicate in project omegat by omegat-org.
the class FileUtil method buildRelativeFilesList.
public static List<String> buildRelativeFilesList(File rootDir, List<String> includes, List<String> excludes) throws IOException {
Path root = rootDir.toPath();
Pattern[] includeMasks = FileUtil.compileFileMasks(includes);
Pattern[] excludeMasks = FileUtil.compileFileMasks(excludes);
BiPredicate<Path, BasicFileAttributes> pred = (p, attr) -> {
return p.toFile().isFile() && FileUtil.checkFileInclude(root.relativize(p).toString(), includeMasks, excludeMasks);
};
try (Stream<Path> stream = Files.find(root, Integer.MAX_VALUE, pred, FileVisitOption.FOLLOW_LINKS)) {
return stream.map(p -> root.relativize(p).toString().replace('\\', '/')).sorted(StreamUtil.localeComparator(Function.identity())).collect(Collectors.toList());
}
}
Aggregations