Skip to content

Commit

Permalink
HSEARCH-763 Cleanup. Fixed formatting, javadocs and unnecessay value …
Browse files Browse the repository at this point in the history
…boxing
  • Loading branch information
hferentschik committed Dec 4, 2014
1 parent 29473df commit ab8faa8
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 30 deletions.
Expand Up @@ -38,7 +38,7 @@
import org.hibernate.search.util.logging.impl.LoggerFactory;

/**
* This factory is responsible for creating and initializing build-in and custom <i>FieldBridges</i>.
* This factory is responsible for creating and initializing build-in and custom {@code FieldBridge}s.
*
* @author Emmanuel Bernard
* @author John Griffin
Expand All @@ -49,7 +49,7 @@ public final class BridgeFactory {
private Set<BridgeProvider> regularProviders;

public BridgeFactory(ServiceManager serviceManager) {
annotationBasedProviders = new HashSet<BridgeProvider>(5);
annotationBasedProviders = new HashSet<>(5);
annotationBasedProviders.add( new CalendarBridgeProvider() );
annotationBasedProviders.add( new DateBridgeProvider() );
annotationBasedProviders.add( new NumericBridgeProvider() );
Expand Down Expand Up @@ -121,7 +121,7 @@ else if ( org.hibernate.search.bridge.StringBridge.class.isAssignableFrom( bridg
*/
public void injectParameters(ClassBridge classBridgeConfiguration, Object classBridge) {
if ( classBridgeConfiguration.params().length > 0 && ParameterizedBridge.class.isAssignableFrom( classBridge.getClass() ) ) {
Map<String, String> params = new HashMap<String, String>( classBridgeConfiguration.params().length );
Map<String, String> params = new HashMap<>( classBridgeConfiguration.params().length );
for ( Parameter param : classBridgeConfiguration.params() ) {
params.put( param.name(), param.value() );
}
Expand Down Expand Up @@ -167,7 +167,7 @@ public FieldBridge guessType(Field field,
ExtendedBridgeProvider.ExtendedBridgeProviderContext context = new XMemberBridgeProviderContext( member, numericField, reflectionManager, serviceManager );
ContainerType containerType = getContainerType( member, reflectionManager );

// We do annotation based providers as Tike at least needs priority over
// We do annotation based providers as Tika at least needs priority over
// default providers because it might override the type for String
// TODO: introduce the notion of bridge contributor annotations to cope with this in the future
for ( BridgeProvider provider : annotationBasedProviders ) {
Expand Down Expand Up @@ -272,23 +272,24 @@ private FieldBridge getFieldBridgeFromBridgeProvider(
}

/**
* Extract the field bridge from @Field.bridge or @FieldBridge.
* Return null if none is present.
* @return the field bridge explicitly specified via {@code @Field.bridge} or {@code @FieldBridge}. {@code null}
* is returned if none is present.
*/
private FieldBridge findExplicitFieldBridge(Field field, XMember member, ReflectionManager reflectionManager) {
//TODO Should explicit FieldBridge also support the notion of container like numeric fields and provider based fields?
// the main problem is that support for a bridge accepting a Map would break
FieldBridge bridge = null;
org.hibernate.search.annotations.FieldBridge bridgeAnn;

org.hibernate.search.annotations.FieldBridge bridgeAnnotation;
//@Field bridge has priority over @FieldBridge
if ( field != null && void.class != field.bridge().impl() ) {
bridgeAnn = field.bridge();
bridgeAnnotation = field.bridge();
}
else {
bridgeAnn = member.getAnnotation( org.hibernate.search.annotations.FieldBridge.class );
bridgeAnnotation = member.getAnnotation( org.hibernate.search.annotations.FieldBridge.class );
}
if ( bridgeAnn != null ) {
bridge = doExtractType( bridgeAnn, member, reflectionManager );
if ( bridgeAnnotation != null ) {
bridge = doExtractType( bridgeAnnotation, member, reflectionManager );
}
return bridge;
}
Expand Down Expand Up @@ -327,7 +328,7 @@ else if ( org.hibernate.search.bridge.StringBridge.class.isAssignableFrom( impl
throw LOG.noFieldBridgeInterfaceImplementedByFieldBridge( impl.getName(), appliedOnName );
}
if ( bridgeAnn.params().length > 0 && ParameterizedBridge.class.isAssignableFrom( impl ) ) {
Map<String, String> params = new HashMap<String, String>( bridgeAnn.params().length );
Map<String, String> params = new HashMap<>( bridgeAnn.params().length );
for ( Parameter param : bridgeAnn.params() ) {
params.put( param.name(), param.value() );
}
Expand Down
Expand Up @@ -11,10 +11,9 @@
import org.hibernate.search.engine.service.spi.ServiceManager;

/**
* Service interface to implement to allow custom bridges to be
* auto discovered.
* Service interface to allow custom bridges to be auto discovered.
*
* It must have a default constructor and a file named
* Implementations of this interface must have a default constructor and a file named
* {@code META-INF/services/org.hibernate.search.bridge.spi.BridgeProvider}
* should contain the fully qualified class name of the bridge provider
* implementation. When several implementations are present in a given JAR,
Expand All @@ -26,21 +25,25 @@
public interface BridgeProvider {

/**
* Return a {@link org.hibernate.search.bridge.FieldBridge} instance if the provider can
* @return a {@link org.hibernate.search.bridge.FieldBridge} instance if the provider can
* build a bridge for the calling context. {@code null} otherwise.
*/
FieldBridge provideFieldBridge(BridgeProviderContext bridgeProviderContext);

interface BridgeProviderContext {

/**
* Member return type seeking a bridge.
* Returns the type of the indexed member/property.
*
* @return the type of the indexed member
*/
Class<?> getReturnType();

/**
* Provides access to the {@code ServiceManager} and gives access to
* Hibernate Search services like the {@code ClassLoaderService}.
*
* @return the Hibernate Search {@code ServiceManager}
*/
ServiceManager getServiceManager();
}
Expand Down
Expand Up @@ -11,9 +11,10 @@
import org.hibernate.search.exception.SearchException;

/**
* Utility class to handle Numeric Fields
* Utility class to handle numeric fields.
*
* @author Gustavo Fernandes
* @author Hardy Ferentschik
*/
public final class NumericFieldUtils {

Expand All @@ -24,7 +25,7 @@ private NumericFieldUtils() {
public static Query createNumericRangeQuery(String fieldName, Object from, Object to,
boolean includeLower, boolean includeUpper) {

Class numericClass;
Class<?> numericClass;

if ( from != null ) {
numericClass = from.getClass();
Expand Down Expand Up @@ -53,16 +54,17 @@ else if ( to != null ) {
// TODO: check for type before in the mapping
throw new SearchException(
"Cannot create numeric range query for field " + fieldName + ", since values are not numeric " +
"(int,long, short or double) ");
"(int, long, short or double) ");
}

/**
* Will create a RangeQuery matching exactly the provided value: lower
* Will create a {@code RangeQuery} matching exactly the provided value: lower
* and upper value match, and bounds are included. This should perform
* as efficiently as a TermQuery.
* @param fieldName
* @param value
* @return the created Query
*
* @param fieldName the field name the query targets
* @param value the value to match
* @return the created {@code Query}
*/
public static Query createExactMatchQuery(String fieldName, Object value) {
return createNumericRangeQuery( fieldName, value, value, true, true );
Expand Down
Expand Up @@ -178,6 +178,13 @@ public Builder precisionStep(int precisionStep) {
public DocumentFieldMetadata build() {
return new DocumentFieldMetadata( this );
}

@Override
public String toString() {
return "Builder{" +
"fieldName='" + fieldName + '\'' +
'}';
}
}
}

Expand Down
Expand Up @@ -171,13 +171,14 @@ public String toString() {
private Map<String, PropertyDescriptor> createPropertyDescriptors(TypeMetadata typeMetadata) {
Map<String, PropertyDescriptor> propertyDescriptorsTmp = new HashMap<String, PropertyDescriptor>();
for ( PropertyMetadata propertyMetadata : typeMetadata.getAllPropertyMetadata() ) {
createOrMergeProperDescriptor( propertyDescriptorsTmp, propertyMetadata );
createOrMergePropertyDescriptor( propertyDescriptorsTmp, propertyMetadata );
}
createOrMergeProperDescriptor( propertyDescriptorsTmp, typeMetadata.getIdPropertyMetadata() );
createOrMergePropertyDescriptor( propertyDescriptorsTmp, typeMetadata.getIdPropertyMetadata() );
return propertyDescriptorsTmp;
}

private void createOrMergeProperDescriptor(Map<String, PropertyDescriptor> propertyDescriptorsTmp, PropertyMetadata propertyMetadata) {
private void createOrMergePropertyDescriptor(Map<String, PropertyDescriptor> propertyDescriptorsTmp,
PropertyMetadata propertyMetadata) {
String propertyName = propertyMetadata.getPropertyAccessorName();
Set<FieldDescriptor> tmpSet = new HashSet<FieldDescriptor>();
if ( propertyDescriptorsTmp.containsKey( propertyName ) ) {
Expand Down
Expand Up @@ -92,7 +92,7 @@ public static Object getMemberValue(Object bean, XMember getter) {
* @return the list of classes in the hierarchy starting at {@code java.lang.Object}
*/
public static List<XClass> createXClassHierarchy(XClass clazz) {
List<XClass> hierarchy = new LinkedList<XClass>();
List<XClass> hierarchy = new LinkedList<>();
XClass next;
for ( XClass previousClass = clazz; previousClass != null; previousClass = next ) {
next = previousClass.getSuperclass();
Expand Down
Expand Up @@ -73,7 +73,6 @@ public void testMapping() throws Exception {

QueryParser parser = new QueryParser( TestConstants.getTargetLuceneVersion(), "id", TestConstants.standardAnalyzer );
org.apache.lucene.search.Query luceneQuery = parser.parse( "" + address.getAddressId() );
System.out.println( luceneQuery.toString() );
FullTextQuery query = s.createFullTextQuery( luceneQuery );
assertEquals( "documentId does not work properly", 1, query.getResultSize() );

Expand Down
Expand Up @@ -21,7 +21,7 @@ public class BigDecimalNumericFieldBridge implements FieldBridge, TwoWayFieldBri
public void set(String name, Object value, Document document, LuceneOptions luceneOptions) {
if ( value != null ) {
BigDecimal decimalValue = (BigDecimal) value;
Long indexedValue = Long.valueOf( decimalValue.multiply( storeFactor ).longValue() );
Long indexedValue = decimalValue.multiply( storeFactor ).longValue();
luceneOptions.addNumericFieldToDocument( name, indexedValue, document );
}
}
Expand Down

0 comments on commit ab8faa8

Please sign in to comment.