private static SMFSchemaValidationError errorExtraAttribute( final SMFAttributeName name) { final StringBuilder sb = new StringBuilder(128); sb.append( "The mesh contains an extra attribute but the schema does not permit them."); sb.append(System.lineSeparator()); sb.append(" Attribute: "); sb.append(name.value()); sb.append(System.lineSeparator()); return SMFSchemaValidationError.of(sb.toString(), Optional.empty()); }
private boolean equalTo(SMFArrayAttributeMapping another) { return name.equals(another.name) && index == another.index && Objects.equals(componentType, another.componentType) && componentCount == another.componentCount; }
/** * Computes a hash code from attributes: {@code name}, {@code index}, {@code componentType}, {@code componentCount}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + name.hashCode(); h += (h << 5) + index; h += (h << 5) + Objects.hashCode(componentType); h += (h << 5) + componentCount; return h; }
/** * Construct a new immutable {@code SMFAttributeName} instance. * @param value The value for the {@code value} attribute * @return An immutable SMFAttributeName instance */ public static SMFAttributeName of(String value) { return validate(new SMFAttributeName(value)); }
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)))); } }
/** * Builds a new {@link SMFAttributeName SMFAttributeName}. * @return An immutable instance of SMFAttributeName * @throws java.lang.IllegalStateException if any required attributes are missing */ public SMFAttributeName build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return SMFAttributeName.validate(new SMFAttributeName(null, value)); }
private static SMFAttributeName validate(SMFAttributeName instance) { instance.checkPreconditions(); return instance; }
/** * Creates an immutable copy of a {@link SMFAttributeNameType} 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 SMFAttributeName instance */ public static SMFAttributeName copyOf(SMFAttributeNameType instance) { if (instance instanceof SMFAttributeName) { return (SMFAttributeName) instance; } return SMFAttributeName.builder() .from(instance) .build(); }
@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(); }
/** * Construct a new immutable {@code SMFAttributeName} instance. * @param value The value for the {@code value} attribute * @return An immutable SMFAttributeName instance */ public static SMFAttributeName of(String value) { return validate(new SMFAttributeName(value)); }
/** * Builds a new {@link SMFAttributeName SMFAttributeName}. * @return An immutable instance of SMFAttributeName * @throws java.lang.IllegalStateException if any required attributes are missing */ public SMFAttributeName build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return SMFAttributeName.validate(new SMFAttributeName(null, value)); }
private static SMFAttributeName validate(SMFAttributeName instance) { instance.checkPreconditions(); return instance; }
/** * Creates an immutable copy of a {@link SMFAttributeNameType} 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 SMFAttributeName instance */ public static SMFAttributeName copyOf(SMFAttributeNameType instance) { if (instance instanceof SMFAttributeName) { return (SMFAttributeName) instance; } return SMFAttributeName.builder() .from(instance) .build(); }
private static SMFSchemaValidationError errorMissingAttribute( final SMFAttributeName name) { final StringBuilder sb = new StringBuilder(128); sb.append("A required attribute is missing."); sb.append(System.lineSeparator()); sb.append(" Attribute: "); sb.append(name.value()); sb.append(System.lineSeparator()); return SMFSchemaValidationError.of(sb.toString(), Optional.empty()); }
name = SMFAttributeName.of(line.get(1)); } catch (final IllegalArgumentException e) { super.failExpectedGot(
private boolean equalTo(SMFSchemaAttribute another) { return name.equals(another.name) && Objects.equals(requiredComponentType, another.requiredComponentType) && Objects.equals(requiredComponentCount, another.requiredComponentCount) && Objects.equals(requiredComponentSize, another.requiredComponentSize); }
/** * Computes a hash code from attributes: {@code name}, {@code componentType}, {@code componentCount}, {@code componentSize}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + name.hashCode(); h += (h << 5) + Objects.hashCode(componentType); h += (h << 5) + Objects.hashCode(componentCount); h += (h << 5) + Objects.hashCode(componentSize); return h; }
/** * Copy the current immutable object by setting a value for the {@link SMFAttributeNameType#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 SMFAttributeName withValue(String value) { if (this.value.equals(value)) return this; String newValue = Objects.requireNonNull(value, "value"); return validate(new SMFAttributeName(this, newValue)); }
private static SMFSchemaValidationError errorWrongComponentSize( final SMFAttributeName name, final int expected, final int received) { final StringBuilder sb = new StringBuilder(128); sb.append("Attribute component size is not the expected size."); sb.append(System.lineSeparator()); sb.append(" Attribute: "); sb.append(name.value()); sb.append(System.lineSeparator()); sb.append(" Expected: "); sb.append(expected); sb.append(System.lineSeparator()); sb.append(" Received: "); sb.append(received); sb.append(System.lineSeparator()); return SMFSchemaValidationError.of(sb.toString(), Optional.empty()); }
@Test public void testMisfiled() { final SMFArrayAttributeMapping m0 = SMFArrayAttributeMapping.of( SMFAttributeName.of("a"), 0, Optional.of(JCGLScalarType.TYPE_FLOAT), 4); this.expected.expect(IllegalArgumentException.class); SMFArrayObjectConfiguration.builder() .setMappings(HashMap.of(SMFAttributeName.of("b"), m0)) .build(); }