@Encoding.Naming(standard = Encoding.StandardNaming.ADD) @Encoding.Init void add( final T element) { this.list = this.list.append(element); }
@Encoding.Naming(value = "setIterable*") @Encoding.Init void setIterable( final Iterable<T> elements) { this.linear_seq = List.ofAll(elements); }
/** * 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) }
if (line.isEmpty()) { return invalid(List.of(this.makeErrorExpectedGot( "The first line must be a version declaration.", "smf <version-major> <version-minor>", line.toJavaStream().collect(Collectors.joining(" "))))); switch (line.get(0)) { case "smf": { if (line.length() != 3) { return invalid(List.of(this.makeErrorExpectedGot( "Incorrect number of arguments.", "smf <version-major> <version-minor>", line.toJavaStream().collect(Collectors.joining(" "))))); final int major = Integer.parseUnsignedInt(line.get(1)); final int minor = Integer.parseUnsignedInt(line.get(2)); 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>", line.toJavaStream().collect(Collectors.joining(" "))))); return invalid(List.of(this.makeErrorExpectedGot( "Unrecognized command.", "smf <version-major> <version-minor>", line.toJavaStream().collect(Collectors.joining(" ")))));
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()))); }
@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); }
if (line.isEmpty()) { continue; switch (line.get(0)) { case "triangles": { if (line.size() == 1) { this.parseTriangles(); } else { "Incorrect number of arguments", "triangles", line.toJavaStream().collect(Collectors.joining(" "))); return; if (line.size() == 1) { this.parseMetas(); } else { "Incorrect number of arguments", "metadata", line.toJavaStream().collect(Collectors.joining(" "))); return; if (line.size() == 2) { final SMFAttributeName name; name = SMFAttributeName.of(line.get(1)); } catch (final IllegalArgumentException e) { super.failExpectedGot(
@Override public JCGLArrayBufferType arrayBuffer() throws IllegalStateException { if (!this.errors.isEmpty()) { throw new IllegalStateException("Array loading has failed"); } return this.array_buffer; }
/** * 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); }
final List<String> line) final String name = line.get(0); switch (name) { return errors.appendAll(result.getError()); return errors.appendAll(result.getError()); return errors.appendAll(result.getError()); return errors.appendAll(result.getError()); return errors.appendAll(result.getError()); "Unrecognized schema statement: " + name, Optional.empty()); return errors.append(error);
private void parseHeaderCommandSchema( final List<String> line) { if (line.size() == 5) { try { final int vendor = Integer.parseUnsignedInt(line.get(1), 16); final int schema = Integer.parseUnsignedInt(line.get(2), 16); final int schema_version_major = Integer.parseUnsignedInt(line.get(3)); final int schema_version_minor = Integer.parseUnsignedInt(line.get(4)); this.schema_id = SMFSchemaIdentifier.of( vendor, schema, schema_version_major, schema_version_minor); } catch (final NumberFormatException e) { super.failExpectedGot( "Could not parse number: " + e.getMessage(), "schema <vendor-id> <schema-id> <schema-version-major> <schema-version-minor>", line.toJavaStream().collect(Collectors.joining(" "))); } } else { super.failExpectedGot( "Incorrect number of arguments", "schema <vendor-id> <schema-id> <schema-version-major> <schema-version-minor>", line.toJavaStream().collect(Collectors.joining(" "))); } }
error_x = checkComponentCount(error_x, name, attr_schema, attribute); } else if (schema.allowExtraAttributes() == SMF_EXTRA_ATTRIBUTES_DISALLOWED) { error_x = errors.append(errorExtraAttribute(name)); error_x = error_x.appendAll( missing.toList().map(SMFSchemaValidator::errorMissingAttribute)); return error_x;
if (line.isEmpty()) { continue; switch (line.get(0)) { case "meta": { this.parseMeta(line); "Expected a meta command.", "meta <vendor-id> <schema-id> <integer-unsigned>", line.toJavaStream().collect(Collectors.joining(" "))); break;
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()))); }
private SMFByteBufferPackedMeshes( final SMFParserEventsDataMetaOptionalSupplierType in_meta, final SMFByteBufferPackerEventsType in_events) { this.meta = NullCheck.notNull(in_meta, "Meta"); this.events = NullCheck.notNull(in_events, "Events"); this.errors = List.empty(); this.warnings = List.empty(); }
/** * _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)); }); }
/** * 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); }
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()))); }
Seq<SMFProcessingError> errors = List.empty(); for (final SMFAttributeName name : this.attributes) { errors = checkAttributeExists(errors, by_name, name); header.attributesInOrder().filter(a -> this.attributes.contains(a.name())); final Map<SMFAttributeName, SMFAttributeArrayType> new_arrays = m.arrays().filter(p -> this.attributes.contains(p._1)); return invalid(List.ofAll(errors));
Seq<SMFProcessingError> errors = List.empty(); errors = checkAttributeExists(errors, by_name, this.attribute); original.withComponentSizeBits(this.size); final List<SMFAttribute> ordered = header.attributesInOrder().replace(original, resampled); final SMFHeader new_header = header.withAttributesInOrder(ordered); return invalid(List.ofAll(errors));