本文整理了Java中javaslang.control.Validation.valid()
方法的一些代码示例,展示了Validation.valid()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Validation.valid()
方法的具体详情如下:
包路径:javaslang.control.Validation
类名称:Validation
方法名:valid
暂无
代码示例来源: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.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.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.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.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())));
}
代码示例来源:origin: com.io7m.smfj/com.io7m.smfj.validation.main
private Validation<List<SMFParseError>, SMFSchemaRequireVertices>
parseStatementRequireVertices(
final List<String> line)
{
if (line.size() == 2) {
final String text = line.get(1);
switch (text) {
case "true":
return valid(SMF_VERTICES_REQUIRED);
case "false":
return valid(SMF_VERTICES_NOT_REQUIRED);
default:
break;
}
}
final StringBuilder sb = new StringBuilder(128);
sb.append("Could not parse vertices requirement.");
sb.append(System.lineSeparator());
sb.append(" Expected: require-vertices (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())));
}
代码示例来源:origin: com.io7m.smfj/com.io7m.smfj.processing.main
final SMFSchemaIdentifier received = received_opt.get();
if (Objects.equals(received, this.config)) {
return valid(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.validation.main
private Validation<List<SMFParseError>, SMFSchemaIdentifier>
parseStatementIdentifier(
final List<String> text)
{
if (text.length() == 4) {
try {
final SMFSchemaName schema = SMFSchemaName.of(text.get(1));
final int major = Integer.parseUnsignedInt(text.get(2));
final int minor = Integer.parseUnsignedInt(text.get(3));
return valid(SMFSchemaIdentifier.of(schema, major, minor));
} catch (final NumberFormatException e) {
return invalid(List.of(SMFParseError.of(
this.reader.position(), e.getMessage(), Optional.of(e))));
}
}
final StringBuilder sb = new StringBuilder(128);
sb.append("Incorrect number of arguments.");
sb.append(System.lineSeparator());
sb.append(
" Expected: schema <schema> <version-major> <version-minor>");
sb.append(System.lineSeparator());
sb.append(" Received: ");
sb.append(text.toJavaStream().collect(Collectors.joining(" ")));
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
@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.processing.main
@Override
public Validation<List<SMFProcessingError>, SMFMemoryMesh> filter(
final SMFFilterCommandContext context,
final SMFMemoryMesh m)
{
NullCheck.notNull(context, "Context");
NullCheck.notNull(m, "Mesh");
final Path file = context.resolvePath(this.meta_file);
LOG.debug("resolved metadata file: {}", file);
try (final InputStream stream = Files.newInputStream(file)) {
final byte[] data = IOUtils.toByteArray(stream);
final SMFMetadata meta = SMFMetadata.of(this.schema_id, data);
final Vector<SMFMetadata> new_meta =
m.metadata().append(meta);
return valid(
SMFMemoryMesh.builder()
.from(m)
.setMetadata(new_meta)
.build());
} catch (final IOException e) {
return invalid(List.of(
SMFProcessingError.of(e.getMessage(), Optional.of(e))));
}
}
}
代码示例来源:origin: com.io7m.smfj/com.io7m.smfj.validation.main
private Validation<List<SMFErrorType>, SMFSchemaVersion> parseVersion(
final LexicalPosition<URI> position,
final List<String> line)
{
if (line.size() == 3) {
final String name = line.get(0);
if (!Objects.equals(name, "smf-schema")) {
return invalid(List.of(
this.unparseableVersionList(line, Optional.empty())));
}
try {
final int major = Integer.parseUnsignedInt(line.get(1));
final int minor = Integer.parseUnsignedInt(line.get(2));
return valid(SMFSchemaVersion.of(major, minor));
} catch (final NumberFormatException e) {
return invalid(List.of(
this.unparseableVersionList(line, Optional.of(e))));
}
}
return invalid(List.of(
this.unparseableVersionList(line, Optional.empty())));
}
代码示例来源:origin: com.io7m.smfj/com.io7m.smfj.validation.api
@Override
public Validation<List<SMFErrorType>, SMFHeader> validate(
final SMFHeader header,
final SMFSchema schema)
{
NullCheck.notNull(header, "Header");
NullCheck.notNull(schema, "Schema");
List<SMFErrorType> errors = List.empty();
final Optional<SMFSchemaIdentifier> file_id_opt = header.schemaIdentifier();
if (file_id_opt.isPresent()) {
final SMFSchemaIdentifier file_id = file_id_opt.get();
final SMFSchemaIdentifier schema_id = schema.schemaIdentifier();
if (!Objects.equals(schema_id, file_id)) {
errors = errors.append(errorWrongSchemaID(schema_id, file_id));
}
}
errors = checkVerticesAndTriangles(header, schema, errors);
errors = checkAttributes(header, schema, errors);
errors = checkCoordinateSystem(header, schema, errors);
if (errors.isEmpty()) {
return valid(header);
}
return invalid(errors);
}
代码示例来源:origin: com.io7m.smfj/com.io7m.smfj.processing.main
/**
* Attempt to parse a command.
*
* @param file The file, if any
* @param line The line
* @param text The text
*
* @return A parsed command or a list of parse errors
*/
public static Validation<List<SMFParseError>, SMFMemoryMeshFilterType> parse(
final Optional<URI> file,
final int line,
final List<String> text)
{
NullCheck.notNull(file, "file");
NullCheck.notNull(text, "text");
if (text.length() == 1) {
try {
return valid(create(Paths.get(text.get(0))));
} catch (final IllegalArgumentException e) {
return errorExpectedGotValidation(file, line, makeSyntax(), text);
}
}
return errorExpectedGotValidation(file, line, makeSyntax(), text);
}
代码示例来源:origin: com.io7m.smfj/com.io7m.smfj.processing.main
/**
* Attempt to parse a command.
*
* @param file The file, if any
* @param line The line
* @param text The text
*
* @return A parsed command or a list of parse errors
*/
public static Validation<List<SMFParseError>, SMFMemoryMeshFilterType> parse(
final Optional<URI> file,
final int line,
final List<String> text)
{
NullCheck.notNull(file, "file");
NullCheck.notNull(text, "text");
if (text.isEmpty()) {
try {
return valid(create());
} catch (final IllegalArgumentException e) {
return errorExpectedGotValidation(file, line, makeSyntax(), text);
}
}
return errorExpectedGotValidation(file, line, makeSyntax(), text);
}
代码示例来源:origin: com.io7m.smfj/com.io7m.smfj.processing.main
/**
* Attempt to parse a command.
*
* @param file The file, if any
* @param line The line
* @param text The text
*
* @return A parsed command or a list of parse errors
*/
public static Validation<List<SMFParseError>, SMFMemoryMeshFilterType> parse(
final Optional<URI> file,
final int line,
final List<String> text)
{
NullCheck.notNull(file, "file");
NullCheck.notNull(text, "text");
if (text.length() >= 1) {
try {
return valid(create(text.map(SMFAttributeName::of).toSet()));
} catch (final IllegalArgumentException e) {
return errorExpectedGotValidation(file, line, makeSyntax(), text);
}
}
return errorExpectedGotValidation(file, line, makeSyntax(), text);
}
代码示例来源:origin: com.io7m.smfj/com.io7m.smfj.processing.main
/**
* Attempt to parse a command.
*
* @param file The file, if any
* @param line The line
* @param text The text
*
* @return A parsed command or a list of parse errors
*/
public static Validation<List<SMFParseError>, SMFMemoryMeshFilterType> parse(
final Optional<URI> file,
final int line,
final List<String> text)
{
NullCheck.notNull(file, "file");
NullCheck.notNull(text, "text");
if (text.length() == 1) {
try {
final SMFAttributeName attr = SMFAttributeName.of(text.get(0));
return Validation.valid(create(attr));
} catch (final IllegalArgumentException e) {
return errorExpectedGotValidation(file, line, makeSyntax(), text);
}
}
return errorExpectedGotValidation(file, line, makeSyntax(), text);
}
代码示例来源:origin: com.io7m.smfj/com.io7m.smfj.processing.main
/**
* Attempt to parse a command.
*
* @param file The file, if any
* @param line The line
* @param text The text
*
* @return A parsed command or a list of parse errors
*/
public static Validation<List<SMFParseError>, SMFMemoryMeshFilterType> parse(
final Optional<URI> file,
final int line,
final List<String> text)
{
NullCheck.notNull(file, "file");
NullCheck.notNull(text, "text");
if (text.length() == 2) {
try {
final SMFAttributeName name = SMFAttributeName.of(text.get(0));
final int size = Integer.parseUnsignedInt(text.get(1));
return valid(create(name, size));
} catch (final IllegalArgumentException e) {
return errorExpectedGotValidation(file, line, makeSyntax(), text);
}
}
return errorExpectedGotValidation(file, line, makeSyntax(), text);
}
代码示例来源:origin: com.io7m.smfj/com.io7m.smfj.processing.main
/**
* Attempt to parse a command.
*
* @param file The file, if any
* @param line The line
* @param text The text
*
* @return A parsed command or a list of parse errors
*/
public static Validation<List<SMFParseError>, SMFMemoryMeshFilterType> parse(
final Optional<URI> file,
final int line,
final List<String> text)
{
NullCheck.notNull(file, "file");
NullCheck.notNull(text, "text");
if (text.length() == 2) {
try {
final SMFAttributeName source = SMFAttributeName.of(text.get(0));
final SMFAttributeName target = SMFAttributeName.of(text.get(1));
return Validation.valid(
create(source, target));
} catch (final IllegalArgumentException e) {
return errorExpectedGotValidation(file, line, makeSyntax(), text);
}
}
return errorExpectedGotValidation(file, line, makeSyntax(), text);
}
代码示例来源:origin: com.io7m.smfj/com.io7m.smfj.processing.main
final SMFHeader new_header =
header.withAttributesInOrder(new_by_order);
return valid(
SMFMemoryMesh.builder()
.from(m)
内容来源于网络,如有侵权,请联系作者删除!