Java Code Examples for org.apache.commons.lang.StringUtils#left()
The following examples show how to use
org.apache.commons.lang.StringUtils#left() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InformationResponseMessage.java From openhab1-addons with Eclipse Public License 2.0 | 6 votes |
@Override protected void parsePayLoad() { Matcher matcher = RESPONSE_PATTERN.matcher(payLoad); if (matcher.matches()) { MAC = matcher.group(1); year = Integer.parseInt(matcher.group(2), 16) + 2000; month = Integer.parseInt(matcher.group(3), 16); minutes = Integer.parseInt(matcher.group(4), 16); logAddress = (Integer.parseInt(matcher.group(5), 16) - 278528) / 32; powerState = (matcher.group(6).equals("01")); hertz = Integer.parseInt(matcher.group(7), 16); hardwareVersion = StringUtils.left(matcher.group(8), 4) + "-" + StringUtils.mid(matcher.group(8), 4, 4) + "-" + StringUtils.right(matcher.group(8), 4); firmwareVersion = Integer.parseInt(matcher.group(9), 16); deviceType = intToDeviceType(Integer.parseInt(matcher.group(10), 16)); } else { logger.debug("Plugwise protocol RoleCallResponseMessage error: {} does not match", payLoad); } }
Example 2
Source File: AssetGlobal.java From kfs with GNU Affero General Public License v3.0 | 6 votes |
/** * Sets the universityFiscalPeriodName attribute. * * @param universityFiscalPeriodName The universityFiscalPeriodName to set. */ public void setUniversityFiscalPeriodName(String universityFiscalPeriodName) { if (StringUtils.isBlank(universityFiscalPeriodName)) { if (this.financialDocumentPostingPeriodCode != null && this.financialDocumentPostingYear != null) { universityFiscalPeriodName = this.financialDocumentPostingPeriodCode + this.financialDocumentPostingYear; } } String THIRTEEN = "13"; if (StringUtils.isNotBlank(universityFiscalPeriodName) && StringUtils.left(universityFiscalPeriodName, 2).equals(THIRTEEN)) { String period = StringUtils.left(universityFiscalPeriodName, 2); Integer year = new Integer(StringUtils.right(universityFiscalPeriodName, 4)); AccountingPeriod accountingPeriod = getAccountingPeriodService().getByPeriod(period, year); setAccountingPeriod(accountingPeriod); } this.universityFiscalPeriodName = universityFiscalPeriodName; }
Example 3
Source File: FileUtils.java From Aooms with Apache License 2.0 | 5 votes |
/** * 链接PATH前处理 * * @param path * @return */ public static String trimLeftPath(String path) { if (isFile(path)) return path; path = replacePath(path); String top = StringUtils.left(path, 1); if (StringUtils.equalsIgnoreCase(SLASH_TWO, top)) return StringUtils.substring(path, 1); return path; }
Example 4
Source File: AssetRetirementGlobal.java From kfs with GNU Affero General Public License v3.0 | 5 votes |
/** * Sets the accountingPeriod if in period 13 * @param accountingPeriodString * TODO remove hardcoding */ public void setAccountingPeriodCompositeString(String accountingPeriodString) { String THIRTEEN = "13"; if (StringUtils.isNotBlank(accountingPeriodString) && StringUtils.left(accountingPeriodString, 2).equals(THIRTEEN)) { String period = StringUtils.left(accountingPeriodString, 2); Integer year = new Integer(StringUtils.right(accountingPeriodString, 4)); AccountingPeriod accountingPeriod = getAccountingPeriodService().getByPeriod(period, year); setAccountingPeriod(accountingPeriod); } }
Example 5
Source File: VoucherForm.java From kfs with GNU Affero General Public License v3.0 | 5 votes |
/** * util method to get posting period code out of selectedAccountingPeriod * * @return String */ protected String getSelectedPostingPeriodCode() { String periodCode = null; String selectedPeriod = getSelectedAccountingPeriod(); if (StringUtils.isNotBlank(selectedPeriod)) { periodCode = StringUtils.left(selectedPeriod, 2); } return periodCode; }
Example 6
Source File: ProcurementCardCreateDocumentServiceImpl.java From kfs with GNU Affero General Public License v3.0 | 5 votes |
/** * Set up PCDO document description as "cardholder name-card number (which is 4 digits)-chartOfAccountsCode-default account" * * @param pcardDocument */ protected void setupDocumentDescription(ProcurementCardDocument pcardDocument) { ProcurementCardHolder cardHolder = pcardDocument.getProcurementCardHolder(); if (ObjectUtils.isNotNull(cardHolder)) { String cardHolderName = StringUtils.left(cardHolder.getCardHolderName(), 23); String lastFourDigits = StringUtils.right(cardHolder.getTransactionCreditCardNumber(), 4); String chartOfAccountsCode = cardHolder.getChartOfAccountsCode(); String accountNumber = cardHolder.getAccountNumber(); String description = MessageFormat.format(DOCUMENT_DESCRIPTION_PATTERN, cardHolderName, lastFourDigits, chartOfAccountsCode, accountNumber); pcardDocument.getDocumentHeader().setDocumentDescription(description); } }
Example 7
Source File: LedgerPostingDocumentBase.java From kfs with GNU Affero General Public License v3.0 | 5 votes |
/** * Set accountingPeriod based on incoming paramater. * @param accountingPeriodString in the form of [period][year] */ public void setAccountingPeriodCompositeString(String accountingPeriodString) { if (StringUtils.isNotBlank(accountingPeriodString)) { String period = StringUtils.left(accountingPeriodString, 2); Integer year = new Integer(StringUtils.right(accountingPeriodString, 4)); AccountingPeriod accountingPeriod = getAccountingPeriodService().getByPeriod(period, year); setAccountingPeriod(accountingPeriod); } }
Example 8
Source File: LaborTransactionDescriptionServiceImpl.java From kfs with GNU Affero General Public License v3.0 | 5 votes |
/** * @see org.kuali.kfs.module.ld.service.LaborTransactionDescriptionService#getTransactionDescription(org.kuali.kfs.gl.businessobject.Transaction) */ public String getTransactionDescription(Transaction transaction) { String documentTypeCode = transaction.getFinancialDocumentTypeCode(); String description = this.getTransactionDescription(documentTypeCode); description = StringUtils.isNotEmpty(description) ? description : transaction.getTransactionLedgerEntryDescription(); // make sure the length of the description cannot excess the specified maximum int transactionDescriptionMaxLength = SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength(transaction.getClass(), KFSPropertyConstants.TRANSACTION_LEDGER_ENTRY_DESC); if (StringUtils.isNotEmpty(description) && description.length() > transactionDescriptionMaxLength) { description = StringUtils.left(description, transactionDescriptionMaxLength); } return description; }
Example 9
Source File: ECSService.java From amazon-ecs-plugin with MIT License | 5 votes |
public ECSService(String credentialsId, String regionName) { this.clientSupplier = () -> { ProxyConfiguration proxy = Jenkins.get().proxy; ClientConfiguration clientConfiguration = new ClientConfiguration(); if (proxy != null) { clientConfiguration.setProxyHost(proxy.name); clientConfiguration.setProxyPort(proxy.port); clientConfiguration.setProxyUsername(proxy.getUserName()); clientConfiguration.setProxyPassword(proxy.getPassword()); } // Default is 3. 10 helps us actually utilize the SDK's backoff strategy // The strategy will wait up to 20 seconds per request (after multiple failures) clientConfiguration.setMaxErrorRetry(10); AmazonECSClientBuilder builder = AmazonECSClientBuilder .standard() .withClientConfiguration(clientConfiguration) .withRegion(regionName); AmazonWebServicesCredentials credentials = getCredentials(credentialsId); if (credentials != null) { if (LOGGER.isLoggable(Level.FINE)) { String awsAccessKeyId = credentials.getCredentials().getAWSAccessKeyId(); String obfuscatedAccessKeyId = StringUtils.left(awsAccessKeyId, 4) + StringUtils.repeat("*", awsAccessKeyId.length() - (2 * 4)) + StringUtils.right(awsAccessKeyId, 4); LOGGER.log(Level.FINE, "Connect to Amazon ECS with IAM Access Key {1}", new Object[]{obfuscatedAccessKeyId}); } builder .withCredentials(credentials); } LOGGER.log(Level.FINE, "Selected Region: {0}", regionName); return builder.build(); }; }
Example 10
Source File: FuncLeft.java From antsdb with GNU Lesser General Public License v3.0 | 5 votes |
@Override public long eval(VdmContext ctx, Heap heap, Parameters params, long pRecord) { long pString = this.parameters.get(0).eval(ctx, heap, params, pRecord); if (pString == 0) { return 0; } long pLength = this.parameters.get(1).eval(ctx, heap, params, pRecord); if (pLength == 0) { return 0; } String str = (String)FishObject.get(heap, AutoCaster.toString(heap, pString)); Long length = (Long)FishObject.get(heap, AutoCaster.toNumber(heap, pLength)); String result = StringUtils.left(str, (int)(long)length); return Unicode16.allocSet(heap, result); }
Example 11
Source File: VaporizingRow.java From antsdb with GNU Lesser General Public License v3.0 | 5 votes |
@Override public String toString() { StringBuilder buf = new StringBuilder(); buf.append("version:"); buf.append(this.version); buf.append('\n'); buf.append("max column id:"); buf.append(getMaxColumnId()); buf.append('\n'); buf.append("trx timestamp:"); buf.append(getTrxTimestamp()); buf.append('\n'); buf.append("key:"); buf.append(BytesUtil.toHex8(getKey())); for (int i = 0; i <= getMaxColumnId(); i++) { Object value = get(i); if (value != null) { buf.append('\n'); buf.append(i); buf.append(":"); String output; if (value instanceof byte[]) { output = BytesUtil.toHex((byte[]) value); } else { output = value.toString(); } if (output.length() >= 80) { output = StringUtils.left(output, 80) + "..."; } buf.append(output); } } return buf.toString(); }
Example 12
Source File: SensitiveInfoUtils.java From SuperBoot with MIT License | 5 votes |
/** * [中文姓名] 只显示第一个汉字,其他隐藏为2个星号<例子:李**> * * @param fullName 全名 * @return */ public static String chineseName(String fullName) { if (StringUtils.isBlank(fullName)) { return ""; } String name = StringUtils.left(fullName, 1); return StringUtils.rightPad(name, StringUtils.length(fullName), "*"); }
Example 13
Source File: UserService.java From seldon-server with Apache License 2.0 | 4 votes |
private static void truncateUsername(User user) { final String username = user.getUsername(); final String truncated = StringUtils.left(username, USERNAME_MAX_LENGTH); user.setUsername(truncated); }
Example 14
Source File: AssetGlobalRule.java From kfs with GNU Affero General Public License v3.0 | 4 votes |
@Override protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) { AssetGlobal assetGlobal = (AssetGlobal) document.getNewMaintainableObject().getBusinessObject(); boolean success = true; success &= super.processCustomSaveDocumentBusinessRules(document); if (GlobalVariables.getMessageMap().hasErrors()) { return false; } String acquisitionTypeCode = assetGlobal.getAcquisitionTypeCode(); String statusCode = assetGlobal.getInventoryStatusCode(); // no need to validate specific fields if document is "Asset Separate" if (!getAssetGlobalService().isAssetSeparate(assetGlobal)) { success &= validateAccount(assetGlobal); if (StringUtils.isNotBlank(acquisitionTypeCode) && StringUtils.isNotBlank(statusCode)) { // check if status code and acquisition type code combination is valid success &= /*REFACTORME*/SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(AssetGlobal.class, CamsConstants.Parameters.VALID_ASSET_STATUSES_BY_ACQUISITION_TYPE, CamsConstants.Parameters.INVALID_ASSET_STATUSES_BY_ACQUISITION_TYPE, acquisitionTypeCode, statusCode).evaluateAndAddError(AssetGlobal.class, CamsPropertyConstants.AssetGlobal.INVENTORY_STATUS_CODE, MAINTAINABLE_ERROR_PREFIX + CamsPropertyConstants.AssetGlobal.INVENTORY_STATUS_CODE); } success &= validateAssetType(assetGlobal); if (isCapitalStatus(assetGlobal)) { success &= validateVendorAndManufacturer(assetGlobal); } success &= validatePaymentCollection(document, assetGlobal); } else { // append doc type to existing doc header description if (!document.getDocumentHeader().getDocumentDescription().toLowerCase().contains(CamsConstants.AssetSeparate.SEPARATE_AN_ASSET_DESCRIPTION.toLowerCase())) { Integer maxDocumentDescription = ddService.getAttributeMaxLength(DocumentHeader.class, KRADPropertyConstants.DOCUMENT_DESCRIPTION); String documentDescription = CamsConstants.AssetSeparate.SEPARATE_AN_ASSET_DESCRIPTION + " " + document.getDocumentHeader().getDocumentDescription(); documentDescription = StringUtils.left(documentDescription, maxDocumentDescription); document.getDocumentHeader().setDocumentDescription(documentDescription); } } // System shall only generate GL entries if we have an incomeAssetObjectCode for this acquisitionTypeCode and the statusCode // is for capital assets // GLs should not be generated while separating assets too if ((success && !getAssetGlobalService().isAssetSeparate(assetGlobal) && super.processCustomSaveDocumentBusinessRules(document)) && getAssetAcquisitionTypeService().hasIncomeAssetObjectCode(acquisitionTypeCode) && this.isCapitalStatus(assetGlobal)) { if (success &= validateAcquisitionIncomeObjectCode(assetGlobal)) { // create poster AssetGlobalGeneralLedgerPendingEntrySource assetGlobalGlPoster = new AssetGlobalGeneralLedgerPendingEntrySource((FinancialSystemDocumentHeader) document.getDocumentHeader()); // create postables getAssetGlobalService().createGLPostables(assetGlobal, assetGlobalGlPoster); if (SpringContext.getBean(GeneralLedgerPendingEntryService.class).generateGeneralLedgerPendingEntries(assetGlobalGlPoster)) { assetGlobal.setGeneralLedgerPendingEntries(assetGlobalGlPoster.getPendingEntries()); } else { assetGlobalGlPoster.getPendingEntries().clear(); } } } return success; }
Example 15
Source File: ItemService.java From seldon-server with Apache License 2.0 | 4 votes |
private static void truncateItemName(ItemBean itemBean, int newLength) { final String name = itemBean.getName(); final String truncatedName = StringUtils.left(name, newLength); logger.info("Truncating itemBean name '" + name + "' to '" + truncatedName + "'"); itemBean.setName(truncatedName); }
Example 16
Source File: AssetRetirementGlobalRule.java From kfs with GNU Affero General Public License v3.0 | 4 votes |
/** * Processes rules when saving this global. * * @param document MaintenanceDocument type of document to be processed. * @return boolean true when success * @see org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase#processCustomSaveDocumentBusinessRules(org.kuali.rice.kns.document.MaintenanceDocument) */ @Override protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) { boolean valid = true; AssetRetirementGlobal assetRetirementGlobal = (AssetRetirementGlobal) document.getNewMaintainableObject().getBusinessObject(); setupConvenienceObjects(); valid &= assetRetirementValidation(assetRetirementGlobal, document); if ((valid && super.processCustomSaveDocumentBusinessRules(document)) && !getAssetRetirementService().isAssetRetiredByMerged(assetRetirementGlobal) && !allPaymentsFederalOwned(assetRetirementGlobal)) { // Check if Asset Object Code and Object code exists and active. if (valid &= validateObjectCodesForGLPosting(assetRetirementGlobal)) { // create poster AssetRetirementGeneralLedgerPendingEntrySource assetRetirementGlPoster = new AssetRetirementGeneralLedgerPendingEntrySource((FinancialSystemDocumentHeader) document.getDocumentHeader()); // create postables getAssetRetirementService().createGLPostables(assetRetirementGlobal, assetRetirementGlPoster); if (SpringContext.getBean(GeneralLedgerPendingEntryService.class).generateGeneralLedgerPendingEntries(assetRetirementGlPoster)) { assetRetirementGlobal.setGeneralLedgerPendingEntries(assetRetirementGlPoster.getPendingEntries()); } else { assetRetirementGlPoster.getPendingEntries().clear(); } } } // add doc header description if retirement reason is "MERGED" if (CamsConstants.AssetRetirementReasonCode.MERGED.equals(assetRetirementGlobal.getRetirementReasonCode())) { if (!document.getDocumentHeader().getDocumentDescription().toLowerCase().contains(CamsConstants.AssetRetirementGlobal.MERGE_AN_ASSET_DESCRIPTION.toLowerCase())) { Integer maxDocumentDescription = ddService.getAttributeMaxLength(DocumentHeader.class, KRADPropertyConstants.DOCUMENT_DESCRIPTION); String documentDescription = CamsConstants.AssetRetirementGlobal.MERGE_AN_ASSET_DESCRIPTION + " " + document.getDocumentHeader().getDocumentDescription(); documentDescription = StringUtils.left(documentDescription, maxDocumentDescription); document.getDocumentHeader().setDocumentDescription(documentDescription); } } // get asset locks List<Long> capitalAssetNumbers = retrieveAssetNumbersForLocking(assetRetirementGlobal); valid &= !this.getCapitalAssetManagementModuleService().isAssetLocked(capitalAssetNumbers, DocumentTypeName.ASSET_RETIREMENT_GLOBAL, document.getDocumentNumber()); return valid; }
Example 17
Source File: RESTApiFacadeImpl.java From zstack with Apache License 2.0 | 4 votes |
private static String getApiResult(APIEvent e) { String apiResult = RESTApiDecoder.dump(e); apiResult = StringUtils.length(apiResult) > restResultMaxLength ? StringUtils.left(apiResult, restResultMaxLength) : apiResult; return apiResult; }
Example 18
Source File: StringUtil.java From dubbox with Apache License 2.0 | 4 votes |
public static String left(String str, int length) { return StringUtils.left(str, length); }
Example 19
Source File: EBusCommandProcessor.java From openhab1-addons with Eclipse Public License 2.0 | 4 votes |
/** * @param provider * @param itemName * @param type * @return */ public byte[] composeSendData(EBusBindingProvider provider, String itemName, Command command) { if (configurationProvider == null || configurationProvider.isEmpty()) { logger.debug("eBus configuration provider not ready, can't get send data yet."); return null; } byte[] data = null; String cmd = provider.getCommand(itemName); Byte dst = provider.getTelegramDestination(itemName); Byte src = provider.getTelegramSource(itemName); HashMap<String, Object> values = null; if (StringUtils.isEmpty(cmd)) { // use id instead String id = provider.getId(itemName); if (!StringUtils.isEmpty(id)) { String[] split = StringUtils.split(id, "."); if (split.length > 1) { cmd = split[0] + "." + split[1]; } } } if (src == null) { src = connector.getSenderId(); } if (command == null) { // polling data = composeEBusTelegram(cmd, dst, src, values); } else { String setValue = provider.getSet(itemName); int index = StringUtils.lastIndexOf(setValue, "."); String cmdId = StringUtils.left(setValue, index); String valueName = StringUtils.substring(setValue, index + 1); // try to convert command to a supported value Object value = StateUtils.convertFromState(command); if (value != null) { values = new HashMap<String, Object>(); values.put(valueName, value); } data = composeEBusTelegram(cmdId, dst, src, values); } // first try, data-ON, data-OFF, etc. if (data == null) { String type = command != null ? command.toString().toLowerCase() : null; if (StringUtils.isNotEmpty(type)) { data = provider.getTelegramData(itemName, type); } } if (data == null) { // ok, try data param data = provider.getTelegramData(itemName); } return data; }
Example 20
Source File: SolidFirePrimaryDataStoreDriver.java From cloudstack with Apache License 2.0 | 4 votes |
@Override public void takeSnapshot(SnapshotInfo snapshotInfo, AsyncCompletionCallback<CreateCmdResult> callback) { CreateCmdResult result; try { VolumeInfo volumeInfo = snapshotInfo.getBaseVolume(); VolumeVO volumeVO = volumeDao.findById(volumeInfo.getId()); long sfVolumeId = Long.parseLong(volumeVO.getFolder()); long storagePoolId = volumeVO.getPoolId(); SolidFireUtil.SolidFireConnection sfConnection = SolidFireUtil.getSolidFireConnection(storagePoolId, storagePoolDetailsDao); SolidFireUtil.SolidFireVolume sfVolume = SolidFireUtil.getVolume(sfConnection, sfVolumeId); StoragePoolVO storagePool = storagePoolDao.findById(storagePoolId); long capacityBytes = storagePool.getCapacityBytes(); // getUsedBytes(StoragePool) will not include the bytes of the proposed new volume or snapshot because // updateSnapshotDetails has not yet been called for this new volume or snapshot long usedBytes = getUsedBytes(storagePool); long sfVolumeSize = sfVolume.getTotalSize(); usedBytes += sfVolumeSize; // For creating a volume or a snapshot, we need to check to make sure a sufficient amount of space remains in the primary storage. // For the purpose of "charging" these bytes against storage_pool.capacity_bytes, we take the full size of the SolidFire volume // that is serving as the volume the snapshot is of (either a new SolidFire volume or a SolidFire snapshot). if (usedBytes > capacityBytes) { throw new CloudRuntimeException("Insufficient amount of space remains in this primary storage to take a snapshot"); } storagePool.setUsedBytes(usedBytes); SnapshotObjectTO snapshotObjectTo = (SnapshotObjectTO)snapshotInfo.getTO(); if (shouldTakeSnapshot(snapshotInfo.getId())) { // We are supposed to take a SolidFire snapshot to serve as the back-end for our CloudStack volume snapshot. String sfNewSnapshotName = volumeInfo.getName() + "-" + snapshotInfo.getUuid(); int maxSnapshotNameLength = 64; int trimRequired = sfNewSnapshotName.length() - maxSnapshotNameLength; if (trimRequired > 0) { sfNewSnapshotName = StringUtils.left(volumeInfo.getName(), (volumeInfo.getName().length() - trimRequired)) + "-" + snapshotInfo.getUuid(); } long sfNewSnapshotId = SolidFireUtil.createSnapshot(sfConnection, sfVolumeId, SolidFireUtil.getSolidFireVolumeName(sfNewSnapshotName), getSnapshotAttributes(snapshotInfo)); updateSnapshotDetails(snapshotInfo.getId(), volumeInfo.getId(), sfVolumeId, sfNewSnapshotId, storagePoolId, sfVolumeSize); snapshotObjectTo.setPath("SfSnapshotId=" + sfNewSnapshotId); } else { // We are supposed to create a new SolidFire volume to serve as the back-end for our CloudStack volume snapshot. String sfNewVolumeName = volumeInfo.getName() + "-" + snapshotInfo.getUuid(); final Iops iops = getIops(MIN_IOPS_FOR_SNAPSHOT_VOLUME, MAX_IOPS_FOR_SNAPSHOT_VOLUME, storagePoolId); long sfNewVolumeId = SolidFireUtil.createVolume(sfConnection, SolidFireUtil.getSolidFireVolumeName(sfNewVolumeName), sfVolume.getAccountId(), sfVolumeSize, sfVolume.isEnable512e(), getSnapshotAttributes(snapshotInfo), iops.getMinIops(), iops.getMaxIops(), iops.getBurstIops()); SolidFireUtil.SolidFireVolume sfNewVolume = SolidFireUtil.getVolume(sfConnection, sfNewVolumeId); updateSnapshotDetails(snapshotInfo.getId(), sfNewVolumeId, storagePoolId, sfVolumeSize, sfNewVolume.getIqn()); snapshotObjectTo.setPath("SfVolumeId=" + sfNewVolumeId); } // Now that we have successfully created a volume or a snapshot, update the space usage in the cloud.storage_pool table // (even though cloud.storage_pool.used_bytes is likely no longer in use). storagePoolDao.update(storagePoolId, storagePool); CreateObjectAnswer createObjectAnswer = new CreateObjectAnswer(snapshotObjectTo); result = new CreateCmdResult(null, createObjectAnswer); result.setResult(null); } catch (Exception ex) { LOGGER.debug(SolidFireUtil.LOG_PREFIX + "Failed to take CloudStack snapshot: " + snapshotInfo.getId(), ex); result = new CreateCmdResult(null, new CreateObjectAnswer(ex.toString())); result.setResult(ex.toString()); } callback.complete(result); }