at.newmedialab.ldpath.model.selectors.StringConstantSelector Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ldpath-core-bundle Show documentation
Show all versions of ldpath-core-bundle Show documentation
Core Implementation of LD Path a simple path-based query language similar to XPath or SPARQL Property Paths that is particularly well-suited for querying and retrieving resources from the Linked Data Cloud by following RDF links between resources and servers.
/*
* Copyright (c) 2011 Salzburg Research.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package at.newmedialab.ldpath.model.selectors;
import at.newmedialab.ldpath.api.backend.RDFBackend;
import at.newmedialab.ldpath.api.selectors.NodeSelector;
import java.util.Collection;
import java.util.Collections;
/**
* Add file description here!
*
* Author: Sebastian Schaffert
*/
public class StringConstantSelector implements NodeSelector {
private String constant;
public StringConstantSelector(String constant) {
this.constant = constant;
}
/**
* Apply the selector to the context node passed as argument and return the collection
* of selected nodes in appropriate order.
*
* @param context the node where to start the selection
* @return the collection of selected nodes
*/
@Override
public Collection select(RDFBackend rdfBackend, Node context) {
return Collections.singleton(rdfBackend.createLiteral(constant));
}
/**
* Return the name of the NodeSelector for registration in the selector registry
*
* @param rdfBackend
* @return
*/
@Override
public String getPathExpression(RDFBackend rdfBackend) {
return String.format("\"%s\"", constant);
}
/**
* Return a name for this selector to be used as the name for the whole path if not explicitly
* specified. In complex selector expressions, this is typically delegated to the first
* occurrence of an atomic selector.
*/
@Override
public String getName(RDFBackend nodeRDFBackend) {
return constant;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
StringConstantSelector that = (StringConstantSelector) o;
if (constant != null ? !constant.equals(that.constant) : that.constant != null) return false;
return true;
}
@Override
public int hashCode() {
return constant != null ? constant.hashCode() : 0;
}
}