本文整理了Java中javaslang.control.Validation
类的一些代码示例,展示了Validation
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Validation
类的具体详情如下:
包路径:javaslang.control.Validation
类名称:Validation
暂无
代码示例来源:origin: com.io7m.smfj/com.io7m.smfj.validation.main
private Validation<List<SMFParseError>, Optional<SMFComponentType>>
parseComponentType(
final String text)
{
if (Objects.equals(text, "-")) {
return valid(Optional.empty());
}
try {
return valid(Optional.of(SMFComponentType.of(text)));
} catch (final IllegalArgumentException e) {
return invalid(List.of(SMFParseError.of(
this.reader.position(),
"Could not parse component type: " + e.getMessage(),
Optional.of(e))));
}
}
代码示例来源:origin: com.io7m.smfj/com.io7m.smfj.processing.main
parser_provider.schemaParserCreate(file.toUri(), stream)) {
final Validation<List<SMFErrorType>, SMFSchema> result_schema = parser.parseSchema();
if (result_schema.isValid()) {
final SMFSchema schema = result_schema.get();
final Validation<List<SMFErrorType>, SMFHeader> result_valid =
validator.validate(m.header(), schema);
if (result_valid.isValid()) {
return valid(m);
return invalid(
result_valid.getError()
.map(e -> SMFProcessingError.of(e.message(), e.exception())));
return invalid(
result_schema.getError()
.map(e -> SMFProcessingError.of(e.message(), e.exception())));
return invalid(List.of(
SMFProcessingError.of(e.getMessage(), Optional.of(e))));
代码示例来源:origin: com.io7m.smfj/com.io7m.smfj.validation.main
final Validation<List<SMFErrorType>, SMFSchemaVersion> r_version =
this.parseVersion(reader.position(), line.get());
if (r_version.isInvalid()) {
return invalid(r_version.getError());
final SMFSchemaVersion version = r_version.get();
if (version.major() == 1) {
return new ParserV1(version, reader, this.uri).parseSchema();
"Empty file: Must begin with an smf-schema version declaration",
Optional.empty());
return invalid(List.of(error));
} catch (final IOException e) {
final SMFParseError error =
SMFParseError.of(reader.position(), "I/O error", Optional.of(e));
return invalid(List.of(error));
"I/O error",
Optional.of(e));
return invalid(List.of(error));
代码示例来源:origin: com.io7m.smfj/com.io7m.smfj.validation.main
final Validation<List<SMFParseError>, SMFSchemaIdentifier> result =
this.parseStatementIdentifier(line);
if (result.isValid()) {
final SMFSchemaIdentifier p = result.get();
this.received_identifier = true;
builder.setSchemaIdentifier(p);
return errors.appendAll(result.getError());
final Validation<List<SMFParseError>, SMFCoordinateSystem> result =
this.parseStatementCoordinates(line);
if (result.isValid()) {
builder.setRequiredCoordinateSystem(result.get());
return errors;
return errors.appendAll(result.getError());
final Validation<List<SMFParseError>, SMFSchemaRequireVertices> result =
this.parseStatementRequireVertices(line);
if (result.isValid()) {
builder.setRequireVertices(result.get());
return errors;
return errors.appendAll(result.getError());
final Validation<List<SMFParseError>, SMFSchemaRequireTriangles> result =
this.parseStatementRequireTriangles(line);
if (result.isValid()) {
builder.setRequireTriangles(result.get());
代码示例来源:origin: com.io7m.smfj/com.io7m.smfj.probe.api
final Validation<Seq<SMFParseError>, SMFVersionProbed> r =
probe.probe(stream);
if (r.isInvalid()) {
errors = errors.appendAll(r.getError());
} else {
return r;
errors = errors.append(errorWithMessage("No format providers available."));
return Validation.invalid(errors);
代码示例来源:origin: com.io7m.smfj/com.io7m.smfj.processing.main
out.toByteArray());
return valid(
SMFMemoryMesh.builder()
.from(m)
代码示例来源:origin: com.io7m.smfj/com.io7m.smfj.bytebuffer
if (result.isInvalid()) {
this.errors = this.errors.appendAll(result.getError());
return Optional.empty();
this.config = result.get();
代码示例来源:origin: com.io7m.smfj/com.io7m.smfj.validation.main
Validation.combine(v_req, v_name, v_type, v_count, v_size)
.ap((req, name, type, count, size) ->
Tuple.of(
sb.append(line.toJavaStream().collect(Collectors.joining(" ")));
sb.append(System.lineSeparator());
return invalid(List.of(SMFParseError.of(
this.reader.position(),
sb.toString(),
代码示例来源:origin: com.io7m.smfj/com.io7m.smfj.processing.api
/**
* Construct an error message that indicates that one sort of input was
* expected but another was received.
*
* @param uri The URI, if any
* @param line The current line number
* @param expected The expected input
* @param text The received input
*
* @return An error message
*/
public static Validation<List<SMFParseError>, SMFMemoryMeshFilterType>
errorExpectedGotValidation(
final Optional<URI> uri,
final int line,
final String expected,
final List<String> text)
{
return Validation.invalid(List.of(
errorExpectedGot(uri, line, expected, text)));
}
代码示例来源:origin: com.io7m.smfj/io7m-smfj-format-text
this.onParseVersion(line.get());
if (v_version.isValid()) {
final SMFFormatVersion version = v_version.get();
super.events.onVersionReceived(version);
switch (version.major()) {
this.failErrors(v_version.getError());
return;
代码示例来源:origin: com.io7m.smfj/com.io7m.smfj.processing.main
@Override
public Validation<List<SMFProcessingError>, SMFMemoryMesh> filter(
final SMFFilterCommandContext context,
final SMFMemoryMesh m)
{
NullCheck.notNull(context, "Context");
NullCheck.notNull(m, "Mesh");
return valid(m.withHeader(m.header().withSchemaIdentifier(this.config)));
}
}
代码示例来源:origin: com.io7m.smfj/com.io7m.smfj.validation.main
private Validation<List<SMFParseError>, OptionalInt>
parseComponentSize(
final String text)
{
if (Objects.equals(text, "-")) {
return valid(OptionalInt.empty());
}
try {
return valid(OptionalInt.of(Integer.parseUnsignedInt(text)));
} catch (final NumberFormatException e) {
return invalid(List.of(SMFParseError.of(
this.reader.position(),
"Could not parse component size: " + e.getMessage(),
Optional.of(e))));
}
}
代码示例来源:origin: com.io7m.smfj/com.io7m.smfj.processing.main
return valid(create(schema_name, schema_version));
} catch (final IllegalArgumentException e) {
return errorExpectedGotValidation(file, line, makeSyntax(), text);
代码示例来源:origin: com.io7m.smfj/com.io7m.smfj.validation.main
private Validation<List<SMFParseError>, OptionalInt>
parseComponentCount(
final String text)
{
if (Objects.equals(text, "-")) {
return valid(OptionalInt.empty());
}
try {
return valid(OptionalInt.of(Integer.parseUnsignedInt(text)));
} catch (final NumberFormatException e) {
return invalid(List.of(SMFParseError.of(
this.reader.position(),
"Could not parse component count: " + e.getMessage(),
Optional.of(e))));
}
}
代码示例来源:origin: com.io7m.smfj/com.io7m.smfj.processing.main
return valid(create(
SMFMemoryMeshFilterCheckConfiguration.builder()
.setComponentCount(count)
代码示例来源:origin: com.io7m.smfj/com.io7m.smfj.validation.main
private Validation<List<SMFParseError>, Boolean>
parseRequired(
final String text)
{
if (Objects.equals("required", text)) {
return valid(Boolean.TRUE);
}
if (Objects.equals("optional", text)) {
return valid(Boolean.FALSE);
}
final StringBuilder sb = new StringBuilder(128);
sb.append("Could not parse requirement.");
sb.append(System.lineSeparator());
sb.append(" Expected: required | optional");
sb.append(System.lineSeparator());
sb.append(" Received: ");
sb.append(text);
sb.append(System.lineSeparator());
return invalid(List.of(SMFParseError.of(
this.reader.position(),
sb.toString(),
Optional.empty())));
}
代码示例来源:origin: com.io7m.smfj/com.io7m.smfj.processing.main
});
return valid(
SMFMemoryMesh.builder()
.from(m)
代码示例来源:origin: com.io7m.smfj/com.io7m.smfj.validation.main
private Validation<List<SMFParseError>, SMFAttributeName>
parseName(
final String text)
{
try {
return valid(SMFAttributeName.of(text));
} catch (final IllegalArgumentException e) {
return invalid(List.of(SMFParseError.of(
this.reader.position(),
"Could not parse attribute name: " + e.getMessage(),
Optional.of(e))));
}
}
代码示例来源:origin: com.io7m.smfj/com.io7m.smfj.processing.main
return Validation.valid(
create(builder.build()));
} catch (final IllegalArgumentException e) {
代码示例来源:origin: com.io7m.smfj/com.io7m.smfj.validation.main
private Validation<List<SMFParseError>, SMFSchemaRequireTriangles>
parseStatementRequireTriangles(
final List<String> line)
{
if (line.size() == 2) {
final String text = line.get(1);
switch (text) {
case "true":
return valid(SMF_TRIANGLES_REQUIRED);
case "false":
return valid(SMF_TRIANGLES_NOT_REQUIRED);
default:
break;
}
}
final StringBuilder sb = new StringBuilder(128);
sb.append("Could not parse triangle requirement.");
sb.append(System.lineSeparator());
sb.append(" Expected: require-triangles (true | false)");
sb.append(System.lineSeparator());
sb.append(" Received: ");
sb.append(line.toJavaStream().collect(Collectors.joining(" ")));
sb.append(System.lineSeparator());
return invalid(List.of(SMFParseError.of(
this.reader.position(),
sb.toString(),
Optional.empty())));
}
内容来源于网络,如有侵权,请联系作者删除!