本文整理了Java中javaslang.collection.List.of()
方法的一些代码示例,展示了List.of()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。List.of()
方法的具体详情如下:
包路径:javaslang.collection.List
类名称:List
方法名:of
暂无
代码示例来源:origin: Vedenin/useful-java-links
/**
* A persistent data structure does preserve the previous version of itself when being modified and is therefore effectively immutable. Fully persistent data structures allow both updates and queries on any version.
*
*/
private void createCollection() {
System.out.println();
System.out.println("createList");
List<Integer> list1 = List.of(1, 2, 3);
System.out.println(list1); // print List(1, 2, 3)
List<Integer> list2 = list1.tail().prepend(0);
System.out.println(list2); // print List(0, 2, 3)
System.out.println();
System.out.println("createQueue");
Queue<Integer> queue = Queue.of(1, 2, 3)
.enqueue(4)
.enqueue(5);
System.out.println(queue); // print Queue(1, 2, 3, 4, 5)
}
代码示例来源:origin: dswarm/dswarm
/**
* sort components re. their natural order (begin from the end, i.e., component without output components)
*
* @param components original components set
* @return
*/
private static javaslang.collection.List<Component> sortComponents(final Set<Component> components) {
final Optional<Component> optionalLastComponent = components.stream()
.filter(component -> {
final Set<Component> outputComponents = component.getOutputComponents();
return outputComponents == null || outputComponents.isEmpty();
})
.findFirst();
if (!optionalLastComponent.isPresent()) {
return javaslang.collection.List.ofAll(components);
}
final Component lastComponent = optionalLastComponent.get();
final javaslang.collection.List<Component> lastComponentList = javaslang.collection.List.of(lastComponent);
final javaslang.collection.Map<String, Component> componentMap = javaslang.collection.HashSet.ofAll(components)
.toMap(component -> Tuple.of(component.getUuid(), component));
final javaslang.collection.List<Component> emptyComponentList = javaslang.collection.List.empty();
return addComponents(lastComponentList, componentMap, emptyComponentList);
}
代码示例来源: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
sb.append(text);
sb.append(System.lineSeparator());
return List.of(SMFProcessingError.of(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.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>, 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>, 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.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>, 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: dswarm/dswarm
/**
* _1 = mapping output - last attribute
* _2 = mapping output attributes - last attribute
* _3 = last attribute of mapping output
*
* @param mappingOutput
* @return
*/
private static Optional<Tuple3<Optional<String>, javaslang.collection.List<String>, String>> determineMappingOutputAttribute(final MappingAttributePathInstance mappingOutput) {
return Optional.ofNullable(mappingOutput)
.flatMap(mappingOutput1 -> Optional.ofNullable(mappingOutput1.getAttributePath()))
.flatMap(attributePath -> Optional.ofNullable(attributePath.toAttributePath()))
.flatMap(attributePathString -> {
// .ESCAPE_XML11.with(NumericEntityEscaper.between(0x7f, Integer.MAX_VALUE)).translate( <- also doesn't work
final String escapedMappingOutputAP = StringEscapeUtils.escapeXml(attributePathString);
final javaslang.collection.List<String> mappingOutputAttributes = javaslang.collection.List.of(escapedMappingOutputAP.split(ATTRIBUTE_DELIMITER));
if (mappingOutputAttributes.isEmpty()) {
return Optional.of(Tuple.of(Optional.empty(), mappingOutputAttributes.init(), escapedMappingOutputAP));
}
final String lastAttribute = mappingOutputAttributes.last();
final String mappingOutputRoot = mappingOutputAttributes.init().mkString(ATTRIBUTE_DELIMITER);
final Optional<String> optionalMappingOutputRoot = Optional.of(mappingOutputRoot).filter(mappingOutputRoot1 -> !mappingOutputRoot1.isEmpty());
return Optional.of(Tuple.of(optionalMappingOutputRoot, mappingOutputAttributes.init(), lastAttribute));
});
}
代码示例来源: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(List.of(
SMFProcessingError.of(e.getMessage(), Optional.of(e))));
代码示例来源:origin: com.io7m.smfj.jcanephora/io7m-smfj-jcanephora-tests
@Test
public void testDuplicate()
{
final SMFArrayAttributeMapping m0 = SMFArrayAttributeMapping.of(
SMFAttributeName.of("a"), 0, Optional.of(JCGLScalarType.TYPE_FLOAT), 4);
final SMFArrayAttributeMapping m1 = SMFArrayAttributeMapping.of(
SMFAttributeName.of("b"), 0, Optional.of(JCGLScalarType.TYPE_FLOAT), 4);
this.expected.expect(IllegalArgumentException.class);
SMFArrayObjectConfiguration.builder()
.setMappings(HashMap.ofEntries(List.of(
Tuple.of(SMFAttributeName.of("a"), m0),
Tuple.of(SMFAttributeName.of("b"), m1))))
.build();
}
代码示例来源:origin: com.io7m.smfj.jcanephora/io7m-smfj-jcanephora-tests
@Test
public void testMappings()
{
final SMFArrayAttributeMapping m0 = SMFArrayAttributeMapping.of(
SMFAttributeName.of("a"), 0, Optional.of(JCGLScalarType.TYPE_FLOAT), 4);
final SMFArrayAttributeMapping m1 = SMFArrayAttributeMapping.of(
SMFAttributeName.of("b"), 1, Optional.of(JCGLScalarType.TYPE_FLOAT), 4);
final SMFArrayObjectConfiguration m =
SMFArrayObjectConfiguration.builder()
.setMappings(HashMap.ofEntries(List.of(
Tuple.of(SMFAttributeName.of("a"), m0),
Tuple.of(SMFAttributeName.of("b"), m1))))
.setIndexBufferUsage(JCGLUsageHint.USAGE_DYNAMIC_COPY)
.setArrayBufferUsage(JCGLUsageHint.USAGE_STREAM_READ)
.build();
Assert.assertEquals(JCGLUsageHint.USAGE_DYNAMIC_COPY, m.indexBufferUsage());
Assert.assertEquals(JCGLUsageHint.USAGE_STREAM_READ, m.arrayBufferUsage());
Assert.assertEquals(m0, m.mappings().get(SMFAttributeName.of("a")).get());
Assert.assertEquals(m1, m.mappings().get(SMFAttributeName.of("b")).get());
Assert.assertEquals(2L, (long) m.mappings().size());
}
}
内容来源于网络,如有侵权,请联系作者删除!