/** * Copy the current immutable object by setting a value for the {@link SMFAttributeType#componentCount() componentCount} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for componentCount * @return A modified copy of the {@code this} object */ public final SMFAttribute withComponentCount(int value) { if (this.componentCount == value) return this; return validate(new SMFAttribute(this, this.name, this.componentType, value, this.componentSizeBits)); }
private static SMFAttribute validate(SMFAttribute instance) { instance.checkPreconditions(); return instance; }
/** * This instance is equal to all instances of {@code SMFAttribute} 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 SMFAttribute && equalTo((SMFAttribute) another); }
a -> "Packed attribute must exist in configuration"); Preconditions.checkPreconditionI( attr.componentCount(), attr.componentCount() == 4, n -> "Attribute must have 4 components"); Preconditions.checkPrecondition( attr.componentType(), attr.componentType() == SMFComponentType.ELEMENT_TYPE_INTEGER_SIGNED, n -> "Attribute must be of a signed integer type"); packed_attr.attribute().componentSizeBits(), packed_attr.offsetOctets(), config.vertexSizeOctets());
size_ok = this.config.componentSize().getAsInt() == attr.componentSizeBits(); count_ok = this.config.componentCount().getAsInt() == attr.componentCount(); type_ok = this.config.componentType().get() == attr.componentType(); String.format( "An attribute '%s' with %d components of type %s with size %d", attr.name().value(), Integer.valueOf(attr.componentCount()), attr.componentType().getName(), Integer.valueOf(attr.componentSizeBits()))));
if (a.componentType() == type && a.componentCount() == count) { return; sb.append(System.lineSeparator()); sb.append(" Attribute: "); sb.append(a.name().value()); sb.append(System.lineSeparator()); sb.append(" Attribute type: "); sb.append(a.componentCount()); sb.append(" components of type "); sb.append(a.componentType().name()); sb.append(System.lineSeparator()); sb.append(" Received: ");
@Override public void onDataAttributeStart( final SMFAttribute attribute) { final String name = attribute.name().value(); if (this.attributes_by_name.containsKey(name)) { final Attribute attr = this.attributes_by_name.get(name); this.packer = new SMFByteBufferPacker( this.array_update.getData(), attr.type, (int) attr.offset, this.vertex_size); } else { this.packer = null; } }
determineComponentType( required_attribute.componentType(), received_attribute.componentType()); new Attribute(received_attribute.componentCount(), decided); final Integer b_index = Integer.valueOf(required_attribute.index());
private static List<SMFErrorType> checkComponentCount( final List<SMFErrorType> errors, final SMFAttributeName name, final SMFSchemaAttribute attr_schema, final SMFAttribute attr) { final OptionalInt req_count_opt = attr_schema.requiredComponentCount(); if (req_count_opt.isPresent()) { final int req_count = req_count_opt.getAsInt(); if (attr.componentCount() != req_count) { return errors.append(errorWrongComponentCount( name, req_count, attr.componentCount())); } } return errors; }
private static List<SMFErrorType> checkComponentType( final List<SMFErrorType> errors, final SMFAttributeName name, final SMFSchemaAttribute attr_schema, final SMFAttribute attr) { final Optional<SMFComponentType> req_type_opt = attr_schema.requiredComponentType(); if (req_type_opt.isPresent()) { final SMFComponentType req_type = req_type_opt.get(); if (attr.componentType() != req_type) { return errors.append(errorWrongComponentType( name, req_type, attr.componentType())); } } return errors; }
private static List<SMFErrorType> checkComponentSize( final List<SMFErrorType> errors, final SMFAttributeName name, final SMFSchemaAttribute attr_schema, final SMFAttribute attr) { final OptionalInt req_size_opt = attr_schema.requiredComponentSize(); if (req_size_opt.isPresent()) { final int req_size = req_size_opt.getAsInt(); if (attr.componentSizeBits() != req_size) { return errors.append(errorWrongComponentSize( name, req_size, attr.componentSizeBits())); } } return errors; }
/** * Builds a new {@link SMFAttribute SMFAttribute}. * @return An immutable instance of SMFAttribute * @throws java.lang.IllegalStateException if any required attributes are missing */ public SMFAttribute build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return SMFAttribute.validate(new SMFAttribute(null, name, componentType, componentCount, componentSizeBits)); }
/** * Creates an immutable copy of a {@link SMFAttributeType} 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 SMFAttribute instance */ public static SMFAttribute copyOf(SMFAttributeType instance) { if (instance instanceof SMFAttribute) { return (SMFAttribute) instance; } return SMFAttribute.builder() .from(instance) .build(); }
a -> "Packed attribute must exist in configuration"); Preconditions.checkPreconditionI( attr.componentCount(), attr.componentCount() == 3, n -> "Attribute must have 3 components"); Preconditions.checkPrecondition( attr.componentType(), attr.componentType() == SMFComponentType.ELEMENT_TYPE_INTEGER_SIGNED, n -> "Attribute must be of a signed integer type"); packed_attr.attribute().componentSizeBits(), packed_attr.offsetOctets(), config.vertexSizeOctets());
String.format( "attribute \"%s\" %s %s %s", attribute.name().value(), attribute.componentType().getName(), Long.toUnsignedString((long) attribute.componentCount()), Long.toUnsignedString((long) attribute.componentSizeBits()))); this.writer.newLine();
switch (this.attribute_current.componentType()) { case ELEMENT_TYPE_INTEGER_SIGNED: { switch (this.attribute_current.componentCount()) { case 4: { this.arrays = this.arrays.put( this.attribute_current.name(), SMFAttributeArrayIntegerSigned4.builder() .setValues(this.elements.map(x -> (Vector4L) x)) this.attribute_current.name(), SMFAttributeArrayIntegerSigned3.builder() .setValues(this.elements.map(x -> (Vector3L) x)) this.attribute_current.name(), SMFAttributeArrayIntegerSigned2.builder() .setValues(this.elements.map(x -> (Vector2L) x)) this.attribute_current.name(), SMFAttributeArrayIntegerSigned1.builder() .setValues(this.elements.map(x -> (Long) x)) switch (this.attribute_current.componentCount()) { case 4: { this.arrays = this.arrays.put( this.attribute_current.name(), SMFAttributeArrayIntegerUnsigned4.builder() .setValues(this.elements.map(x -> (Vector4L) x)) this.attribute_current.name(),
/** * @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; }
this.vertices = in_vertices; if (Long.compareUnsigned(in_vertices, 0L) > 0) { switch (attribute.componentType()) { case ELEMENT_TYPE_INTEGER_SIGNED: { switch (attribute.componentCount()) { case 1: { this.cursor_signed1 = SMFByteBufferCursors.createSigned1( switch (attribute.componentCount()) { case 1: { this.cursor_unsigned1 = SMFByteBufferCursors.createUnsigned1( switch (attribute.componentCount()) { case 1: { this.cursor_float1 = SMFByteBufferCursors.createFloat1(
/** * Builds a new {@link SMFAttribute SMFAttribute}. * @return An immutable instance of SMFAttribute * @throws java.lang.IllegalStateException if any required attributes are missing */ public SMFAttribute build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return SMFAttribute.validate(new SMFAttribute(null, name, componentType, componentCount, componentSizeBits)); }
/** * Creates an immutable copy of a {@link SMFAttributeType} 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 SMFAttribute instance */ public static SMFAttribute copyOf(SMFAttributeType instance) { if (instance instanceof SMFAttribute) { return (SMFAttribute) instance; } return SMFAttribute.builder() .from(instance) .build(); }