/** * Construct a new immutable {@code SMFSchemaName} instance. * @param value The value for the {@code value} attribute * @return An immutable SMFSchemaName instance */ public static SMFSchemaName of(String value) { return validate(new SMFSchemaName(value)); }
private static SMFSchemaName validate(SMFSchemaName instance) { instance.checkPreconditions(); return instance; }
/** * This instance is equal to all instances of {@code SMFSchemaName} that have equal attribute values. * @return {@code true} if {@code this} is equal to {@code another} instance */ @Override public boolean equals(Object another) { if (this == another) return true; return another instanceof SMFSchemaName && equalTo((SMFSchemaName) another); }
private String matchString() { final StringBuilder sb = new StringBuilder(64); if (this.name.isPresent()) { sb.append(this.name.get().value()); } else { sb.append("-"); } sb.append(" "); if (this.version.isPresent()) { sb.append(Integer.toUnsignedString( this.version.get().getLeft().intValue())); sb.append(" "); sb.append(Integer.toUnsignedString( this.version.get().getRight().intValue())); } else { sb.append("-"); } return sb.toString(); } }
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()))); }
/** * Computes a hash code from attributes: {@code name}, {@code versionMajor}, {@code versionMinor}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + name.hashCode(); h += (h << 5) + versionMajor; h += (h << 5) + versionMinor; return h; }
private boolean equalTo(SMFSchemaIdentifier another) { return name.equals(another.name) && versionMajor == another.versionMajor && versionMinor == another.versionMinor; }
/** * Builds a new {@link SMFSchemaName SMFSchemaName}. * @return An immutable instance of SMFSchemaName * @throws java.lang.IllegalStateException if any required attributes are missing */ public SMFSchemaName build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return SMFSchemaName.validate(new SMFSchemaName(null, value)); }
/** * Creates an immutable copy of a {@link SMFSchemaNameType} value. * Uses accessors to get values to initialize the new immutable instance. * If an instance is already immutable, it is returned as is. * @param instance The instance to copy * @return A copied immutable SMFSchemaName instance */ public static SMFSchemaName copyOf(SMFSchemaNameType instance) { if (instance instanceof SMFSchemaName) { return (SMFSchemaName) instance; } return SMFSchemaName.builder() .from(instance) .build(); }
writer.append(id.name().value()); writer.append(" "); writer.append(Integer.toUnsignedString(id.versionMajor()));
SMFMetadata.of( SMFSchemaIdentifier.of( SMFSchemaName.of("com.io7m.smf.application"), 1, 0),
/** * @return A humanly-readable string describing the schema identifier */ @Value.Lazy default String toHumanString() { return String.format( "%s %s.%s", this.name().value(), Integer.toUnsignedString(this.versionMajor()), Integer.toUnsignedString(this.versionMinor())); } }
schema_name = Optional.empty(); } else { schema_name = Optional.of(SMFSchemaName.of(text.get(0)));
/** * Copy the current immutable object by setting a value for the {@link SMFSchemaNameType#value() value} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for value * @return A modified copy of the {@code this} object */ public final SMFSchemaName withValue(String value) { if (this.value.equals(value)) return this; String newValue = Objects.requireNonNull(value, "value"); return validate(new SMFSchemaName(this, newValue)); }
/** * 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); }
final SMFSchemaName schema = SMFSchemaName.of(text.get(0)); final int major = Integer.parseUnsignedInt(text.get(1)); final int minor = Integer.parseUnsignedInt(text.get(2));
final SMFSchemaName schema = SMFSchemaName.of(text.get(0)); final int major = Integer.parseUnsignedInt(text.get(1)); final int minor = Integer.parseUnsignedInt(text.get(2));