org.eclipse.rdf4j.model.impl.SimpleNamespace Java Examples

The following examples show how to use org.eclipse.rdf4j.model.impl.SimpleNamespace. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ElasticsearchNamespaceStore.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public Iterator<SimpleNamespace> iterator() {

	SearchResponse searchResponse = clientProvider.getClient()
			.prepareSearch(index)
			.addSort(FieldSortBuilder.DOC_FIELD_NAME, SortOrder.ASC)
			.setQuery(QueryBuilders.constantScoreQuery(matchAllQuery()))
			.setSize(10000)
			.get();

	SearchHits hits = searchResponse.getHits();
	if (hits.totalHits > 10000) {
		throw new SailException("Namespace store only supports 10 000 items, found " + hits.totalHits);
	}

	return StreamSupport.stream(hits.spliterator(), false)
			.map(SearchHit::getSourceAsMap)
			.map(map -> new SimpleNamespace(map.get(PREFIX).toString(), map.get(NAMESPACE).toString()))
			.iterator();

}
 
Example #2
Source File: NamespacesTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Test method for {@link org.eclipse.rdf4j.model.util.Namespaces#asMap(java.util.Set)}.
 */
@Test
public final void testAsMapMultiple() {
	Set<Namespace> input = new HashSet<>();
	input.add(new SimpleNamespace(RDF.PREFIX, RDF.NAMESPACE));
	input.add(new SimpleNamespace(RDFS.PREFIX, RDFS.NAMESPACE));
	input.add(new SimpleNamespace(DC.PREFIX, DC.NAMESPACE));
	input.add(new SimpleNamespace(SKOS.PREFIX, SKOS.NAMESPACE));
	input.add(new SimpleNamespace(SESAME.PREFIX, SESAME.NAMESPACE));

	Map<String, String> map = Namespaces.asMap(input);

	assertFalse(map.isEmpty());
	assertEquals(5, map.size());

	assertTrue(map.containsKey(RDF.PREFIX));
	assertEquals(RDF.NAMESPACE, map.get(RDF.PREFIX));
	assertTrue(map.containsKey(RDFS.PREFIX));
	assertEquals(RDFS.NAMESPACE, map.get(RDFS.PREFIX));
	assertTrue(map.containsKey(DC.PREFIX));
	assertEquals(DC.NAMESPACE, map.get(DC.PREFIX));
	assertTrue(map.containsKey(SKOS.PREFIX));
	assertEquals(SKOS.NAMESPACE, map.get(SKOS.PREFIX));
	assertTrue(map.containsKey(SESAME.PREFIX));
	assertEquals(SESAME.NAMESPACE, map.get(SESAME.PREFIX));
}
 
Example #3
Source File: NamespacesTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Test method for {@link org.eclipse.rdf4j.model.util.Namespaces#wrap(java.util.Set)}.
 */
@Test
public final void testWrapClear() throws Exception {
	Set<Namespace> testSet = new LinkedHashSet<>();
	Map<String, String> testMap = Namespaces.wrap(testSet);
	// Check no exceptions when calling clear on empty backing set
	testMap.clear();

	testSet.add(new SimpleNamespace(testPrefix1, testName1));

	assertFalse(testMap.isEmpty());
	assertEquals(1, testMap.size());

	testMap.clear();

	assertTrue(testMap.isEmpty());
	assertEquals(0, testMap.size());
}
 
Example #4
Source File: NamespacesTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Test method for {@link org.eclipse.rdf4j.model.util.Namespaces#wrap(java.util.Set)}.
 */
@Test
public final void testWrapContainsKey() throws Exception {
	Set<Namespace> testSet = new LinkedHashSet<>();
	Map<String, String> testMap = Namespaces.wrap(testSet);
	// Check no exceptions when calling containsKey on empty backing set
	assertFalse(testMap.containsKey(testPrefix1));

	testSet.add(new SimpleNamespace(testPrefix1, testName1));

	assertTrue(testMap.containsKey(testPrefix1));

	testSet.clear();

	assertFalse(testMap.containsKey(testPrefix1));
}
 
Example #5
Source File: NamespacesTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Test method for {@link org.eclipse.rdf4j.model.util.Namespaces#wrap(java.util.Set)}.
 */
@Test
public final void testWrapContainsValue() throws Exception {
	Set<Namespace> testSet = new LinkedHashSet<>();
	Map<String, String> testMap = Namespaces.wrap(testSet);
	// Check no exceptions when calling containsKey on empty backing set
	assertFalse(testMap.containsValue(testName1));

	testSet.add(new SimpleNamespace(testPrefix1, testName1));

	assertTrue(testMap.containsValue(testName1));

	testSet.clear();

	assertFalse(testMap.containsValue(testName1));
}
 
Example #6
Source File: NamespacesTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Test method for {@link org.eclipse.rdf4j.model.util.Namespaces#wrap(java.util.Set)}.
 */
@Test
public final void testWrapEntrySet() throws Exception {
	Set<Namespace> testSet = new LinkedHashSet<>();
	Map<String, String> testMap = Namespaces.wrap(testSet);

	Set<Entry<String, String>> entrySet1 = testMap.entrySet();
	assertNotNull(entrySet1);
	assertTrue(entrySet1.isEmpty());

	testSet.add(new SimpleNamespace(testPrefix1, testName1));

	Set<Entry<String, String>> entrySet2 = testMap.entrySet();
	assertNotNull(entrySet2);
	assertFalse(entrySet2.isEmpty());
	assertEquals(1, entrySet2.size());
	Entry<String, String> nextEntry = entrySet2.iterator().next();
	assertEquals(testPrefix1, nextEntry.getKey());
	assertEquals(testName1, nextEntry.getValue());

	testSet.clear();

	Set<Entry<String, String>> entrySet3 = testMap.entrySet();
	assertNotNull(entrySet3);
	assertTrue(entrySet3.isEmpty());
}
 
Example #7
Source File: HTTPRepositoryConnection.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public RepositoryResult<Namespace> getNamespaces() throws RepositoryException {
	try {
		List<Namespace> namespaceList = new ArrayList<>();

		try (TupleQueryResult namespaces = client.getNamespaces()) {
			while (namespaces.hasNext()) {
				BindingSet bindingSet = namespaces.next();
				Value prefix = bindingSet.getValue("prefix");
				Value namespace = bindingSet.getValue("namespace");

				if (prefix instanceof Literal && namespace instanceof Literal) {
					String prefixStr = ((Literal) prefix).getLabel();
					String namespaceStr = ((Literal) namespace).getLabel();
					namespaceList.add(new SimpleNamespace(prefixStr, namespaceStr));
				}
			}
		}

		return createRepositoryResult(namespaceList);
	} catch (QueryEvaluationException | IOException e) {
		throw new RepositoryException(e);
	}
}
 
Example #8
Source File: NamespacesTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Test method for {@link org.eclipse.rdf4j.model.util.Namespaces#wrap(java.util.Set)}.
 */
@Test
public final void testWrapKeySet() throws Exception {
	Set<Namespace> testSet = new LinkedHashSet<>();
	Map<String, String> testMap = Namespaces.wrap(testSet);

	Set<String> keySet1 = testMap.keySet();
	assertNotNull(keySet1);
	assertTrue(keySet1.isEmpty());

	testSet.add(new SimpleNamespace(testPrefix1, testName1));

	Set<String> keySet2 = testMap.keySet();
	assertNotNull(keySet2);
	assertFalse(keySet2.isEmpty());
	assertEquals(1, keySet2.size());
	String nextKey = keySet2.iterator().next();
	assertEquals(testPrefix1, nextKey);

	testSet.clear();

	Set<String> keySet3 = testMap.keySet();
	assertNotNull(keySet3);
	assertTrue(keySet3.isEmpty());
}
 
Example #9
Source File: ProtocolTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Test for GitHub issue #262
 *
 * @throws Exception
 */
@Test
public void testPutEmptyPrefix() throws Exception {
	String repositoryLocation = TestServer.REPOSITORY_URL;
	String namespacesLocation = Protocol.getNamespacesLocation(repositoryLocation);
	String emptyPrefixLocation = Protocol.getNamespacePrefixLocation(repositoryLocation, "");

	Set<Namespace> namespacesBefore = getNamespaces(namespacesLocation);

	putNamespace(emptyPrefixLocation, "http://example.org/");

	Set<Namespace> namespacesAfter = getNamespaces(namespacesLocation);

	Set<Namespace> namespaceDeletions = Sets.difference(namespacesBefore, namespacesAfter);
	Set<Namespace> namespaceAdditions = Sets.difference(namespacesAfter, namespacesBefore);

	assertTrue("Some namespaces have been deleted", namespaceDeletions.isEmpty());
	assertEquals(Sets.newHashSet(new SimpleNamespace("", "http://example.org/")), namespaceAdditions);
}
 
Example #10
Source File: NamespacesTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Test method for {@link org.eclipse.rdf4j.model.util.Namespaces#wrap(java.util.Set)}.
 */
@Test
public final void testWrapValues() throws Exception {
	Set<Namespace> testSet = new LinkedHashSet<>();
	Map<String, String> testMap = Namespaces.wrap(testSet);

	Collection<String> values1 = testMap.values();
	assertNotNull(values1);
	assertTrue(values1.isEmpty());

	testSet.add(new SimpleNamespace(testPrefix1, testName1));

	Collection<String> values2 = testMap.values();
	assertNotNull(values2);
	assertFalse(values2.isEmpty());
	assertEquals(1, values2.size());
	String nextValue = values2.iterator().next();
	assertEquals(testName1, nextValue);

	testSet.clear();

	Collection<String> values3 = testMap.values();
	assertNotNull(values3);
	assertTrue(values3.isEmpty());
}
 
Example #11
Source File: ModelNamespacesTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Test method for {@link org.eclipse.rdf4j.model.Model#removeNamespace(java.lang.String)}.
 */
@Test
public final void testRemoveNamespaceSingle() {
	testModel.setNamespace(DC.PREFIX, DC.NAMESPACE);

	Set<Namespace> namespaces = testModel.getNamespaces();

	assertNotNull("Namespaces set must not be null", namespaces);
	assertFalse(namespaces.isEmpty());
	assertEquals(1, namespaces.size());

	assertTrue("Did not find the expected namespace in the set",
			namespaces.contains(new SimpleNamespace(DC.PREFIX, DC.NAMESPACE)));

	assertFalse(testModel.removeNamespace(RDF.NAMESPACE).isPresent());
	assertFalse(testModel.removeNamespace(RDFS.NAMESPACE).isPresent());
	assertEquals(new SimpleNamespace(DC.PREFIX, DC.NAMESPACE), testModel.removeNamespace(DC.PREFIX).get());
	assertFalse(testModel.removeNamespace(SKOS.NAMESPACE).isPresent());
	assertFalse(testModel.removeNamespace(SESAME.NAMESPACE).isPresent());

	Set<Namespace> namespacesAfter = testModel.getNamespaces();

	assertNotNull("Namespaces set must not be null", namespacesAfter);
	assertTrue("Namespaces must now be empty", namespacesAfter.isEmpty());
}
 
Example #12
Source File: HBaseSail.java    From Halyard with Apache License 2.0 6 votes vote down vote up
@Override
public void initialize() throws SailException { //initialize the SAIL
    try {
    	    //get or create and get the HBase table
        table = HalyardTableUtils.getTable(config, tableName, create, splitBits);

        //Iterate over statements relating to namespaces and add them to the namespace map.
        try (CloseableIteration<? extends Statement, SailException> nsIter = getStatements(null, HALYARD.NAMESPACE_PREFIX_PROPERTY, null, true)) {
            while (nsIter.hasNext()) {
                Statement st = nsIter.next();
                if (st.getObject() instanceof Literal) {
                    String prefix = st.getObject().stringValue();
                    String name = st.getSubject().stringValue();
                    namespaces.put(prefix, new SimpleNamespace(prefix, name));
                }
            }
        }
    } catch (IOException ex) {
        throw new SailException(ex);
    }
}
 
Example #13
Source File: ModelNamespacesTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Test method for {@link org.eclipse.rdf4j.model.Model#setNamespace(org.eclipse.rdf4j.model.Namespace)}.
 */
@Test
public final void testSetNamespaceNamespace() {
	testModel.setNamespace(new SimpleNamespace(RDF.PREFIX, RDF.NAMESPACE));
	testModel.setNamespace(new SimpleNamespace(RDFS.PREFIX, RDFS.NAMESPACE));
	testModel.setNamespace(new SimpleNamespace(DC.PREFIX, DC.NAMESPACE));
	testModel.setNamespace(new SimpleNamespace(SKOS.PREFIX, SKOS.NAMESPACE));
	testModel.setNamespace(new SimpleNamespace(SESAME.PREFIX, SESAME.NAMESPACE));

	Set<Namespace> namespaces = testModel.getNamespaces();

	assertNotNull("Namespaces set must not be null", namespaces);
	assertFalse(namespaces.isEmpty());
	assertEquals(5, namespaces.size());

	assertEquals(new SimpleNamespace(RDF.PREFIX, RDF.NAMESPACE), testModel.getNamespace(RDF.PREFIX).get());
	assertEquals(new SimpleNamespace(RDFS.PREFIX, RDFS.NAMESPACE), testModel.getNamespace(RDFS.PREFIX).get());
	assertEquals(new SimpleNamespace(DC.PREFIX, DC.NAMESPACE), testModel.getNamespace(DC.PREFIX).get());
	assertEquals(new SimpleNamespace(SKOS.PREFIX, SKOS.NAMESPACE), testModel.getNamespace(SKOS.PREFIX).get());
	assertEquals(new SimpleNamespace(SESAME.PREFIX, SESAME.NAMESPACE), testModel.getNamespace(SESAME.PREFIX).get());
}
 
Example #14
Source File: ModelNamespacesTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Test method for {@link org.eclipse.rdf4j.model.Model#getNamespace(java.lang.String)}.
 */
@Test
public final void testGetNamespaceMultiple() {
	testModel.setNamespace(RDF.PREFIX, RDF.NAMESPACE);
	testModel.setNamespace(RDFS.PREFIX, RDFS.NAMESPACE);
	testModel.setNamespace(DC.PREFIX, DC.NAMESPACE);
	testModel.setNamespace(SKOS.PREFIX, SKOS.NAMESPACE);
	testModel.setNamespace(SESAME.PREFIX, SESAME.NAMESPACE);

	Set<Namespace> namespaces = testModel.getNamespaces();

	assertNotNull("Namespaces set must not be null", namespaces);
	assertFalse(namespaces.isEmpty());
	assertEquals(5, namespaces.size());

	assertEquals(new SimpleNamespace(RDF.PREFIX, RDF.NAMESPACE), testModel.getNamespace(RDF.PREFIX).get());
	assertEquals(new SimpleNamespace(RDFS.PREFIX, RDFS.NAMESPACE), testModel.getNamespace(RDFS.PREFIX).get());
	assertEquals(new SimpleNamespace(DC.PREFIX, DC.NAMESPACE), testModel.getNamespace(DC.PREFIX).get());
	assertEquals(new SimpleNamespace(SKOS.PREFIX, SKOS.NAMESPACE), testModel.getNamespace(SKOS.PREFIX).get());
	assertEquals(new SimpleNamespace(SESAME.PREFIX, SESAME.NAMESPACE), testModel.getNamespace(SESAME.PREFIX).get());
}
 
Example #15
Source File: ModelNamespacesTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Test method for {@link org.eclipse.rdf4j.model.Model#getNamespace(java.lang.String)}.
 */
@Test
public final void testGetNamespaceSingle() {
	testModel.setNamespace(RDFS.PREFIX, RDFS.NAMESPACE);

	Set<Namespace> namespaces = testModel.getNamespaces();

	assertNotNull("Namespaces set must not be null", namespaces);
	assertFalse(namespaces.isEmpty());
	assertEquals(1, namespaces.size());

	assertTrue("Did not find the expected namespace in the set",
			namespaces.contains(new SimpleNamespace(RDFS.PREFIX, RDFS.NAMESPACE)));

	assertFalse(testModel.getNamespace(RDF.PREFIX).isPresent());
	assertEquals(new SimpleNamespace(RDFS.PREFIX, RDFS.NAMESPACE), testModel.getNamespace(RDFS.PREFIX).get());
	assertFalse(testModel.getNamespace(DC.PREFIX).isPresent());
	assertFalse(testModel.getNamespace(SKOS.PREFIX).isPresent());
	assertFalse(testModel.getNamespace(SESAME.PREFIX).isPresent());
}
 
Example #16
Source File: ModelNamespacesTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Test method for {@link org.eclipse.rdf4j.model.Model#getNamespaces()}.
 */
@Test
public final void testGetNamespacesMultiple() {
	testModel.setNamespace(RDF.PREFIX, RDF.NAMESPACE);
	testModel.setNamespace(RDFS.PREFIX, RDFS.NAMESPACE);
	testModel.setNamespace(DC.PREFIX, DC.NAMESPACE);
	testModel.setNamespace(SKOS.PREFIX, SKOS.NAMESPACE);
	testModel.setNamespace(SESAME.PREFIX, SESAME.NAMESPACE);

	Set<Namespace> namespaces = testModel.getNamespaces();

	assertNotNull("Namespaces set must not be null", namespaces);
	assertFalse(namespaces.isEmpty());
	assertEquals(5, namespaces.size());

	assertTrue(namespaces.contains(new SimpleNamespace(RDF.PREFIX, RDF.NAMESPACE)));
	assertTrue(namespaces.contains(new SimpleNamespace(RDFS.PREFIX, RDFS.NAMESPACE)));
	assertTrue(namespaces.contains(new SimpleNamespace(DC.PREFIX, DC.NAMESPACE)));
	assertTrue(namespaces.contains(new SimpleNamespace(SKOS.PREFIX, SKOS.NAMESPACE)));
	assertTrue(namespaces.contains(new SimpleNamespace(SESAME.PREFIX, SESAME.NAMESPACE)));
}
 
Example #17
Source File: SimpleMemoryNamespaceStore.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public String getNamespace(String prefix) {
	String result = null;
	SimpleNamespace namespace = namespacesMap.get(prefix);
	if (namespace != null) {
		result = namespace.getName();
	}
	return result;
}
 
Example #18
Source File: Model.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Sets the prefix for a namespace. This will replace any existing namespace associated to the prefix.
 *
 * @param prefix The new prefix.
 * @param name   The namespace name that the prefix maps to.
 * @return The {@link Namespace} object for the given namespace.
 */
public default Namespace setNamespace(String prefix, String name) {
	Optional<? extends Namespace> result = getNamespace(prefix);
	if (!result.isPresent() || !result.get().getName().equals(name)) {
		result = Optional.of(new SimpleNamespace(prefix, name));
		setNamespace(result.get());
	}
	return result.get();
}
 
Example #19
Source File: HBaseSail.java    From Halyard with Apache License 2.0 5 votes vote down vote up
@Override
public void setNamespace(String prefix, String name) throws SailException {
    namespaces.put(prefix, new SimpleNamespace(prefix, name));
    ValueFactory vf = getValueFactory();
    try {
        removeStatements(null, HALYARD.NAMESPACE_PREFIX_PROPERTY, vf.createLiteral(prefix));
        addStatementInternal(vf.createIRI(name), HALYARD.NAMESPACE_PREFIX_PROPERTY, vf.createLiteral(prefix), HALYARD.SYSTEM_GRAPH_CONTEXT, getDefaultTimeStamp());
    } catch (SailException e) {
        LOG.log(Level.WARNING, "Namespace prefix could not be presisted due to an exception", e);
    }
}
 
Example #20
Source File: NamespacesTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Test method for {@link org.eclipse.rdf4j.model.util.Namespaces#asMap(java.util.Set)}.
 */
@Test
public final void testAsMapOne() {
	Set<Namespace> input = new HashSet<>();
	input.add(new SimpleNamespace(RDF.PREFIX, RDF.NAMESPACE));

	Map<String, String> map = Namespaces.asMap(input);

	assertFalse(map.isEmpty());
	assertEquals(1, map.size());

	assertTrue(map.containsKey(RDF.PREFIX));
	assertEquals(RDF.NAMESPACE, map.get(RDF.PREFIX));
}
 
Example #21
Source File: NamespacesTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Test method for {@link org.eclipse.rdf4j.model.util.Namespaces#wrap(java.util.Set)}.
 */
@Test
public final void testWrapGet() throws Exception {
	Set<Namespace> testSet = new LinkedHashSet<>();
	Map<String, String> testMap = Namespaces.wrap(testSet);
	assertNull(testMap.get(testPrefix1));

	testSet.add(new SimpleNamespace(testPrefix1, testName1));
	assertEquals(testName1, testMap.get(testPrefix1));

	testSet.clear();
	assertNull(testMap.get(testPrefix1));
}
 
Example #22
Source File: NamespacesTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Test method for {@link org.eclipse.rdf4j.model.util.Namespaces#wrap(java.util.Set)}.
 */
@Test
public final void testWrapIsEmpty() throws Exception {
	Set<Namespace> testSet = new LinkedHashSet<>();
	Map<String, String> testMap = Namespaces.wrap(testSet);
	assertTrue(testMap.isEmpty());

	testSet.add(new SimpleNamespace(testPrefix1, testName1));
	assertFalse(testMap.isEmpty());

	testSet.clear();
	assertTrue(testMap.isEmpty());
}
 
Example #23
Source File: NamespacesTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Test method for {@link org.eclipse.rdf4j.model.util.Namespaces#wrap(java.util.Set)}.
 */
@Test
public final void testWrapPut() throws Exception {
	Set<Namespace> testSet = new LinkedHashSet<>();
	Map<String, String> testMap = Namespaces.wrap(testSet);

	String put1 = testMap.put(testPrefix1, testName1);
	assertNull("Should have returned null from put on an empty backing set", put1);
	assertEquals(1, testSet.size());
	assertTrue(testSet.contains(new SimpleNamespace(testPrefix1, testName1)));
	assertTrue(testMap.containsKey(testPrefix1));
	assertTrue(testMap.containsValue(testName1));

	String put2 = testMap.put(testPrefix1, testName2);
	assertEquals(put2, testName1);
	// Size should be one at this point as original should have been replaced.
	assertEquals(1, testSet.size());
	assertTrue(testSet.contains(new SimpleNamespace(testPrefix1, testName2)));
	assertTrue(testMap.containsKey(testPrefix1));
	assertFalse(testMap.containsValue(testName1));
	assertTrue(testMap.containsValue(testName2));

	testSet.clear();

	assertTrue(testMap.isEmpty());
	assertEquals(0, testMap.size());
	assertFalse(testMap.containsKey(testPrefix1));
	assertFalse(testMap.containsValue(testName1));
	assertFalse(testMap.containsValue(testName2));

	String put3 = testMap.put(testPrefix1, testName1);
	assertNull("Should have returned null from put on an empty backing set", put3);
	assertEquals(1, testSet.size());
	assertTrue(testSet.contains(new SimpleNamespace(testPrefix1, testName1)));
	assertTrue(testMap.containsKey(testPrefix1));
	assertTrue(testMap.containsValue(testName1));
}
 
Example #24
Source File: ModelNamespacesTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Test method for {@link org.eclipse.rdf4j.model.Model#getNamespaces()}.
 */
@Test
public final void testGetNamespacesSingle() {
	testModel.setNamespace(RDF.PREFIX, RDF.NAMESPACE);

	Set<Namespace> namespaces = testModel.getNamespaces();

	assertNotNull("Namespaces set must not be null", namespaces);
	assertFalse(namespaces.isEmpty());
	assertEquals(1, namespaces.size());

	assertTrue("Did not find the expected namespace in the set",
			namespaces.contains(new SimpleNamespace(RDF.PREFIX, RDF.NAMESPACE)));
}
 
Example #25
Source File: SailSourceModel.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Namespace setNamespace(String prefix, String name) {
	try {
		sink().setNamespace(prefix, name);
	} catch (SailException e) {
		throw new ModelException(e);
	}
	return new SimpleNamespace(prefix, name);
}
 
Example #26
Source File: Prefixes.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Set a namespace from a string, using one whitespace to separate prefix and namespace URI E.g. 'dcterms
 * http://purl.org/dc/terms/'
 *
 * @param namespace
 */
private void setNamespace(String namespace) {
	String[] parts = namespace.split(" ");
	if (parts.length != 2) {
		throw new IllegalArgumentException("Error parsing namespace: " + namespace);
	}
	if (parts[1].equals("<none>")) {
		clearNamespace(parts[0]);
		return;
	}
	if (!URIUtil.isValidURIReference(parts[1])) {
		throw new IllegalArgumentException("Error parsing namespace URI: " + parts[1]);
	}
	get().add(new SimpleNamespace(parts[0], parts[1]));
}
 
Example #27
Source File: NamespaceStore.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public String getNamespace(String prefix) {
	String result = null;
	SimpleNamespace namespace = namespacesMap.get(prefix);
	if (namespace != null) {
		result = namespace.getName();
	}
	return result;
}
 
Example #28
Source File: NamespaceStore.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void setNamespace(String prefix, String name) {
	SimpleNamespace ns = namespacesMap.get(prefix);

	if (ns != null) {
		if (!ns.getName().equals(name)) {
			ns.setName(name);
			contentsChanged = true;
		}
	} else {
		namespacesMap.put(prefix, new SimpleNamespace(prefix, name));
		contentsChanged = true;
	}
}
 
Example #29
Source File: NamespaceStore.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void removeNamespace(String prefix) {
	SimpleNamespace ns = namespacesMap.remove(prefix);

	if (ns != null) {
		contentsChanged = true;
	}
}
 
Example #30
Source File: SailModel.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Namespace setNamespace(String prefix, String name) {
	try {
		conn.setNamespace(prefix, name);
	} catch (SailException e) {
		throw new ModelException(e);
	}
	return new SimpleNamespace(prefix, name);
}