All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hibernate.search.cfg.ConcatStringBridge Maven / Gradle / Ivy

There is a newer version: 5.11.12.Final
Show newest version
/*
 * Hibernate Search, full-text search for your domain model
 *
 * License: GNU Lesser General Public License (LGPL), version 2.1 or later
 * See the lgpl.txt file in the root directory or .
 */
package org.hibernate.search.cfg;

import java.util.Map;

import org.hibernate.search.bridge.ParameterizedBridge;
import org.hibernate.search.bridge.StringBridge;

/**
 * @author Emmanuel Bernard
 */
public class ConcatStringBridge implements StringBridge, ParameterizedBridge {
	public static final String SIZE = "size";
	private int size;

	@Override
	public String objectToString(Object object) {
		if ( object == null ) {
			return "";
		}
		if ( !( object instanceof String ) ) {
			throw new RuntimeException( "not a string" );
		}
		String string = object.toString();
		int maxSize = string.length() >= size ? size : string.length();
		return string.substring( 0, maxSize );
	}

	@Override
	public void setParameterValues(Map parameters) {
		size = Integer.valueOf( parameters.get( SIZE ) );
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy