/** * <p> * Replace the value at the i'th position in the list with the given value. * If the list is too short to have an i'th element, throws a {@link * ListIndexException}. * </p> * * @param i The index into the list, from 0 * @param value The new value to associate with the i'th list element * @return The value that was previously at position i in the list * @exception ListIndexException if the list has fewer than (i + 1) * elements. */ @Override public RDFNode replace( int i, RDFNode value ) { if (s_checkValid) { checkValid(); } checkNotNil( "Tried to replace a value in the empty list" ); return findElement( false, i ).setHead( value ); }
/** * <p> * Replace the value at the i'th position in the list with the given value. * If the list is too short to have an i'th element, throws a {@link * ListIndexException}. * </p> * * @param i The index into the list, from 0 * @param value The new value to associate with the i'th list element * @return The value that was previously at position i in the list * @exception ListIndexException if the list has fewer than (i + 1) * elements. */ @Override public RDFNode replace( int i, RDFNode value ) { if (s_checkValid) { checkValid(); } checkNotNil( "Tried to replace a value in the empty list" ); return findElement( false, i ).setHead( value ); }
public void testSetHead() { final Resource root = model.createResource(TestList.NS + "root"); final Property p = model.createProperty(TestList.NS, "p"); // a list of the nil object, but not typed final Resource nil = RDF.nil; model.add(nil, RDF.type, RDF.List); final Resource list = model.createResource(); model.add(list, RDF.type, RDF.List); model.add(list, RDF.first, "fred"); model.add(list, RDF.rest, nil); model.add(root, p, list); final RDFList l1 = getListRoot(model); checkValid("sethead1", l1, true); Assert.assertEquals("List head should be 'fred'", "fred", ((Literal) l1.getHead()).getString()); l1.setHead(model.createTypedLiteral(42)); checkValid("sethead2", l1, true); Assert.assertEquals("List head should be '42'", 42, ((Literal) l1.getHead()).getInt()); }
public void testSetHead() { final Resource root = model.createResource(TestList.NS + "root"); final Property p = model.createProperty(TestList.NS, "p"); // a list of the nil object, but not typed final Resource nil = RDF.nil; model.add(nil, RDF.type, RDF.List); final Resource list = model.createResource(); model.add(list, RDF.type, RDF.List); model.add(list, RDF.first, "fred"); model.add(list, RDF.rest, nil); model.add(root, p, list); final RDFList l1 = getListRoot(model); checkValid("sethead1", l1, true); Assert.assertEquals("List head should be 'fred'", "fred", ((Literal) l1.getHead()).getString()); l1.setHead(model.createTypedLiteral(42)); checkValid("sethead2", l1, true); Assert.assertEquals("List head should be '42'", 42, ((Literal) l1.getHead()).getInt()); }