You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
geoportal-data-viewer-app/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/util/StringUtil.java

35 lines
919 B
Java

/**
*
*/
package org.gcube.portlets.user.geoportaldataviewer.client.util;
/**
* The Class StringUtil.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Nov 16, 2020
*/
public class StringUtil {
/**
* Ellipsize.
*
* @param input the input string that may be subjected to shortening
* @param maxCharacters the maximum characters that must be returned for the input string. Must be at least 3 (that is the ellipses size)
* @return the string
* @throws Exception the exception
*/
public static String ellipsize(String input, int maxCharacters) throws Exception{
if(maxCharacters < 3) {
throw new IllegalArgumentException("maxCharacters must be at least 3 because the ellipsis already take up 3 characters");
}
if (input == null || input.length() < maxCharacters) {
return input;
}
return input.substring(0, maxCharacters)+"...";
}
}