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; } }
/** * 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; }
private String trimQuery(String fullFileName) { return fullFileName.contains("?") ? StringUtils.left(fullFileName, fullFileName.indexOf("?")) : fullFileName; }
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; }
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; }
@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)); }
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); } }
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); } }
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); } }
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); } }
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); } }
public void setName(String theName) { myName = left(theName, CS_NAME_LENGTH); }
public void setFailureMessage(String theFailureMessage) { myFailureMessage = left(theFailureMessage, FAILURE_MESSAGE_LENGTH); }
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());
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)); }
@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); }
@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); }
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); } }
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); } }
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); }