javaslang.control.Validation.invalid()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(177)

本文整理了Java中javaslang.control.Validation.invalid()方法的一些代码示例,展示了Validation.invalid()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Validation.invalid()方法的具体详情如下:
包路径:javaslang.control.Validation
类名称:Validation
方法名:invalid

Validation.invalid介绍

暂无

代码示例

代码示例来源: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>, 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

return invalid(List.of(
 SMFProcessingError.of(sb.toString(), Optional.empty())));

代码示例来源: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.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/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>, 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>, 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.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.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/io7m-smfj-format-text

return invalid(List.of(this.makeErrorExpectedGot(
 "The first line must be a version declaration.",
 "smf <version-major> <version-minor>",
case "smf": {
 if (line.length() != 3) {
  return invalid(List.of(this.makeErrorExpectedGot(
   "Incorrect number of arguments.",
   "smf <version-major> <version-minor>",
  return valid(SMFFormatVersion.of(major, minor));
 } catch (final NumberFormatException e) {
  return invalid(List.of(this.makeErrorExpectedGot(
   "Cannot parse number: " + e.getMessage(),
   "smf <version-major> <version-minor>",
 return invalid(List.of(this.makeErrorExpectedGot(
  "Unrecognized command.",
  "smf <version-major> <version-minor>",

代码示例来源: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.processing.main

return invalid(this.expectedGot(
  String.format(
   "An attribute '%s' with %d components of type %s with size %d",
return invalid(this.expectedGot("nothing"));

代码示例来源: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.probe.api

errors = errors.append(errorWithMessage("No format providers available."));
return Validation.invalid(errors);

代码示例来源:origin: com.io7m.smfj/com.io7m.smfj.processing.main

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.processing.main

m.withHeader(m.header().withTriangles(new_triangles)));
return Validation.invalid(errors);

代码示例来源:origin: com.io7m.smfj/com.io7m.smfj.processing.main

return invalid(List.ofAll(errors));

代码示例来源:origin: com.io7m.smfj/com.io7m.smfj.processing.main

return invalid(List.ofAll(errors));

相关文章