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)))); } }
@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(); }
name = SMFAttributeName.of(line.get(1)); } catch (final IllegalArgumentException e) { super.failExpectedGot(
@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(); }
try { final SMFAttributeName name = SMFAttributeName.of(line.get(1)); final SMFComponentType type = SMFComponentType.of(line.get(2));
final SMFAttributeName attr = SMFAttributeName.of(text.get(0));
/** * 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); }
@Test public void testMappings() { final SMFArrayAttributeMapping m0 = SMFArrayAttributeMapping.of( SMFAttributeName.of("a"), 0, Optional.of(JCGLScalarType.TYPE_FLOAT), 4); final SMFArrayAttributeMapping m1 = SMFArrayAttributeMapping.of( SMFAttributeName.of("b"), 1, Optional.of(JCGLScalarType.TYPE_FLOAT), 4); final SMFArrayObjectConfiguration m = SMFArrayObjectConfiguration.builder() .setMappings(HashMap.ofEntries(List.of( Tuple.of(SMFAttributeName.of("a"), m0), Tuple.of(SMFAttributeName.of("b"), m1)))) .setIndexBufferUsage(JCGLUsageHint.USAGE_DYNAMIC_COPY) .setArrayBufferUsage(JCGLUsageHint.USAGE_STREAM_READ) .build(); Assert.assertEquals(JCGLUsageHint.USAGE_DYNAMIC_COPY, m.indexBufferUsage()); Assert.assertEquals(JCGLUsageHint.USAGE_STREAM_READ, m.arrayBufferUsage()); Assert.assertEquals(m0, m.mappings().get(SMFAttributeName.of("a")).get()); Assert.assertEquals(m1, m.mappings().get(SMFAttributeName.of("b")).get()); Assert.assertEquals(2L, (long) m.mappings().size()); } }
/** * 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); }
/** * 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); }
.setComponentType(type) .setIndex(0) .setName(SMFAttributeName.of("x")) .build();