@Override public void onMetaData( final long vendor, final long schema, final byte[] data) { for (int index = 0; index < this.want.length; ++index) { if (this.want[index]) { this.delegates.get(index).onMetaData(vendor, schema, data); } } } }
@Override public boolean onMeta( final long vendor, final long schema, final long length) { boolean any = false; for (int index = 0; index < this.want.length; ++index) { final boolean want_now = this.delegates.get(index).onMeta(vendor, schema, length); this.want[index] = want_now; any = any || want_now; } return any; }
private void parseMeta( final List<String> line) throws Exception { if (line.length() == 4) { final long vendor_id = (long) Integer.parseUnsignedInt(line.get(1), 16); final long schema_id = (long) Integer.parseUnsignedInt(line.get(2), 16); final long lines = Long.parseUnsignedLong(line.get(3)); this.parseMetaDataValues(vendor_id, schema_id, lines); } else { super.failExpectedGot( "Incorrect number of arguments", "meta <vendor-id> <schema-id> <integer-unsigned>", 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()))); }
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()))); }
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(" "))); } }
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()))); }
/** * @return The attributes by name */ @Value.Derived default SortedMap<SMFAttributeName, SMFAttribute> attributesByName() { SortedMap<SMFAttributeName, SMFAttribute> m = TreeMap.empty(); final List<SMFAttribute> ordered = this.attributesInOrder(); for (int index = 0; index < ordered.size(); ++index) { final SMFAttribute attr = ordered.get(index); if (m.containsKey(attr.name())) { final StringBuilder sb = new StringBuilder(128); sb.append("Duplicate attribute name."); sb.append(System.lineSeparator()); sb.append(" Attribute: "); sb.append(attr.name().value()); sb.append(System.lineSeparator()); throw new IllegalArgumentException(sb.toString()); } m = m.put(attr.name(), attr); } return m; }
/** * @return The attributes by name */ @Value.Derived default SortedMap<SMFAttributeName, SMFAttribute> attributesByName() { SortedMap<SMFAttributeName, SMFAttribute> m = TreeMap.empty(); final List<SMFAttribute> ordered = this.attributesInOrder(); for (int index = 0; index < ordered.size(); ++index) { final SMFAttribute attr = ordered.get(index); if (m.containsKey(attr.name())) { final StringBuilder sb = new StringBuilder(128); sb.append("Duplicate attribute name."); sb.append(System.lineSeparator()); sb.append(" Attribute: "); sb.append(attr.name().value()); sb.append(System.lineSeparator()); throw new IllegalArgumentException(sb.toString()); } m = m.put(attr.name(), attr); } return m; }
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()))); }
Optional<Pair<Integer, Integer>> schema_version = Optional.empty(); if (Objects.equals(text.get(0), "-")) { schema_name = Optional.empty(); } else { schema_name = Optional.of(SMFSchemaName.of(text.get(0))); final int major = Integer.parseUnsignedInt(text.get(1)); final int minor = Integer.parseUnsignedInt(text.get(2)); schema_version = Optional.of(Pair.pair(
/** * 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() == 4) { try { final SMFSchemaName name = SMFSchemaName.of(text.get(0)); final int major = Integer.parseUnsignedInt(text.get(1)); final int minor = Integer.parseUnsignedInt(text.get(2)); final Path path = Paths.get(text.get(3)); return valid(create(SMFSchemaIdentifier.of(name, major, minor), path)); } catch (final IllegalArgumentException e) { return errorExpectedGotValidation(file, line, makeSyntax(), text); } } return errorExpectedGotValidation(file, line, makeSyntax(), text); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }