You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by og...@apache.org on 2011/05/13 17:29:21 UTC
svn commit: r1102791 [8/9] - in
/incubator/stanbol/trunk/entityhub/yard/solr/src:
main/java/org/apache/stanbol/entityhub/yard/solr/
main/java/org/apache/stanbol/entityhub/yard/solr/defaults/
main/java/org/apache/stanbol/entityhub/yard/solr/impl/ main/j...
Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/FieldMapper.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/FieldMapper.java?rev=1102791&r1=1102790&r2=1102791&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/FieldMapper.java (original)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/FieldMapper.java Fri May 13 15:29:20 2011
@@ -19,152 +19,175 @@ package org.apache.stanbol.entityhub.yar
import java.util.Collection;
import java.util.List;
-
/**
- * Implementations of this interface implement the mapping of logical field (as
- * represented by {@link IndexField}) to the actual field name(s) used to index
- * such values. <p>
- * Such mappings are needed for indexing as well as querying for information
- * within the full text index.<p>
- * Implementations of this class are NOT responsible for converting actual
- * values to there index representation. This is provided by the
- * {@link IndexValueFactory} that converts java object's to {@link IndexValue}
- * instances and vis versa. However this interface contains a convenience
- * method that allows to get the field names for a <code>List<String> path</code>
- * and a <code>IndexValue indexValue</code> because this is the most common task
- * while indexing data.<p>
- * The three encode** methods are used to encode query constraints.<p>
- * Implementations are encouraged to cache mappings, because typically there will
- * be many request with similar parameters.
+ * Implementations of this interface implement the mapping of logical field (as represented by
+ * {@link IndexField}) to the actual field name(s) used to index such values.
+ * <p>
+ * Such mappings are needed for indexing as well as querying for information within the full text index.
+ * <p>
+ * Implementations of this class are NOT responsible for converting actual values to there index
+ * representation. This is provided by the {@link IndexValueFactory} that converts java object's to
+ * {@link IndexValue} instances and vis versa. However this interface contains a convenience method that
+ * allows to get the field names for a <code>List<String> path</code> and a
+ * <code>IndexValue indexValue</code> because this is the most common task while indexing data.
+ * <p>
+ * The three encode** methods are used to encode query constraints.
+ * <p>
+ * Implementations are encouraged to cache mappings, because typically there will be many request with similar
+ * parameters.
+ *
* @author Rupert Westenthaler.
*/
public interface FieldMapper {
/**
- * This is the unique ID of this component. This ID must be be used to store
- * configurations that should be unique for this component.
+ * This is the unique ID of this component. This ID must be be used to store configurations that should be
+ * unique for this component.
*/
String URI = "urn:eu.iksproject:rick.yard.solr:config.namespacePrefixConfig";
- //TODO: Need to change that to following
- //String URI = "urn:org.apache.stanbol:entityhub.yard.solr:config.namespacePrefixConfig";
- // ... will do that later, because it would invalidate all existing indexes
+ // TODO: Need to change that to following
+ // String URI = "urn:org.apache.stanbol:entityhub.yard.solr:config.namespacePrefixConfig";
+ // ... will do that later, because it would invalidate all existing indexes
/**
* The field used to store all namespace prefixes
*/
String PREFIX_FIELD = "urn:eu.iksproject:rick.yard.solr:config.namespacePrefix";
- //TODO: Need to change that to following
- //String PREFIX_FIELD = "urn:org.apache.stanbol:entityhub.yard.solr:config.namespacePrefix";
- // ... will do that later, because it would invalidate all existing indexes
- /**
- * Getter for the Field used to store the domain(s) of the Document. This
- * field is used if Documents of different domains are stored within the
- * same Index.<p>
+
+ // TODO: Need to change that to following
+ // String PREFIX_FIELD = "urn:org.apache.stanbol:entityhub.yard.solr:config.namespacePrefix";
+ // ... will do that later, because it would invalidate all existing indexes
+ /**
+ * Getter for the Field used to store the domain(s) of the Document. This field is used if Documents of
+ * different domains are stored within the same Index.
+ * <p>
+ *
* @return the field name to store the document domain within the index
*/
String getDocumentDomainField();
+
/**
- * Getter for the actual field names for parsed path and index value.<p>
- * Note that the dataType and the language are encoded as prefixes and/or
- * suffixes to the field name. A single value may be indexed in several
- * fields in the document (especially to support searches for multiple
- * languages)
- * @param path the path. MUST NOT be <code>null</code> nor empty and MUST
- * NOT contain an element that is <code>null</code> or empty.
- * @param indexValue the index value. MUST NOT be <code>null</code>.
- * @return the field names. Guaranteed to contain at least one element. All
- * element are guaranteed to be not <code>null</code> nor empty.
- * @throws IllegalArgumentException if the parsed path and/or index value do
- * not confirm with the requirements
+ * Getter for the actual field names for parsed path and index value.
+ * <p>
+ * Note that the dataType and the language are encoded as prefixes and/or suffixes to the field name. A
+ * single value may be indexed in several fields in the document (especially to support searches for
+ * multiple languages)
+ *
+ * @param path
+ * the path. MUST NOT be <code>null</code> nor empty and MUST NOT contain an element that is
+ * <code>null</code> or empty.
+ * @param indexValue
+ * the index value. MUST NOT be <code>null</code>.
+ * @return the field names. Guaranteed to contain at least one element. All element are guaranteed to be
+ * not <code>null</code> nor empty.
+ * @throws IllegalArgumentException
+ * if the parsed path and/or index value do not confirm with the requirements
*/
Collection<String> getFieldNames(List<String> path, IndexValue indexValue) throws IllegalArgumentException;
+
/**
- * Getter for the actual field names used to index the parsed logical index
- * field. A single index field may be indexed in several
- * fields in the document (especially to support searches for multiple
+ * Getter for the actual field names used to index the parsed logical index field. A single index field
+ * may be indexed in several fields in the document (especially to support searches for multiple
* languages)
- * @param indexField the index field. MUST NOT be <code>null</code>
- * @return the field names. Guaranteed to contain at least one element. All
- * element are guaranteed to be not <code>null</code> nor empty.
- * @throws IllegalArgumentException if the parsed index field is
- * <code>null</code>.
+ *
+ * @param indexField
+ * the index field. MUST NOT be <code>null</code>
+ * @return the field names. Guaranteed to contain at least one element. All element are guaranteed to be
+ * not <code>null</code> nor empty.
+ * @throws IllegalArgumentException
+ * if the parsed index field is <code>null</code>.
*/
Collection<String> getFieldNames(IndexField indexField) throws IllegalArgumentException;
+
/**
- * Getter for the logical {@link IndexField} of an given fieldName, typically
- * as found in a document retrieved from the index.
- * @param fieldName the name of the field in the index document
- * @return the logical index field or <code>null</code> if the parsed field
- * name does not represent a logical field.<p>
- * Note that this may only happen, if the index is configured to store values
- * for fields that do not represent logical field. This is typically not the
- * case, but may be activated for debugging reasons.
+ * Getter for the logical {@link IndexField} of an given fieldName, typically as found in a document
+ * retrieved from the index.
+ *
+ * @param fieldName
+ * the name of the field in the index document
+ * @return the logical index field or <code>null</code> if the parsed field name does not represent a
+ * logical field.
+ * <p>
+ * Note that this may only happen, if the index is configured to store values for fields that do
+ * not represent logical field. This is typically not the case, but may be activated for debugging
+ * reasons.
*/
IndexField getField(String fieldName);
+
/**
* Getter for the field name used to store the unique identification-
+ *
* @return
*/
String getDocumentIdField();
+
/**
- * Getter for the field name used to store id's of documents this document
- * depends on.<p>
- * This is only needed when path with a length > 1 are indexed. This
- * information is needed to for maintenance of the index if such entities are
- * changed. However this information might also be used to calculate the
- * semantic context.<p>
- * Note that the values stored in this field are a subset of the values
- * stored by the {@link #getReferredDocumentField()} field.
- * @return the field name used for storing the id's of documents this document
- * depends on.
+ * Getter for the field name used to store id's of documents this document depends on.
+ * <p>
+ * This is only needed when path with a length > 1 are indexed. This information is needed to for
+ * maintenance of the index if such entities are changed. However this information might also be used to
+ * calculate the semantic context.
+ * <p>
+ * Note that the values stored in this field are a subset of the values stored by the
+ * {@link #getReferredDocumentField()} field.
+ *
+ * @return the field name used for storing the id's of documents this document depends on.
*/
String getDependentDocumentField();
+
/**
- * Getter for the field name used to store the id's of documents this document
- * refers to.<p>
- * This information is needed for maintenance of the index if documents are
- * deleted. However this information might also be used to calculate the
- * semantic context.<p>
- * Note that the values stored in this field are a superset of the values
- * stored by the {@link #getDependentDocumentField()} field.
- * @return the field name used for storing the id's of documents this document
- * refers to.
+ * Getter for the field name used to store the id's of documents this document refers to.
+ * <p>
+ * This information is needed for maintenance of the index if documents are deleted. However this
+ * information might also be used to calculate the semantic context.
+ * <p>
+ * Note that the values stored in this field are a superset of the values stored by the
+ * {@link #getDependentDocumentField()} field.
+ *
+ * @return the field name used for storing the id's of documents this document refers to.
*/
String getReferredDocumentField();
/**
* Getter for the Merger Field for the parse language
- * @param lang the language or <code>null</code> for the merger field for all
- * languages
+ *
+ * @param lang
+ * the language or <code>null</code> for the merger field for all languages
* @return the merger field for the parsed language
*/
String getLanguageMergerField(String lang);
+
/**
* Getter for the field prefixes for the parsed languages
- * @param lang the languages. <code>null</code> or an empty array to indicate
- * that no language is present.
- * @return the field prefixes used to encode the parsed languages. Guaranteed
- * to return NOT <code>null</code>. If no prefix is needed to encode, an
- * empty collection is returned
+ *
+ * @param lang
+ * the languages. <code>null</code> or an empty array to indicate that no language is present.
+ * @return the field prefixes used to encode the parsed languages. Guaranteed to return NOT
+ * <code>null</code>. If no prefix is needed to encode, an empty collection is returned
*/
Collection<String> encodeLanguages(Collection<String> languages);
+
/**
* Getter for the prefix/suffix used to encode the parsed index data type.
- * @param dataType the data type
- * @return An array with two entries, where the first represents the
- * prefix and the second the suffix used to encode the index data type. In
- * case no prefix/suffix is used to represent the parsed index data type, the
- * according entry in the array is <code>null</code>
- * @throws IllegalArgumentException if no prefix/suffix mapping is defined
- * for the parsed index data type
+ *
+ * @param dataType
+ * the data type
+ * @return An array with two entries, where the first represents the prefix and the second the suffix used
+ * to encode the index data type. In case no prefix/suffix is used to represent the parsed index
+ * data type, the according entry in the array is <code>null</code>
+ * @throws IllegalArgumentException
+ * if no prefix/suffix mapping is defined for the parsed index data type
*/
- String[] encodeDataType(IndexDataType dataType) throws IllegalArgumentException ;
+ String[] encodeDataType(IndexDataType dataType) throws IllegalArgumentException;
+
/**
* Getter for the encoded path
- * @param path the path. MUST NOT be <code>null</code> nor empty and MUST
- * NOT contain an element that is <code>null</code> or empty.
+ *
+ * @param path
+ * the path. MUST NOT be <code>null</code> nor empty and MUST NOT contain an element that is
+ * <code>null</code> or empty.
* @return the encoded path
- * @throws IllegalArgumentException if the parsed path and/or index value do
- * not confirm with the requirements
+ * @throws IllegalArgumentException
+ * if the parsed path and/or index value do not confirm with the requirements
*/
- String encodePath(List<String>path) throws IllegalArgumentException;
+ String encodePath(List<String> path) throws IllegalArgumentException;
}
Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/IndexDataType.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/IndexDataType.java?rev=1102791&r1=1102790&r2=1102791&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/IndexDataType.java (original)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/IndexDataType.java Fri May 13 15:29:20 2011
@@ -19,27 +19,27 @@ package org.apache.stanbol.entityhub.yar
import org.apache.stanbol.entityhub.servicesapi.defaults.NamespaceEnum;
/**
- * This class is used to define index types. It is only used to provide an unique
- * ID and an human readable name for such types.<p>
- * This type is necessary, because we assume that indices only support string
- * values. Therefore any java type needs to be converted to its string
- * representation. This type is used to preserve the type information. <p>
- * How types are encoded within the index depends on the actual full text index
- * used. The functionality of mapping of this index data types to the actual
- * types as supported by the index is provided by the used {@link FieldMapper}
- * implementation.<p>
- * It is suggested to use the XSD Datatypes as id's for instances where suitable.
- * see <a herf=http://www.w3.org/TR/xmlschema-2/#built-in-datatypes> XSD built in
- * datatypes</a> for more information.
- *
+ * This class is used to define index types. It is only used to provide an unique ID and an human readable
+ * name for such types.
+ * <p>
+ * This type is necessary, because we assume that indices only support string values. Therefore any java type
+ * needs to be converted to its string representation. This type is used to preserve the type information.
+ * <p>
+ * How types are encoded within the index depends on the actual full text index used. The functionality of
+ * mapping of this index data types to the actual types as supported by the index is provided by the used
+ * {@link FieldMapper} implementation.
+ * <p>
+ * It is suggested to use the XSD Datatypes as id's for instances where suitable. see <a
+ * herf=http://www.w3.org/TR/xmlschema-2/#built-in-datatypes> XSD built in datatypes</a> for more information.
+ *
* @author Rupert Westenthaler
- *
+ *
*/
public final class IndexDataType {
/**
* The default index type is defined as xsd:string (http://www.w3.org/2001/XMLSchema/string)
*/
- public static final IndexDataType DEFAULT = new IndexDataType(NamespaceEnum.xsd+"string");
+ public static final IndexDataType DEFAULT = new IndexDataType(NamespaceEnum.xsd + "string");
/**
* Prefix used by this type
*/
@@ -48,64 +48,73 @@ public final class IndexDataType {
* Suffix used by this type
*/
private final String name;
+
public IndexDataType(String id) {
- this(id,null);
+ this(id, null);
}
+
/**
- * Creates a new index data type, by defining it's id and name. The id MUST NOT
- * be <code>null</code> nor empty. If the name is <code>null</code>, than the
- * name is generated based on the id by searching the last index of '#', '/' or
- * ':'.
- * @param id the unique id used for this data type. Values MUST NOT be
- * <code>null</code> nor empty.
- * @param name the name for this data type.
- *
+ * Creates a new index data type, by defining it's id and name. The id MUST NOT be <code>null</code> nor
+ * empty. If the name is <code>null</code>, than the name is generated based on the id by searching the
+ * last index of '#', '/' or ':'.
+ *
+ * @param id
+ * the unique id used for this data type. Values MUST NOT be <code>null</code> nor empty.
+ * @param name
+ * the name for this data type.
+ *
*/
- public IndexDataType(String id,String name) {
+ public IndexDataType(String id, String name) {
this.id = id;
- if(name == null){
+ if (name == null) {
String defaultName;
- if(id.lastIndexOf('#')>=0){
- defaultName = id.substring(id.lastIndexOf('#')+1);
- } else if(id.lastIndexOf('/')>=0){
- defaultName = id.substring(id.lastIndexOf('/')+1);
- } else if(id.lastIndexOf(':')>=0){
- defaultName = id.substring(id.lastIndexOf(':')+1);
+ if (id.lastIndexOf('#') >= 0) {
+ defaultName = id.substring(id.lastIndexOf('#') + 1);
+ } else if (id.lastIndexOf('/') >= 0) {
+ defaultName = id.substring(id.lastIndexOf('/') + 1);
+ } else if (id.lastIndexOf(':') >= 0) {
+ defaultName = id.substring(id.lastIndexOf(':') + 1);
} else {
defaultName = id;
}
- //convert first char to lower case
- this.name = defaultName.substring(0,1).toLowerCase()+defaultName.substring(1);
+ // convert first char to lower case
+ this.name = defaultName.substring(0, 1).toLowerCase() + defaultName.substring(1);
} else {
this.name = name;
}
}
+
/**
* Getter for the prefix
- * @return the prefix used by this type or <code>null</code> if this
- * type does not use a prefix.
+ *
+ * @return the prefix used by this type or <code>null</code> if this type does not use a prefix.
*/
- public final String getId(){
+ public final String getId() {
return id;
}
+
/**
* Getter for the name
+ *
* @return the name of this dataType
*/
- public final String getName(){
+ public final String getName() {
return name;
}
+
@Override
public int hashCode() {
return id.hashCode();
}
+
@Override
public boolean equals(Object obj) {
- return obj instanceof IndexDataType && ((IndexDataType)obj).id.equals(id);
+ return obj instanceof IndexDataType && ((IndexDataType) obj).id.equals(id);
}
+
/**
- * Returns the id of the dataType. Use {@link #getName()} if you need a
- * short variant
+ * Returns the id of the dataType. Use {@link #getName()} if you need a short variant
+ *
* @return the id of the dataType
*/
@Override
Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/IndexField.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/IndexField.java?rev=1102791&r1=1102790&r2=1102791&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/IndexField.java (original)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/IndexField.java Fri May 13 15:29:20 2011
@@ -23,21 +23,21 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
-
-
/**
- * Represents a logical field within the index.<p>
+ * Represents a logical field within the index.
+ * <p>
* A logical field consists of the following parts:
* <ul>
- * <li> The path, a list of path elements (URIs parsed as String)
- * <li> The {@link IndexDataType}
- * <li> The language
+ * <li>The path, a list of path elements (URIs parsed as String)
+ * <li>The {@link IndexDataType}
+ * <li>The language
* </ul>
* <p>
- * Logical fields are than mapped with an 1..n mapping to actual fields in the
- * Index Documents. This functionality is provided by the {@link FieldMapper}
+ * Logical fields are than mapped with an 1..n mapping to actual fields in the Index Documents. This
+ * functionality is provided by the {@link FieldMapper}
+ *
* @author Rupert Westenthaler
- *
+ *
*/
public class IndexField {
@@ -45,101 +45,116 @@ public class IndexField {
private final IndexDataType indexType;
private final Set<String> languages;
private final int hash;
+
/**
* Constructs a new IndexField
+ *
* @param path
* @param indexType
* @param language
* @throws IllegalArgumentException
*/
- public IndexField(List<String> path, IndexDataType indexType, String...languages) throws IllegalArgumentException {
+ public IndexField(List<String> path, IndexDataType indexType, String... languages) throws IllegalArgumentException {
validatePath(path);
- //we need to create a new list, to ensure, that no one can change this member!
+ // we need to create a new list, to ensure, that no one can change this member!
this.path = Collections.unmodifiableList(new ArrayList<String>(path));
- if(indexType == null){
- this.indexType = IndexDataType.DEFAULT; //the type representing no pre- nor suffix
+ if (indexType == null) {
+ this.indexType = IndexDataType.DEFAULT; // the type representing no pre- nor suffix
} else {
this.indexType = indexType;
}
- if(languages == null || languages.length<1){
+ if (languages == null || languages.length < 1) {
this.languages = Collections.emptySet();
} else {
Set<String> languageSet = new HashSet<String>();
- for(String language : languages){
- if(language == null || language.isEmpty()){
- languageSet.add(null); //interpret empty as default language
+ for (String language : languages) {
+ if (language == null || language.isEmpty()) {
+ languageSet.add(null); // interpret empty as default language
} else {
languageSet.add(language);
}
}
this.languages = Collections.unmodifiableSet(languageSet);
}
- //calculate the hash of is immutable class only once
- hash = this.path.hashCode()+this.indexType.hashCode()+this.languages.hashCode();
+ // calculate the hash of is immutable class only once
+ hash = this.path.hashCode() + this.indexType.hashCode() + this.languages.hashCode();
}
+
/**
- * Checks if the path is not <code>null</code>, empty and does not contain
- * a <code>null</code> or empty element.
- * @param path the path to validate
- * @throws IllegalArgumentException if the parsed path in not valid
+ * Checks if the path is not <code>null</code>, empty and does not contain a <code>null</code> or empty
+ * element.
+ *
+ * @param path
+ * the path to validate
+ * @throws IllegalArgumentException
+ * if the parsed path in not valid
*/
public static void validatePath(List<String> path) throws IllegalArgumentException {
- if(path == null || path.isEmpty()){
+ if (path == null || path.isEmpty()) {
throw new IllegalArgumentException("Parameter path MUST NOT be NULL nor empty!");
}
- if(path.contains(null) || path.contains("")){
- throw new IllegalArgumentException(
- String.format("The parsed path MUST NOT contain a NULL value or an empty element (path=%s)",path));
+ if (path.contains(null) || path.contains("")) {
+ throw new IllegalArgumentException(String.format(
+ "The parsed path MUST NOT contain a NULL value or an empty element (path=%s)", path));
}
}
+
/**
* Getter for the Path
- * @return the path. Unmodifiable list, guaranteed to contain at lest one
- * element. All elements are guaranteed NOT <code>null</code> and NOT empty.
+ *
+ * @return the path. Unmodifiable list, guaranteed to contain at lest one element. All elements are
+ * guaranteed NOT <code>null</code> and NOT empty.
*/
public final List<String> getPath() {
return path;
}
+
/**
* Getter for the index data type
+ *
* @return the index data type. Guaranteed to be NOT <code>null</code>
*/
- public final IndexDataType getDataType(){
+ public final IndexDataType getDataType() {
return indexType;
}
+
/**
* Checks if this field defines any language
- * @return <code>true</code> if a language is defined for this field. Note
- * that <code>true</code> is returned if the language is <code>null</code>.
+ *
+ * @return <code>true</code> if a language is defined for this field. Note that <code>true</code> is
+ * returned if the language is <code>null</code>.
*/
- public final boolean hasLanguage(){
+ public final boolean hasLanguage() {
return !languages.isEmpty();
}
+
/**
* Getter for the Languages.
- * @return the languages. Unmodifiable collection, guaranteed to contain at
- * least one element. May contain the <code>null</code> value (used for the
- * default language).
+ *
+ * @return the languages. Unmodifiable collection, guaranteed to contain at least one element. May contain
+ * the <code>null</code> value (used for the default language).
*/
- public final Collection<String> getLanguages(){
+ public final Collection<String> getLanguages() {
return languages;
}
+
@Override
public boolean equals(Object obj) {
- return obj instanceof IndexField &&
- ((IndexField)obj).path.equals(path) &&
- ((IndexField)obj).indexType.equals(indexType) &&
- ((IndexField)obj).languages.equals(languages);
+ return obj instanceof IndexField && ((IndexField) obj).path.equals(path)
+ && ((IndexField) obj).indexType.equals(indexType)
+ && ((IndexField) obj).languages.equals(languages);
}
+
@Override
public int hashCode() {
return hash;
}
+
@Override
public String toString() {
- return String.format("IndexField[path: %s|type: %s", path,indexType)+
- (hasLanguage()?String.format("|languages: %s]", languages):"]");
+ return String.format("IndexField[path: %s|type: %s", path, indexType)
+ + (hasLanguage() ? String.format("|languages: %s]", languages) : "]");
}
}
Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/IndexValue.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/IndexValue.java?rev=1102791&r1=1102790&r2=1102791&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/IndexValue.java (original)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/IndexValue.java Fri May 13 15:29:20 2011
@@ -27,58 +27,65 @@ public final class IndexValue {
*/
private final int hash;
- public IndexValue(String value,IndexDataType type){
- this(value,type,null,false);
+ public IndexValue(String value, IndexDataType type) {
+ this(value, type, null, false);
}
- public IndexValue(String value,IndexDataType type,String language){
- this(value,type,language,true);
+ public IndexValue(String value, IndexDataType type, String language) {
+ this(value, type, language, true);
}
- private IndexValue(String value,IndexDataType type,String language,boolean hasLanguage){
- if(value == null || value.isEmpty()){
+
+ private IndexValue(String value, IndexDataType type, String language, boolean hasLanguage) {
+ if (value == null || value.isEmpty()) {
throw new IllegalArgumentException("The value MUST NOT be NULL nor empty!");
}
this.value = value;
- if(type == null){
+ if (type == null) {
throw new IllegalArgumentException("The IndexType MUST NOT be NULL nor empty!");
}
this.type = type;
this.hasLanguage = hasLanguage;
- if(this.hasLanguage){
+ if (this.hasLanguage) {
this.language = language;
} else {
this.language = null;
}
- this.hash = type.hashCode()+value.hashCode()+(language!=null?language.hashCode():0);
+ this.hash = type.hashCode() + value.hashCode() + (language != null ? language.hashCode() : 0);
}
- public final String getValue(){
+
+ public final String getValue() {
return value;
}
- public final IndexDataType getType(){
+
+ public final IndexDataType getType() {
return type;
}
- public final String getLanguage(){
+
+ public final String getLanguage() {
return language;
}
- public final boolean hasLanguage(){
+
+ public final boolean hasLanguage() {
return hasLanguage;
}
+
@Override
public int hashCode() {
return hash;
}
+
@Override
public boolean equals(Object obj) {
- return obj instanceof IndexValue &&
- ((IndexValue)obj).value.equals(value) &&
- ((IndexValue)obj).type.equals(type) &&
- ((IndexValue)obj).hasLanguage == hasLanguage && (
- (language == null && ((IndexValue)obj).language == null) ||
- (language!=null &&language.equals(((IndexValue)obj).language))
- );
+ return obj instanceof IndexValue
+ && ((IndexValue) obj).value.equals(value)
+ && ((IndexValue) obj).type.equals(type)
+ && ((IndexValue) obj).hasLanguage == hasLanguage
+ && ((language == null && ((IndexValue) obj).language == null) || (language != null && language
+ .equals(((IndexValue) obj).language)));
}
+
@Override
public String toString() {
- return value+(language!=null?("@"+language):"")+"^^"+type;
+ return value + (language != null ? ("@" + language) : "") + "^^" + type;
}
}
Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/IndexValueFactory.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/IndexValueFactory.java?rev=1102791&r1=1102790&r2=1102791&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/IndexValueFactory.java (original)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/IndexValueFactory.java Fri May 13 15:29:20 2011
@@ -41,13 +41,11 @@ import org.joda.time.format.ISODateTimeF
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
/**
- * This class provides methods to convert java objects to {@link IndexValue} and
- * vice versa.
+ * This class provides methods to convert java objects to {@link IndexValue} and vice versa.
* <p>
* Implementation Note: This class needs to be thread save.
- *
+ *
* @author Rupert Westenthaler
*/
public class IndexValueFactory {
@@ -57,7 +55,7 @@ public class IndexValueFactory {
private static ValueFactory valueFactory = InMemoryValueFactory.getInstance();
private static IndexValueFactory instance = new IndexValueFactory();
static {
- //register the default converters
+ // register the default converters
instance.registerConverter(new BigDecimalConverter());
instance.registerConverter(new BigIntegerConverter());
instance.registerConverter(new DateConverter());
@@ -70,109 +68,120 @@ public class IndexValueFactory {
instance.registerConverter(new StringConverter());
instance.registerConverter(new TextConverter(valueFactory));
}
+
/**
* Get a <code>IndexValueFactory</code>.
- *
+ *
* @return the <code>IndexValueFactory</code> instance
*/
public static IndexValueFactory getInstance() {
return instance;
}
- //TODO: add support for IndexTypeConverter
-// private Map<IndexType,TypeConverter<?>> indexTypeConverters =
-// new HashMap<IndexType, TypeConverter<?>>();
+ // TODO: add support for IndexTypeConverter
+ // private Map<IndexType,TypeConverter<?>> indexTypeConverters =
+ // new HashMap<IndexType, TypeConverter<?>>();
/**
- * Holds the java class to {@link TypeConverter} mapping for all converters
- * registered for a Java Class.<p>
- * NOTE: this implementation distinguishes between classed and interfaces,
- * because for Classes a simple get lookup in the Map can be used while for
- * Interfaces we need to Iterate over the entries of the Map and check with
- * {@link Class#isAssignableFrom(Class)}.
+ * Holds the java class to {@link TypeConverter} mapping for all converters registered for a Java Class.
+ * <p>
+ * NOTE: this implementation distinguishes between classed and interfaces, because for Classes a simple
+ * get lookup in the Map can be used while for Interfaces we need to Iterate over the entries of the Map
+ * and check with {@link Class#isAssignableFrom(Class)}.
*/
- private Map<Class<?>,TypeConverter<?>> javaClassConverters =
- Collections.synchronizedMap(new HashMap<Class<?>, TypeConverter<?>>());
+ private Map<Class<?>,TypeConverter<?>> javaClassConverters = Collections
+ .synchronizedMap(new HashMap<Class<?>,TypeConverter<?>>());
/**
- * Holds the java interface to {@link TypeConverter} mappings for all
- * converters registered for a Java Interface<p>
- * NOTE: this implementation distinguishes between classed and interfaces,
- * because for Classes a simple get lookup in the Map can be used while for
- * Interfaces we need to Iterate over the entries of the Map and check with
- * {@link Class#isAssignableFrom(Class)}.
+ * Holds the java interface to {@link TypeConverter} mappings for all converters registered for a Java
+ * Interface
+ * <p>
+ * NOTE: this implementation distinguishes between classed and interfaces, because for Classes a simple
+ * get lookup in the Map can be used while for Interfaces we need to Iterate over the entries of the Map
+ * and check with {@link Class#isAssignableFrom(Class)}.
*/
- private Map<Class<?>,TypeConverter<?>> javaInterfaceConverters =
- new HashMap<Class<?>, TypeConverter<?>>();
+ private Map<Class<?>,TypeConverter<?>> javaInterfaceConverters = new HashMap<Class<?>,TypeConverter<?>>();
+
/**
- * Registers a converter to this factory. Note that only one converter per
- * java type can be registered
+ * Registers a converter to this factory. Note that only one converter per java type can be registered
+ *
* @see TypeConverter#getJavaType()
- * @param converter the converter to be registered
+ * @param converter
+ * the converter to be registered
*/
- public void registerConverter(TypeConverter<?> converter){
- if(converter == null){ return;}
+ public void registerConverter(TypeConverter<?> converter) {
+ if (converter == null) {
+ return;
+ }
Class<?> javaType = converter.getJavaType();
- if(javaType.isInterface()){
- //NOTE: To ensure thread save iterations over Entries of this Map
- //create new map instance, add to the new instance and replace reference
+ if (javaType.isInterface()) {
+ // NOTE: To ensure thread save iterations over Entries of this Map
+ // create new map instance, add to the new instance and replace reference
// ... i know this is slow, but such calls are very uncommon
- Map<Class<?>,TypeConverter<?>> javaInterfaceConverterMap =
- new HashMap<Class<?>,TypeConverter<?>>(this.javaInterfaceConverters);
- javaInterfaceConverterMap.put(javaType,converter);
- //TODO: add support for IndexTypeConverter
+ Map<Class<?>,TypeConverter<?>> javaInterfaceConverterMap = new HashMap<Class<?>,TypeConverter<?>>(
+ this.javaInterfaceConverters);
+ javaInterfaceConverterMap.put(javaType, converter);
+ // TODO: add support for IndexTypeConverter
this.javaInterfaceConverters = javaInterfaceConverterMap;
} else {
- //there are no Iterations over this Map!
- javaClassConverters.put(javaType,converter);
+ // there are no Iterations over this Map!
+ javaClassConverters.put(javaType, converter);
}
}
+
/**
* Removes the converter for the parsed java type
- * @param type the java type
- * @return the removed converter or <code>null</code> if none was registered
- * for the parsed type.
+ *
+ * @param type
+ * the java type
+ * @return the removed converter or <code>null</code> if none was registered for the parsed type.
*/
@SuppressWarnings("unchecked")
- public <T> TypeConverter<T> removeConverter(Class<T> type){
- if(type == null){ return null;}
+ public <T> TypeConverter<T> removeConverter(Class<T> type) {
+ if (type == null) {
+ return null;
+ }
TypeConverter<T> converter;
- if(type.isInterface()){
- if(javaInterfaceConverters.containsKey(type)){
- //create new map instance, remove to the converter and replace reference
+ if (type.isInterface()) {
+ if (javaInterfaceConverters.containsKey(type)) {
+ // create new map instance, remove to the converter and replace reference
// ... i know this is slow, but such calls are very uncommon
- Map<Class<?>,TypeConverter<?>> javaInterfaceConverterMap =
- new HashMap<Class<?>,TypeConverter<?>>(this.javaInterfaceConverters);
- converter = (TypeConverter<T>)javaInterfaceConverterMap.remove(type);
+ Map<Class<?>,TypeConverter<?>> javaInterfaceConverterMap = new HashMap<Class<?>,TypeConverter<?>>(
+ this.javaInterfaceConverters);
+ converter = (TypeConverter<T>) javaInterfaceConverterMap.remove(type);
this.javaInterfaceConverters = javaInterfaceConverterMap;
} else {
converter = null;
}
} else {
- converter = (TypeConverter<T>)javaClassConverters.remove(type);
+ converter = (TypeConverter<T>) javaClassConverters.remove(type);
}
return converter;
}
+
/**
* Creates the value as used to index the parsed object
- *
- * @param value the value to be indexed
+ *
+ * @param value
+ * the value to be indexed
* @return the index representation of the parsed value
- * @throws NoConverterException thrown if <code>value</code> is of an invalid type
- * @throws IllegalArgumentException if the parsed value is null
+ * @throws NoConverterException
+ * thrown if <code>value</code> is of an invalid type
+ * @throws IllegalArgumentException
+ * if the parsed value is null
*/
@SuppressWarnings("unchecked")
- public IndexValue createIndexValue(Object value) throws NoConverterException,IllegalArgumentException {
- if(value == null){
+ public IndexValue createIndexValue(Object value) throws NoConverterException, IllegalArgumentException {
+ if (value == null) {
throw new IllegalArgumentException("Parameter value MUST NOT be NULL!");
}
- //first try to get the class and find a converter registered for a class
- TypeConverter<Object> converter = (TypeConverter<Object>)javaClassConverters.get(value.getClass());
- if(converter != null){
+ // first try to get the class and find a converter registered for a class
+ TypeConverter<Object> converter = (TypeConverter<Object>) javaClassConverters.get(value.getClass());
+ if (converter != null) {
return converter.createIndexValue(value);
}
- //if not successful we need still to search for converters registered for interfaces
- for(Entry<Class<?>, TypeConverter<?>> entry : javaInterfaceConverters.entrySet()){
- if(entry.getKey().isAssignableFrom(value.getClass())){
- return ((TypeConverter<Object>)entry.getValue()).createIndexValue(value);
+ // if not successful we need still to search for converters registered for interfaces
+ for (Entry<Class<?>,TypeConverter<?>> entry : javaInterfaceConverters.entrySet()) {
+ if (entry.getKey().isAssignableFrom(value.getClass())) {
+ return ((TypeConverter<Object>) entry.getValue()).createIndexValue(value);
}
}
throw new NoConverterException(value.getClass());
@@ -180,120 +189,145 @@ public class IndexValueFactory {
/**
* Converts a IndexValue instance to an instance of the specified class
- *
+ *
* @param <T>
- * @param type the <code>Class</code> of the returned object
- * @param indexValue the index value instance
+ * @param type
+ * the <code>Class</code> of the returned object
+ * @param indexValue
+ * the index value instance
* @return a java object representing the value of the index value
- * @throws NoConverterException thrown if <code>type</code> is unsupported
- * @throws UnsupportedIndexTypeException if the {@link IndexDataType} of the parsed
- * {@link IndexValue} is not supported by the registered converter
- * @throws IllegalArgumentException if any of the two parameter is <code>null</code>
+ * @throws NoConverterException
+ * thrown if <code>type</code> is unsupported
+ * @throws UnsupportedIndexTypeException
+ * if the {@link IndexDataType} of the parsed {@link IndexValue} is not supported by the
+ * registered converter
+ * @throws IllegalArgumentException
+ * if any of the two parameter is <code>null</code>
*/
- public <T> T createValue(Class<T> type, IndexValue indexValue)
- throws NoConverterException,UnsupportedIndexTypeException,IllegalArgumentException {
- return createValue(type, indexValue.getType(),indexValue.getType(), indexValue.getLanguage());
+ public <T> T createValue(Class<T> type, IndexValue indexValue) throws NoConverterException,
+ UnsupportedIndexTypeException,
+ IllegalArgumentException {
+ return createValue(type, indexValue.getType(), indexValue.getType(), indexValue.getLanguage());
}
+
/**
* Converts a IndexValue instance to an instance of the specified class
- *
+ *
* @param <T>
- * @param javaType the requested java type
- * @param indexType the index type
- * @param indexValue the value in the index
- * @param language the language of the value in the index
+ * @param javaType
+ * the requested java type
+ * @param indexType
+ * the index type
+ * @param indexValue
+ * the value in the index
+ * @param language
+ * the language of the value in the index
* @return a java object representing the value of the index value
- * @throws NoConverterException thrown if <code>type</code> is unsupported
- * @throws UnsupportedIndexTypeException if the {@link IndexDataType} of the parsed
- * {@link IndexValue} is not supported by the registered converter
- * @throws IllegalArgumentException if any of the two parameter is <code>null</code>
+ * @throws NoConverterException
+ * thrown if <code>type</code> is unsupported
+ * @throws UnsupportedIndexTypeException
+ * if the {@link IndexDataType} of the parsed {@link IndexValue} is not supported by the
+ * registered converter
+ * @throws IllegalArgumentException
+ * if any of the two parameter is <code>null</code>
*/
@SuppressWarnings("unchecked")
- public <T> T createValue(Class<T> javaType, IndexDataType indexType, Object indexValue,String language)
- throws NoConverterException,UnsupportedIndexTypeException,IllegalArgumentException {
- if(javaType == null){
+ public <T> T createValue(Class<T> javaType, IndexDataType indexType, Object indexValue, String language) throws NoConverterException,
+ UnsupportedIndexTypeException,
+ IllegalArgumentException {
+ if (javaType == null) {
throw new IllegalArgumentException("Parameter Class<T> type MUST NOT be NULL");
}
- if(indexValue == null){
+ if (indexValue == null) {
throw new IllegalArgumentException("Parameter IndexValue MUST NOT be NULL");
}
- //search interface converter map if the parsed type is an interface
- TypeConverter<T> converter = (TypeConverter<T>)(javaType.isInterface()?javaInterfaceConverters.get(javaType):javaClassConverters.get(javaType));
- if(converter != null){
- return converter.createObject(indexType,indexValue,language);
+ // search interface converter map if the parsed type is an interface
+ TypeConverter<T> converter = (TypeConverter<T>) (javaType.isInterface() ? javaInterfaceConverters
+ .get(javaType) : javaClassConverters.get(javaType));
+ if (converter != null) {
+ return converter.createObject(indexType, indexValue, language);
} else {
throw new NoConverterException(javaType);
}
}
- //TODO: add support for IndexTypeConverter
-// /**
-// * Converts a IndexValue instance to an java object. The type of the java
-// * object.
-// * @param indexValue the index value instance
-// * @return a java object representing the value of the index value
-// * @throws NoConverterException if no converter for the index value is registered
-// */
-// public Object createObject(IndexValue indexValue) throws NoConverterException {
-//
-// }
+ // TODO: add support for IndexTypeConverter
+ // /**
+ // * Converts a IndexValue instance to an java object. The type of the java
+ // * object.
+ // * @param indexValue the index value instance
+ // * @return a java object representing the value of the index value
+ // * @throws NoConverterException if no converter for the index value is registered
+ // */
+ // public Object createObject(IndexValue indexValue) throws NoConverterException {
+ //
+ // }
/*
* ==== Internal Classes for the default converter Implementations ====
*/
- public static class DateConverter implements TypeConverter<Date> {
- private static final DateTimeFormatter XML_DATE_TIME_FORMAT = ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC);
- private static final DateTimeFormatter XML_DATE_TIME_FORMAT_noMillis = ISODateTimeFormat.dateTimeNoMillis().withZone(DateTimeZone.UTC);
+ public static class DateConverter implements TypeConverter<Date> {
+ private static final DateTimeFormatter XML_DATE_TIME_FORMAT = ISODateTimeFormat.dateTime().withZone(
+ DateTimeZone.UTC);
+ private static final DateTimeFormatter XML_DATE_TIME_FORMAT_noMillis = ISODateTimeFormat
+ .dateTimeNoMillis().withZone(DateTimeZone.UTC);
public static final IndexDataType INDEX_TYPE = IndexDataTypeEnum.DATE.getIndexType();
@Override
public IndexValue createIndexValue(Date value) {
- return new IndexValue(XML_DATE_TIME_FORMAT.print(value.getTime()),INDEX_TYPE);
+ return new IndexValue(XML_DATE_TIME_FORMAT.print(value.getTime()), INDEX_TYPE);
}
@Override
public Date createObject(IndexValue indexValue) {
- if(indexValue == null){
+ if (indexValue == null) {
return null;
}
return createObject(indexValue.getType(), indexValue, indexValue.getLanguage());
}
+
@Override
public Class<Date> getJavaType() {
return Date.class;
}
+
@Override
- public IndexDataType getIndexType(){
+ public IndexDataType getIndexType() {
return INDEX_TYPE;
}
@Override
- public Date createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException, UnsupportedValueException {
- if(type == null){
+ public Date createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException,
+ UnsupportedValueException {
+ if (type == null) {
throw new IllegalArgumentException("The parsed IndexDataType MUST NOT be null");
}
- if(!type.equals(INDEX_TYPE)) {
- throw new UnsupportedIndexTypeException(this,type);
+ if (!type.equals(INDEX_TYPE)) {
+ throw new UnsupportedIndexTypeException(this, type);
}
- if(value == null){
+ if (value == null) {
return null;
}
- if(value instanceof Date){
+ if (value instanceof Date) {
return (Date) value;
- } else if(value instanceof Calendar){
- return ((Calendar)value).getTime();
+ } else if (value instanceof Calendar) {
+ return ((Calendar) value).getTime();
} else {
DateTime date;
try {
- //NOTE: Solr only support UTC ... so we need to change the Timezone
+ // NOTE: Solr only support UTC ... so we need to change the Timezone
date = XML_DATE_TIME_FORMAT.parseDateTime(value.toString());
} catch (IllegalArgumentException e) {
try {
date = XML_DATE_TIME_FORMAT_noMillis.parseDateTime(value.toString());
} catch (IllegalArgumentException e1) {
- log.warn("Unable to parse Date/Time for Value "+value.toString()+" (use ISO date format (milliseconds optional))! -> no Date Mapping added!",e1);
- throw new UnsupportedValueException(this, type, value,e);
+ log.warn(
+ "Unable to parse Date/Time for Value "
+ + value.toString()
+ + " (use ISO date format (milliseconds optional))! -> no Date Mapping added!",
+ e1);
+ throw new UnsupportedValueException(this, type, value, e);
}
}
return date.toDate();
@@ -308,7 +342,7 @@ public class IndexValueFactory {
@Override
public IndexValue createIndexValue(Boolean value) {
- if(value == null){
+ if (value == null) {
return null;
}
return new IndexValue(value.toString(), INDEX_TYPE);
@@ -316,33 +350,36 @@ public class IndexValueFactory {
@Override
public Boolean createObject(IndexValue value) {
- if(value == null){
+ if (value == null) {
return null;
}
return createObject(value.getType(), value.getValue(), value.getLanguage());
}
+
@Override
public Class<Boolean> getJavaType() {
return Boolean.class;
}
+
@Override
public IndexDataType getIndexType() {
return INDEX_TYPE;
}
@Override
- public Boolean createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException, UnsupportedValueException {
- if(type == null){
+ public Boolean createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException,
+ UnsupportedValueException {
+ if (type == null) {
throw new IllegalArgumentException("The parsed IndexDataType MUST NOT be null");
}
- if(!type.equals(INDEX_TYPE)){
- throw new UnsupportedIndexTypeException(this,type);
+ if (!type.equals(INDEX_TYPE)) {
+ throw new UnsupportedIndexTypeException(this, type);
}
- if(value == null){
+ if (value == null) {
return null;
}
- if(value instanceof Boolean){
- return (Boolean)value;
+ if (value instanceof Boolean) {
+ return (Boolean) value;
} else {
return Boolean.valueOf(value.toString());
}
@@ -352,21 +389,26 @@ public class IndexValueFactory {
public static class StringConverter implements TypeConverter<String> {
public static final IndexDataType INDEX_TYPE = IndexDataTypeEnum.STR.getIndexType();
private boolean acceptAllIndexTypes;
+
public final boolean isAcceptAllIndexTypes() {
return acceptAllIndexTypes;
}
+
public final void setAcceptAllIndexTypes(boolean acceptAllIndexTypes) {
this.acceptAllIndexTypes = acceptAllIndexTypes;
}
+
public StringConverter() {
this(true);
}
- public StringConverter(boolean acceptAllIndexTypes){
+
+ public StringConverter(boolean acceptAllIndexTypes) {
this.acceptAllIndexTypes = acceptAllIndexTypes;
}
+
@Override
public IndexValue createIndexValue(String value) {
- if(value == null){
+ if (value == null) {
return null;
}
return new IndexValue(value, INDEX_TYPE);
@@ -374,50 +416,58 @@ public class IndexValueFactory {
@Override
public String createObject(IndexValue value) {
- if(value == null){
+ if (value == null) {
return null;
}
- //for now accept any IndexValue regardless of type
-// if(!value.getType().equals(INDEX_TYPE)){
-// new UnsupportedIndexTypeException(this, value);
-// }
+ // for now accept any IndexValue regardless of type
+ // if(!value.getType().equals(INDEX_TYPE)){
+ // new UnsupportedIndexTypeException(this, value);
+ // }
return value.getValue();
}
+
@Override
public Class<String> getJavaType() {
return String.class;
}
+
@Override
public IndexDataType getIndexType() {
return INDEX_TYPE;
}
+
@Override
public String createObject(IndexDataType type, Object value, String lang) throws NullPointerException {
- if(type == null){
+ if (type == null) {
throw new IllegalArgumentException("The parsed IndexDataType MUST NOT be null");
}
- return value!=null?value.toString():null;
+ return value != null ? value.toString() : null;
}
}
public static class IntegerConverter implements TypeConverter<Integer> {
public static final IndexDataType INDEX_TYPE = IndexDataTypeEnum.INT.getIndexType();
private boolean acceptLong;
+
public final boolean isAcceptLong() {
return acceptLong;
}
+
public final void setAcceptLong(boolean acceptLong) {
this.acceptLong = acceptLong;
}
+
public IntegerConverter() {
this(true);
}
- public IntegerConverter(boolean acceptLongIndexType){
+
+ public IntegerConverter(boolean acceptLongIndexType) {
this.acceptLong = acceptLongIndexType;
}
+
@Override
public IndexValue createIndexValue(Integer value) {
- if(value == null){
+ if (value == null) {
return null;
}
return new IndexValue(value.toString(), INDEX_TYPE);
@@ -425,31 +475,37 @@ public class IndexValueFactory {
@Override
public Integer createObject(IndexValue value) {
- if(value == null){
+ if (value == null) {
return null;
}
return createObject(value.getType(), value.getValue(), value.getLanguage());
}
+
@Override
public Class<Integer> getJavaType() {
// TODO Auto-generated method stub
return Integer.class;
}
+
@Override
public IndexDataType getIndexType() {
return INDEX_TYPE;
}
+
@Override
- public Integer createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException, UnsupportedValueException, NullPointerException {
- if(type == null){
+ public Integer createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException,
+ UnsupportedValueException,
+ NullPointerException {
+ if (type == null) {
throw new IllegalArgumentException("The parsed IndexDataType MUST NOT be null");
}
- if(type.equals(INDEX_TYPE)){
- if(value == null){ //move in here to ensure returning UnsupportedIndexTypeException on wrong types
+ if (type.equals(INDEX_TYPE)) {
+ if (value == null) { // move in here to ensure returning UnsupportedIndexTypeException on
+ // wrong types
return null;
}
- if(value instanceof Integer){
- return (Integer)value;
+ if (value instanceof Integer) {
+ return (Integer) value;
} else {
try {
return Integer.valueOf(value.toString());
@@ -457,13 +513,14 @@ public class IndexValueFactory {
throw new UnsupportedValueException(this, type, value, e);
}
}
- } else if(acceptLong && type.equals(IndexDataTypeEnum.LONG.getIndexType())){
- if(value == null){ //move in here to ensure returning UnsupportedIndexTypeException on wrong types
+ } else if (acceptLong && type.equals(IndexDataTypeEnum.LONG.getIndexType())) {
+ if (value == null) { // move in here to ensure returning UnsupportedIndexTypeException on
+ // wrong types
return null;
}
long longValue;
- if(value instanceof Long){
- longValue = ((Long)value).longValue();
+ if (value instanceof Long) {
+ longValue = ((Long) value).longValue();
} else {
try {
longValue = Long.parseLong(value.toString());
@@ -471,15 +528,19 @@ public class IndexValueFactory {
throw new UnsupportedValueException(this, type, value, e);
}
}
- if(Integer.MAX_VALUE >= longValue && Integer.MIN_VALUE <= longValue){
- return Integer.valueOf((int)longValue);
+ if (Integer.MAX_VALUE >= longValue && Integer.MIN_VALUE <= longValue) {
+ return Integer.valueOf((int) longValue);
} else {
- //parsed long value outside of the int range
- throw new UnsupportedValueException(this, type, value,
- new IllegalStateException("Unable to convert LONG Value to Integer, because the value is outside of the Integer Range!"));
+ // parsed long value outside of the int range
+ throw new UnsupportedValueException(
+ this,
+ type,
+ value,
+ new IllegalStateException(
+ "Unable to convert LONG Value to Integer, because the value is outside of the Integer Range!"));
}
} else {
- throw new UnsupportedIndexTypeException(this,type);
+ throw new UnsupportedIndexTypeException(this, type);
}
}
}
@@ -491,7 +552,7 @@ public class IndexValueFactory {
@Override
public IndexValue createIndexValue(Long value) {
- if(value == null){
+ if (value == null) {
return null;
}
return new IndexValue(value.toString(), LONG_TYPE);
@@ -499,33 +560,37 @@ public class IndexValueFactory {
@Override
public Long createObject(IndexValue value) {
- if(value == null){
+ if (value == null) {
return null;
}
return createObject(value.getType(), value.getValue(), value.getLanguage());
}
+
@Override
public Class<Long> getJavaType() {
return Long.class;
}
+
@Override
public IndexDataType getIndexType() {
return LONG_TYPE;
}
@Override
- public Long createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException, UnsupportedValueException,NullPointerException {
- if(type == null){
+ public Long createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException,
+ UnsupportedValueException,
+ NullPointerException {
+ if (type == null) {
throw new IllegalArgumentException("The parsed IndexDataType MUST NOT be null");
}
- if(type.equals(LONG_TYPE) || type.equals(INT_TYPE)){
- if(value == null){
+ if (type.equals(LONG_TYPE) || type.equals(INT_TYPE)) {
+ if (value == null) {
return null;
}
- if(value instanceof Long){
+ if (value instanceof Long) {
return (Long) value;
- } else if(value instanceof Integer){
- return ((Integer)value).longValue();
+ } else if (value instanceof Integer) {
+ return ((Integer) value).longValue();
} else {
try {
return new Long(value.toString());
@@ -542,16 +607,13 @@ public class IndexValueFactory {
public static class DoubleConverter implements TypeConverter<Double> {
public static final IndexDataType INDEX_TYPE = IndexDataTypeEnum.DOUBLE.getIndexType();
- private static final Set<IndexDataType> SUPPORTED = new HashSet<IndexDataType>(
- Arrays.asList(
- IndexDataTypeEnum.FLOAT.getIndexType(),
- IndexDataTypeEnum.INT.getIndexType(),
- IndexDataTypeEnum.LONG.getIndexType(),
- INDEX_TYPE));
+ private static final Set<IndexDataType> SUPPORTED = new HashSet<IndexDataType>(Arrays.asList(
+ IndexDataTypeEnum.FLOAT.getIndexType(), IndexDataTypeEnum.INT.getIndexType(),
+ IndexDataTypeEnum.LONG.getIndexType(), INDEX_TYPE));
@Override
public IndexValue createIndexValue(Double value) {
- if(value == null){
+ if (value == null) {
return null;
}
return new IndexValue(value.toString(), INDEX_TYPE);
@@ -559,73 +621,81 @@ public class IndexValueFactory {
@Override
public Double createObject(IndexValue value) {
- if(value == null){
+ if (value == null) {
return null;
}
return createObject(value.getType(), value.getValue(), value.getLanguage());
}
+
@Override
public Class<Double> getJavaType() {
return Double.class;
}
+
@Override
public IndexDataType getIndexType() {
return INDEX_TYPE;
}
@Override
- public Double createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException, UnsupportedValueException, NullPointerException {
- if(type == null){
+ public Double createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException,
+ UnsupportedValueException,
+ NullPointerException {
+ if (type == null) {
throw new IllegalArgumentException("The parsed IndexDataType MUST NOT be null");
}
- if(SUPPORTED.contains(type)){
- if(value == null){
+ if (SUPPORTED.contains(type)) {
+ if (value == null) {
return null;
}
- if(value instanceof Double){
+ if (value instanceof Double) {
return (Double) value;
- } else if(value instanceof Float){
- return ((Float)value).doubleValue();
+ } else if (value instanceof Float) {
+ return ((Float) value).doubleValue();
} else {
try {
return new Double(value.toString());
} catch (NumberFormatException e) {
- throw new UnsupportedValueException(this,type, value, e);
+ throw new UnsupportedValueException(this, type, value, e);
}
}
} else {
- throw new UnsupportedIndexTypeException(this,type);
+ throw new UnsupportedIndexTypeException(this, type);
}
}
}
+
public static class FloatConverter implements TypeConverter<Float> {
public static final IndexDataType INDEX_TYPE = IndexDataTypeEnum.FLOAT.getIndexType();
private static final Collection<IndexDataType> DOUBLE_LONG_TYPES = Arrays.asList(
- IndexDataTypeEnum.LONG.getIndexType(),
- IndexDataTypeEnum.DOUBLE.getIndexType());
- private final Set<IndexDataType> supported = Collections.synchronizedSet(new HashSet<IndexDataType>());
+ IndexDataTypeEnum.LONG.getIndexType(), IndexDataTypeEnum.DOUBLE.getIndexType());
+ private final Set<IndexDataType> supported = Collections
+ .synchronizedSet(new HashSet<IndexDataType>());
+
public FloatConverter() {
this(true);
}
- public FloatConverter(boolean acceptDoubleAndLongIndexType){
- supported.addAll(Arrays.asList(
- IndexDataTypeEnum.INT.getIndexType(),
- INDEX_TYPE));
+
+ public FloatConverter(boolean acceptDoubleAndLongIndexType) {
+ supported.addAll(Arrays.asList(IndexDataTypeEnum.INT.getIndexType(), INDEX_TYPE));
setAcceptDoubleAndLongIndexTypes(acceptDoubleAndLongIndexType);
}
- public boolean isAcceptDoubleAndLongIndexTypes(){
+
+ public boolean isAcceptDoubleAndLongIndexTypes() {
return supported.containsAll(DOUBLE_LONG_TYPES);
}
- public final void setAcceptDoubleAndLongIndexTypes(boolean state){
- if(state){
+
+ public final void setAcceptDoubleAndLongIndexTypes(boolean state) {
+ if (state) {
supported.addAll(DOUBLE_LONG_TYPES);
} else {
supported.removeAll(DOUBLE_LONG_TYPES);
}
}
+
@Override
public IndexValue createIndexValue(Float value) {
- if(value == null){
+ if (value == null) {
return null;
}
return new IndexValue(value.toString(), INDEX_TYPE);
@@ -633,32 +703,37 @@ public class IndexValueFactory {
@Override
public Float createObject(IndexValue value) {
- if(value == null){
+ if (value == null) {
return null;
}
return createObject(value.getType(), value.getValue(), value.getLanguage());
}
+
@Override
public Class<Float> getJavaType() {
return Float.class;
}
+
@Override
public IndexDataType getIndexType() {
return INDEX_TYPE;
}
+
@Override
- public Float createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException, UnsupportedValueException, NullPointerException {
- if(type == null) {
+ public Float createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException,
+ UnsupportedValueException,
+ NullPointerException {
+ if (type == null) {
throw new IllegalArgumentException("The parsed IndexDataType MUST NOT be null");
}
- if(supported.contains(type)){
- if(value == null){
+ if (supported.contains(type)) {
+ if (value == null) {
return null;
}
- if(value instanceof Float){
+ if (value instanceof Float) {
return (Float) value;
- } else if(value instanceof Double){
- return ((Double)value).floatValue();
+ } else if (value instanceof Double) {
+ return ((Double) value).floatValue();
} else {
try {
return new Float(value.toString());
@@ -667,10 +742,11 @@ public class IndexValueFactory {
}
}
} else {
- throw new UnsupportedIndexTypeException(this,type);
+ throw new UnsupportedIndexTypeException(this, type);
}
}
}
+
public static class BigIntegerConverter implements TypeConverter<BigInteger> {
public static final IndexDataType INDEX_TYPE = IndexDataTypeEnum.LONG.getIndexType();
@@ -678,7 +754,7 @@ public class IndexValueFactory {
@Override
public IndexValue createIndexValue(BigInteger value) {
- if(value == null){
+ if (value == null) {
return null;
}
return new IndexValue(value.toString(), INDEX_TYPE);
@@ -686,52 +762,54 @@ public class IndexValueFactory {
@Override
public BigInteger createObject(IndexValue value) {
- if(value == null){
+ if (value == null) {
return null;
}
- return createObject(value.getType(), value.getValue(),value.getLanguage());
+ return createObject(value.getType(), value.getValue(), value.getLanguage());
}
+
@Override
public Class<BigInteger> getJavaType() {
return BigInteger.class;
}
+
@Override
public IndexDataType getIndexType() {
return INDEX_TYPE;
}
@Override
- public BigInteger createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException, UnsupportedValueException, NullPointerException {
- if(type == null){
+ public BigInteger createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException,
+ UnsupportedValueException,
+ NullPointerException {
+ if (type == null) {
throw new IllegalArgumentException("The parsed IndexDataType MUST NOT be null");
}
- if(type.equals(INDEX_TYPE) || type.equals(INT_TYPE)){
- if(value == null){
+ if (type.equals(INDEX_TYPE) || type.equals(INT_TYPE)) {
+ if (value == null) {
return null;
}
try {
return new BigInteger(value.toString());
- }catch (NumberFormatException e) {
- throw new UnsupportedValueException(this, type,value, e);
+ } catch (NumberFormatException e) {
+ throw new UnsupportedValueException(this, type, value, e);
}
} else {
throw new UnsupportedIndexTypeException(this, type);
}
}
}
+
public static class BigDecimalConverter implements TypeConverter<BigDecimal> {
public static final IndexDataType INDEX_TYPE = IndexDataTypeEnum.DOUBLE.getIndexType();
- private static final Set<IndexDataType> SUPPORTED = new HashSet<IndexDataType>(
- Arrays.asList(
- IndexDataTypeEnum.FLOAT.getIndexType(),
- IndexDataTypeEnum.INT.getIndexType(),
- IndexDataTypeEnum.LONG.getIndexType(),
- INDEX_TYPE));
+ private static final Set<IndexDataType> SUPPORTED = new HashSet<IndexDataType>(Arrays.asList(
+ IndexDataTypeEnum.FLOAT.getIndexType(), IndexDataTypeEnum.INT.getIndexType(),
+ IndexDataTypeEnum.LONG.getIndexType(), INDEX_TYPE));
@Override
public IndexValue createIndexValue(BigDecimal value) {
- if(value == null){
+ if (value == null) {
return null;
}
return new IndexValue(value.toString(), INDEX_TYPE);
@@ -739,21 +817,24 @@ public class IndexValueFactory {
@Override
public BigDecimal createObject(IndexValue value) {
- return createObject(value.getType(),value.getValue(), value.getLanguage());
+ return createObject(value.getType(), value.getValue(), value.getLanguage());
}
+
@Override
- public BigDecimal createObject(IndexDataType type,Object value, String lang) throws UnsupportedIndexTypeException, UnsupportedValueException, NullPointerException {
- if(type == null){
+ public BigDecimal createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException,
+ UnsupportedValueException,
+ NullPointerException {
+ if (type == null) {
throw new IllegalArgumentException("The parsed IndexDataType MUST NOT be null");
}
- if(SUPPORTED.contains(type)){
- if(value == null){
+ if (SUPPORTED.contains(type)) {
+ if (value == null) {
return null;
}
try {
return new BigDecimal(value.toString());
} catch (NumberFormatException e) {
- throw new UnsupportedValueException(this, type,value, e);
+ throw new UnsupportedValueException(this, type, value, e);
}
} else {
throw new UnsupportedIndexTypeException(type);
@@ -764,51 +845,61 @@ public class IndexValueFactory {
public Class<BigDecimal> getJavaType() {
return BigDecimal.class;
}
+
@Override
public IndexDataType getIndexType() {
return INDEX_TYPE;
}
}
+
public static class TextConverter implements TypeConverter<Text> {
public static final IndexDataType INDEX_TYPE = IndexDataTypeEnum.TXT.getIndexType();
private static final IndexDataType STRING_TYPE = IndexDataTypeEnum.STR.getIndexType();
private final ValueFactory valueFactory;
+
public TextConverter(ValueFactory valueFactory) {
- if(valueFactory == null){
+ if (valueFactory == null) {
throw new IllegalArgumentException("Parameter ValueFactory MUST NOT be NULL!");
}
this.valueFactory = valueFactory;
}
+
@Override
public IndexValue createIndexValue(Text value) {
- if(value == null){
+ if (value == null) {
return null;
}
- return new IndexValue(value.getText(), INDEX_TYPE,value.getLanguage());
+ return new IndexValue(value.getText(), INDEX_TYPE, value.getLanguage());
}
+
@Override
public Text createObject(IndexValue value) throws UnsupportedIndexTypeException {
- if(value == null){
+ if (value == null) {
return null;
}
return createObject(value.getType(), value.getValue(), value.getLanguage());
}
+
@Override
public Class<Text> getJavaType() {
return Text.class;
}
+
@Override
public IndexDataType getIndexType() {
return INDEX_TYPE;
}
+
@Override
- public Text createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException, UnsupportedValueException, NullPointerException {
- if(type == null){
+ public Text createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException,
+ UnsupportedValueException,
+ NullPointerException {
+ if (type == null) {
throw new IllegalArgumentException("The parsed IndexDataType MUST NOT be null");
}
- if(type.equals(INDEX_TYPE) || type.equals(STRING_TYPE)){
- if(value == null){
+ if (type.equals(INDEX_TYPE) || type.equals(STRING_TYPE)) {
+ if (value == null) {
return null;
}
return valueFactory.createText(value.toString(), lang);
@@ -817,44 +908,53 @@ public class IndexValueFactory {
}
}
}
+
public static class ReferenceConverter implements TypeConverter<Reference> {
public static final IndexDataType INDEX_TYPE = IndexDataTypeEnum.REF.getIndexType();
private final ValueFactory valueFactory;
+
public ReferenceConverter(ValueFactory valueFactory) {
- if(valueFactory == null){
+ if (valueFactory == null) {
throw new IllegalArgumentException("Parameter ValueFactory MUST NOT be NULL!");
}
this.valueFactory = valueFactory;
}
+
@Override
public IndexValue createIndexValue(Reference value) {
- if(value == null){
+ if (value == null) {
return null;
}
return new IndexValue(value.getReference(), INDEX_TYPE);
}
+
@Override
public Reference createObject(IndexValue value) throws UnsupportedIndexTypeException {
- if(value == null){
+ if (value == null) {
return null;
}
return createObject(value.getType(), value.getValue(), value.getLanguage());
}
+
@Override
public Class<Reference> getJavaType() {
return Reference.class;
}
+
@Override
public IndexDataType getIndexType() {
return INDEX_TYPE;
}
+
@Override
- public Reference createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException, UnsupportedValueException, NullPointerException {
- if(type == null) {
+ public Reference createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException,
+ UnsupportedValueException,
+ NullPointerException {
+ if (type == null) {
throw new IllegalArgumentException("The parsed IndexDataType MUST NOT be null");
}
- if(type.equals(INDEX_TYPE)){
- if(value == null){
+ if (type.equals(INDEX_TYPE)) {
+ if (value == null) {
return null;
}
return valueFactory.createReference(value.toString());
Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/NoConverterException.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/NoConverterException.java?rev=1102791&r1=1102790&r2=1102791&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/NoConverterException.java (original)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/NoConverterException.java Fri May 13 15:29:20 2011
@@ -19,10 +19,9 @@ package org.apache.stanbol.entityhub.yar
import java.lang.reflect.Type;
/**
- * This exception is thrown when no adapter is available to do a required
- * java-object to {@link IndexValue} or {@link IndexValue} to java-object
- * adapter is registered to the used {@link IndexValueFactory}.
- *
+ * This exception is thrown when no adapter is available to do a required java-object to {@link IndexValue} or
+ * {@link IndexValue} to java-object adapter is registered to the used {@link IndexValueFactory}.
+ *
* @author Rupert Westenthaler
*/
public class NoConverterException extends RuntimeException {
@@ -33,12 +32,13 @@ public class NoConverterException extend
private static final long serialVersionUID = 1L;
/**
- * Create an instance of <code>NoAdapterException</code>
- * indicating that no adapter is available for the type.
- *
- * @param type the type for which no adapter is available
+ * Create an instance of <code>NoAdapterException</code> indicating that no adapter is available for the
+ * type.
+ *
+ * @param type
+ * the type for which no adapter is available
*/
public NoConverterException(Type type) {
- super("No adapter available for type "+type);
+ super("No adapter available for type " + type);
}
}