本文整理了Java中org.apache.commons.lang3.StringUtils.left()
方法的一些代码示例,展示了StringUtils.left()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringUtils.left()
方法的具体详情如下:
包路径:org.apache.commons.lang3.StringUtils
类名称:StringUtils
方法名:left
[英]Gets the leftmost len characters of a String.
If len characters are not available, or the String is null, the String will be returned without an exception. An empty String is returned if len is negative.
StringUtils.left(null, *) = null
StringUtils.left(*, -ve) = ""
StringUtils.left("", *) = ""
StringUtils.left("abc", 0) = ""
StringUtils.left("abc", 2) = "ab"
StringUtils.left("abc", 4) = "abc"
[中]获取字符串最左边的len字符。
如果len字符不可用,或者字符串为null,则将返回该字符串,而不会出现异常。如果len为负,则返回空字符串。
StringUtils.left(null, *) = null
StringUtils.left(*, -ve) = ""
StringUtils.left("", *) = ""
StringUtils.left("abc", 0) = ""
StringUtils.left("abc", 2) = "ab"
StringUtils.left("abc", 4) = "abc"
代码示例来源:origin: gocd/gocd
public String limit(String code, int limit) {
if (code == null) {
return "";
}
String lefted = StringUtils.left(code, limit);
if (code.length() > limit) {
lefted = lefted + "...";
}
return lefted;
}
}
代码示例来源:origin: apache/phoenix
/**
* Add a numerically increasing counter onto the and of a random string.
* Incremented counter should be thread safe.
*
* @param column {@link org.apache.phoenix.pherf.configuration.Column}
* @return {@link org.apache.phoenix.pherf.rules.DataValue}
*/
private DataValue getSequentialDataValue(Column column) {
DataValue data = null;
long inc = COUNTER.getAndIncrement();
String strInc = String.valueOf(inc);
int paddedLength = column.getLengthExcludingPrefix();
String strInc1 = StringUtils.leftPad(strInc, paddedLength, "0");
String strInc2 = StringUtils.right(strInc1, column.getLengthExcludingPrefix());
String varchar = (column.getPrefix() != null) ? column.getPrefix() + strInc2:
strInc2;
// Truncate string back down if it exceeds length
varchar = StringUtils.left(varchar,column.getLength());
data = new DataValue(column.getType(), varchar);
return data;
}
代码示例来源:origin: selenide/selenide
private String trimQuery(String fullFileName) {
return fullFileName.contains("?")
? StringUtils.left(fullFileName, fullFileName.indexOf("?"))
: fullFileName;
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
public TableCreator addRow(Object[] data) {
if (data.length != cols.length) {
throw new IllegalArgumentException("Wrong number of data elements. Needed [" + cols.length + "] " +
"but received [" + data.length + "]");
}
sb.append('|');
for (int i = 0; i < data.length; i++) {
String trimmed = StringUtils.left(String.valueOf(data[i]), cols[i].width);
sb.append(' ').append(StringUtils.rightPad(trimmed, cols[i].width)).append(" |");
}
sb.append("\r\n");
return this;
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
public TableCreator addRow(String rowHeader, Object rowData) {
String trimmed = StringUtils.left(rowHeader, globalRowHeaderWidth);
sb.append("| ")
.append(StringUtils.rightPad(trimmed, globalRowHeaderWidth))
.append(StringUtils.rightPad(String.valueOf(rowData), rowWidth - globalRowHeaderWidth - 3))
.append("|\r\n");
return this;
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testLeft_String() {
assertSame(null, StringUtils.left(null, -1));
assertSame(null, StringUtils.left(null, 0));
assertSame(null, StringUtils.left(null, 2));
assertEquals("", StringUtils.left("", -1));
assertEquals("", StringUtils.left("", 0));
assertEquals("", StringUtils.left("", 2));
assertEquals("", StringUtils.left(FOOBAR, -1));
assertEquals("", StringUtils.left(FOOBAR, 0));
assertEquals(FOO, StringUtils.left(FOOBAR, 3));
assertSame(FOOBAR, StringUtils.left(FOOBAR, 80));
}
代码示例来源:origin: apache/nifi
private void createConfigureDetails(int actionId, ConfigureDetails configurationDetails) throws DataAccessException {
PreparedStatement statement = null;
try {
// obtain a statement to insert to the processor action table
statement = connection.prepareStatement(INSERT_CONFIGURE_DETAILS);
statement.setInt(1, actionId);
statement.setString(2, StringUtils.left(configurationDetails.getName(), 1000));
statement.setString(3, StringUtils.left(configurationDetails.getValue(), 5000));
statement.setString(4, StringUtils.left(configurationDetails.getPreviousValue(), 5000));
// insert the action
int updateCount = statement.executeUpdate();
// ensure the operation completed successfully
if (updateCount != 1) {
throw new DataAccessException("Unable to insert configure details.");
}
} catch (SQLException sqle) {
throw new DataAccessException(sqle);
} finally {
RepositoryUtils.closeQuietly(statement);
}
}
代码示例来源:origin: apache/nifi
private void createConnectDetails(int actionId, ConnectDetails connectionDetails) throws DataAccessException {
PreparedStatement statement = null;
try {
// obtain a statement to insert to the processor action table
statement = connection.prepareStatement(INSERT_CONNECT_DETAILS);
statement.setInt(1, actionId);
statement.setString(2, connectionDetails.getSourceId());
statement.setString(3, StringUtils.left(connectionDetails.getSourceName(), 1000));
statement.setString(4, StringUtils.left(connectionDetails.getSourceType().toString(), 1000));
statement.setString(5, StringUtils.left(connectionDetails.getRelationship(), 1000));
statement.setString(6, connectionDetails.getDestinationId());
statement.setString(7, StringUtils.left(connectionDetails.getDestinationName(), 1000));
statement.setString(8, StringUtils.left(connectionDetails.getDestinationType().toString(), 1000));
// insert the action
int updateCount = statement.executeUpdate();
// ensure the operation completed successfully
if (updateCount != 1) {
throw new DataAccessException("Unable to insert connection details.");
}
} catch (SQLException sqle) {
throw new DataAccessException(sqle);
} finally {
RepositoryUtils.closeQuietly(statement);
}
}
代码示例来源:origin: apache/nifi
private void createExtensionDetails(int actionId, ExtensionDetails extensionDetails) throws DataAccessException {
PreparedStatement statement = null;
try {
// obtain a statement to insert to the extension action table
statement = connection.prepareStatement(INSERT_EXTENSION_DETAILS);
statement.setInt(1, actionId);
statement.setString(2, StringUtils.left(extensionDetails.getType(), 1000));
// insert the action
int updateCount = statement.executeUpdate();
// ensure the operation completed successfully
if (updateCount != 1) {
throw new DataAccessException("Unable to insert extension details.");
}
} catch (SQLException sqle) {
throw new DataAccessException(sqle);
} finally {
RepositoryUtils.closeQuietly(statement);
}
}
代码示例来源:origin: apache/nifi
private void createRemoteProcessGroupDetails(int actionId, RemoteProcessGroupDetails remoteProcessGroupDetails) throws DataAccessException {
PreparedStatement statement = null;
try {
// obtain a statement to insert to the processor action table
statement = connection.prepareStatement(INSERT_REMOTE_PROCESS_GROUP_DETAILS);
statement.setInt(1, actionId);
statement.setString(2, StringUtils.left(remoteProcessGroupDetails.getUri(), 2500));
// insert the action
int updateCount = statement.executeUpdate();
// ensure the operation completed successfully
if (updateCount != 1) {
throw new DataAccessException("Unable to insert remote prcoess group details.");
}
} catch (SQLException sqle) {
throw new DataAccessException(sqle);
} finally {
RepositoryUtils.closeQuietly(statement);
}
}
代码示例来源:origin: apache/nifi
private void createMoveDetails(int actionId, MoveDetails moveDetails) throws DataAccessException {
PreparedStatement statement = null;
try {
// obtain a statement to insert to the processor action table
statement = connection.prepareStatement(INSERT_MOVE_DETAILS);
statement.setInt(1, actionId);
statement.setString(2, moveDetails.getGroupId());
statement.setString(3, StringUtils.left(moveDetails.getGroup(), 1000));
statement.setString(4, moveDetails.getPreviousGroupId());
statement.setString(5, StringUtils.left(moveDetails.getPreviousGroup(), 1000));
// insert the action
int updateCount = statement.executeUpdate();
// ensure the operation completed successfully
if (updateCount != 1) {
throw new DataAccessException("Unable to insert move details.");
}
} catch (SQLException sqle) {
throw new DataAccessException(sqle);
} finally {
RepositoryUtils.closeQuietly(statement);
}
}
代码示例来源:origin: jamesagnew/hapi-fhir
public void setName(String theName) {
myName = left(theName, CS_NAME_LENGTH);
}
代码示例来源:origin: jamesagnew/hapi-fhir
public void setFailureMessage(String theFailureMessage) {
myFailureMessage = left(theFailureMessage, FAILURE_MESSAGE_LENGTH);
}
代码示例来源:origin: apache/nifi
statement.setString(1, StringUtils.left(action.getUserIdentity(), 4096));
statement.setString(2, action.getSourceId());
statement.setString(3, StringUtils.left(action.getSourceName(), 1000));
statement.setString(4, action.getSourceType().name());
statement.setString(5, action.getOperation().name());
代码示例来源:origin: jamesagnew/hapi-fhir
public static long calculateHashNormalized(ModelConfig theModelConfig, String theResourceType, String theParamName, String theValueNormalized) {
/*
* If we're not allowing contained searches, we'll add the first
* bit of the normalized value to the hash. This helps to
* make the hash even more unique, which will be good for
* performance.
*/
int hashPrefixLength = HASH_PREFIX_LENGTH;
if (theModelConfig.isAllowContainsSearches()) {
hashPrefixLength = 0;
}
return hash(theResourceType, theParamName, left(theValueNormalized, hashPrefixLength));
}
代码示例来源:origin: palantir/atlasdb
@Test(expected = RuntimeException.class)
public void throwWhenCreatingDifferentLongTablesWithSameFirstCharactersUntilTheTableNameLimit() {
String tableNameForFirstSixtyCharactersToBeSame = StringUtils.left(TEST_LONG_TABLE_NAME,
PostgresDdlTable.ATLASDB_POSTGRES_TABLE_NAME_LIMIT - TEST_NAMESPACE.getName().length()
- TWO_UNDERSCORES);
createTwoTablesWithSamePrefix(tableNameForFirstSixtyCharactersToBeSame);
}
代码示例来源:origin: palantir/atlasdb
@Test
public void shouldNotThrowWhenCreatingDifferentLongTablesWithSameFirstCharactersUntilOneLessThanTableNameLimit() {
String tableNameForFirstFiftyNineCharactersToBeSame = StringUtils.left(TEST_LONG_TABLE_NAME,
PostgresDdlTable.ATLASDB_POSTGRES_TABLE_NAME_LIMIT - TEST_NAMESPACE.getName().length()
- TWO_UNDERSCORES - 1);
createTwoTablesWithSamePrefix(tableNameForFirstFiftyNineCharactersToBeSame);
}
代码示例来源:origin: apache/phoenix
private DataValue getRandomDataValue(Column column) {
String varchar = RandomStringUtils.randomAlphanumeric(column.getLength());
varchar = (column.getPrefix() != null) ? column.getPrefix() + varchar : varchar;
// Truncate string back down if it exceeds length
varchar = StringUtils.left(varchar, column.getLength());
return new DataValue(column.getType(), varchar);
}
}
代码示例来源:origin: info.magnolia/magnolia-core
protected String getParentPath(String name) {
final String lcName = name.toLowerCase();
if (lcName.length() == 1) {
return "/" + lcName.charAt(0);
}
return "/" + lcName.charAt(0) + "/" + StringUtils.left(lcName, 2);
}
}
代码示例来源:origin: org.xworker/xworker_core
public static String left(ActionContext actionContext){
Thing self = actionContext.getObject("self");
String str = (String) self.doAction("getStr", actionContext);
Integer len = (Integer) self.doAction("getLen", actionContext);
return StringUtils.left(str, len);
}
内容来源于网络,如有侵权,请联系作者删除!