/** * Makes a copy of the command text and optionally copies other aspects * * @param copyParams * Whether to copy parameters * @param copyBase * Whether to copy the Base URI * @param copyPrefixes * Whether to copy the prefix mappings * @return Copy of the string */ public ParameterizedSparqlString copy(boolean copyParams, boolean copyBase, boolean copyPrefixes) { ParameterizedSparqlString copy = new ParameterizedSparqlString(this.cmd.toString(), null, (copyBase ? this.baseUri : null), (copyPrefixes ? this.prefixes : null)); if (copyParams) { Iterator<String> vars = this.getVars(); while (vars.hasNext()) { String var = vars.next(); copy.setParam(var, this.getParam(var)); } for (Entry<Integer, Node> entry : this.positionalParams.entrySet()) { copy.setParam(entry.getKey(), entry.getValue()); } } return copy; }
@Test public void test_param_string_copy_2() { // Test copying - copying and changing a parameter changes only one // instance ParameterizedSparqlString query = new ParameterizedSparqlString(); query.setIri("x", "http://example.org/original"); ParameterizedSparqlString copy = query.copy(); copy.setIri("x", "http://example.org/copy"); Assert.assertEquals("http://example.org/original", query.getParam("x").toString()); Assert.assertFalse("http://example.org/copy".equals(query.getParam("x").toString())); Assert.assertEquals("http://example.org/copy", copy.getParam("x").toString()); Assert.assertFalse("http://example.org/original".equals(copy.getParam("x").toString())); }
@Test public void test_param_string_copy_7() { // Test copying - copying and changing a parameter changes only one // instance ParameterizedSparqlString query = new ParameterizedSparqlString(); query.setIri(0, "http://example.org/original"); ParameterizedSparqlString copy = query.copy(); copy.setIri(0, "http://example.org/copy"); Assert.assertEquals("http://example.org/original", query.getParam(0).toString()); Assert.assertFalse("http://example.org/copy".equals(query.getParam(0).toString())); Assert.assertEquals("http://example.org/copy", copy.getParam(0).toString()); Assert.assertFalse("http://example.org/original".equals(copy.getParam(0).toString())); }
@Test public void test_param_string_copy_5() { // Test selective copying - copying without copying parameters ParameterizedSparqlString query = new ParameterizedSparqlString(); query.setIri("x", "http://example.org/original"); ParameterizedSparqlString copy = query.copy(false); Assert.assertEquals("http://example.org/original", query.getParam("x").toString()); Assert.assertEquals(null, copy.getParam("x")); }
@Test public void test_param_string_copy_8() { // Test selective copying - copying without copying parameters ParameterizedSparqlString query = new ParameterizedSparqlString(); query.setIri(0, "http://example.org/original"); ParameterizedSparqlString copy = query.copy(false); Assert.assertEquals("http://example.org/original", query.getParam(0).toString()); Assert.assertEquals(null, copy.getParam(0)); }
@Test public void test_param_string_constructor_6() { // Test constructor with predefined parameters QuerySolutionMap map = new QuerySolutionMap(); Resource r = ResourceFactory.createResource("http://example.org"); map.add("s", r); Literal l = ResourceFactory.createPlainLiteral("example"); map.add("o", l); ParameterizedSparqlString query = new ParameterizedSparqlString("", map); Assert.assertEquals(r.asNode(), query.getParam("s")); Assert.assertEquals(l.asNode(), query.getParam("o")); }
@Test public void test_param_string_constructor_7() { // Test constructor with predefined parameters - variant of constructor // that does not require command text QuerySolutionMap map = new QuerySolutionMap(); Resource r = ResourceFactory.createResource("http://example.org"); map.add("s", r); Literal l = ResourceFactory.createPlainLiteral("example"); map.add("o", l); ParameterizedSparqlString query = new ParameterizedSparqlString(map); Assert.assertEquals(r.asNode(), query.getParam("s")); Assert.assertEquals(l.asNode(), query.getParam("o")); }
@Test public void test_param_string_constructor_4() { // Test constructor with predefined parameters QuerySolutionMap map = new QuerySolutionMap(); Resource r = ResourceFactory.createResource("http://example.org"); map.add("s", r); ParameterizedSparqlString query = new ParameterizedSparqlString("", map); Assert.assertEquals(r.asNode(), query.getParam("s")); }
@Test public void test_param_string_constructor_5() { // Test constructor with predefined parameters - variant of constructor // that does not require command text QuerySolutionMap map = new QuerySolutionMap(); Resource r = ResourceFactory.createResource("http://example.org"); map.add("s", r); ParameterizedSparqlString query = new ParameterizedSparqlString(map); Assert.assertEquals(r.asNode(), query.getParam("s")); }