Java Code Examples for org.apache.commons.lang.StringUtils#rightPad()

The following examples show how to use org.apache.commons.lang.StringUtils#rightPad() . These examples are extracted from open source projects. 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 Project: hop   File: WidgetUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static CTabFolder createTabFolder( Composite composite, FormData fd, String... titles ) {
  Composite container = new Composite( composite, SWT.NONE );
  WidgetUtils.setFormLayout( container, 0 );
  container.setLayoutData( fd );

  CTabFolder tabFolder = new CTabFolder( container, SWT.NONE );
  tabFolder.setLayoutData( new FormDataBuilder().fullSize().result() );

  for ( String title : titles ) {
    if ( title.length() < 8 ) {
      title = StringUtils.rightPad( title, 8 );
    }
    Composite tab = new Composite( tabFolder, SWT.NONE );
    WidgetUtils.setFormLayout( tab, ConstUi.MEDUIM_MARGIN );

    CTabItem tabItem = new CTabItem( tabFolder, SWT.NONE );
    tabItem.setText( title );
    tabItem.setControl( tab );
  }

  tabFolder.setSelection( 0 );
  return tabFolder;
}
 
Example 2
Source Project: openhab1-addons   File: API.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Constructor for Serial Connection
 *
 * @param sPort
 * @param baud
 */
public API(String sPort, int baud, String userCode, DSCAlarmInterfaceType interfaceType) {
    if (StringUtils.isNotBlank(sPort)) {
        serialPort = sPort;
    }

    if (isValidBaudRate(baud)) {
        baudRate = baud;
    }

    if (StringUtils.isNotBlank(userCode)) {
        this.dscAlarmUserCode = userCode;
    }

    // The IT-100 requires 6 digit codes. Shorter codes are right padded with 0.
    this.dscAlarmUserCode = StringUtils.rightPad(dscAlarmUserCode, 6, '0');

    connectorType = DSCAlarmConnectorType.SERIAL;

    if (interfaceType != null) {
        this.interfaceType = interfaceType;
    } else {
        this.interfaceType = DSCAlarmInterfaceType.IT100;
    }
}
 
Example 3
public static String multipleLineRightPad(String field, int LINE_LENGTH, char fillPaddingWith) {
    if (!StringUtils.isEmpty(field) && !field.endsWith(" ")) {
        field += " ";
    }

    if (field.length() < LINE_LENGTH) {
        return StringUtils.rightPad(field, LINE_LENGTH, fillPaddingWith);
    } else {
        final List<String> words = Arrays.asList(field.split(" "));
        int currentLineLength = 0;
        String result = "";

        for (final String word : words) {
            final String toAdd = word + " ";

            if (currentLineLength + toAdd.length() > LINE_LENGTH) {
                result = StringUtils.rightPad(result, LINE_LENGTH, fillPaddingWith) + '\n';
                currentLineLength = toAdd.length();
            } else {
                currentLineLength += toAdd.length();
            }

            result += toAdd;
        }

        if (currentLineLength < LINE_LENGTH) {
            return StringUtils.rightPad(result, result.length() + (LINE_LENGTH - currentLineLength), fillPaddingWith);
        }

        return result;
    }
}
 
Example 4
Source Project: servicecomb-java-chassis   File: Impl.java    License: Apache License 2.0 5 votes vote down vote up
@RequestMapping(path = "/channel/news/subscribe", method = RequestMethod.POST)
public AppClientDataRsp subscribeNewsColumn(@RequestBody ChannelRequestBase request) {
  AppClientDataRsp response = new AppClientDataRsp();
  String rsp = StringUtils.rightPad("edge test", 1024, "*");
  response.setRsp(rsp);
  return response;
}
 
Example 5
Source Project: ralasafe   File: UserTypeManagerImpl.java    License: MIT License 5 votes vote down vote up
private void preModify( UserType userType ) {
	String xml = getUserMetadataXML(userType);
	if( xml.length()>=1000&&xml.length()<=2000 ) {
		xml=StringUtils.rightPad( xml, 4000-xml.length() );
	}
	
	userType.setUserMetadataXML(xml);
}
 
Example 6
/**
 * Convert the user input as an Object, it returns a String that matches the input with a right padding. The padding attribute is given as a converter
 * parameter, the default padding character is ' '.
 */
public Object getAsObject(FacesContext context, UIComponent component, String value) {
    if (context == null || component == null) {
        throw new NullPointerException();
    }
    int padding = getPadding(context, component);
    if (StringUtils.isBlank(value)) {
        return StringUtils.rightPad("", padding);
    }
    return StringUtils.rightPad(value, padding);
}
 
Example 7
@Override
public String toString()
{
  return StringUtils.leftPad(getNo(), 4)
      + " "
      + StringUtils.rightPad(getTitle(), 20)
      + " "
      + StringUtils.leftPad(CurrencyFormatter.format(getAmount()), 18);
  /*
   * StringBuffer buf = new StringBuffer(); buf.append(row); for (KontoUmsatz umsatz : kontoUmsaetze) { buf.append("\n ");
   * buf.append(umsatz.toString()); } return buf.toString();
   */
}
 
Example 8
public static String getSpaceFinancialSystemOriginationCode() {
    if (SPACE_FINANCIAL_SYSTEM_ORIGINATION_CODE == null) {
        SPACE_FINANCIAL_SYSTEM_ORIGINATION_CODE = StringUtils.rightPad("", SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength(OriginationCode.class, KFSPropertyConstants.FINANCIAL_SYSTEM_ORIGINATION_CODE), ' ');
    }
    return SPACE_FINANCIAL_SYSTEM_ORIGINATION_CODE;
}
 
Example 9
public static String getSpaceBalanceTypeCode() {
    if (SPACE_BALANCE_TYPE_CODE == null) {
        SPACE_BALANCE_TYPE_CODE = StringUtils.rightPad("", SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength(BalanceType.class, KFSPropertyConstants.CODE), ' ');
    }
    return SPACE_BALANCE_TYPE_CODE;
}
 
Example 10
public static String getDashOrganizationReferenceId() {
    if (DASH_ORGANIZATION_REFERENCE_ID == null) {
        DASH_ORGANIZATION_REFERENCE_ID = StringUtils.rightPad("", SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength(OriginEntryFull.class, KFSPropertyConstants.ORGANIZATION_REFERENCE_ID), '-');
    }
    return DASH_ORGANIZATION_REFERENCE_ID;
}
 
Example 11
public static String getDashFinancialObjectCode() {
    if (DASH_FINANCIAL_OBJECT_CODE == null) {
        DASH_FINANCIAL_OBJECT_CODE = StringUtils.rightPad("", SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength(OriginEntryFull.class, KFSPropertyConstants.FINANCIAL_OBJECT_CODE), '-');
    }
    return DASH_FINANCIAL_OBJECT_CODE;
}
 
Example 12
public static String getSpaceUniversityFiscalYear() {
    if (SPACE_UNIVERSITY_FISCAL_YEAR == null) {
        SPACE_UNIVERSITY_FISCAL_YEAR = StringUtils.rightPad("", SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength(OriginEntryFull.class, KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR), ' ');
    }
    return SPACE_UNIVERSITY_FISCAL_YEAR;
}
 
Example 13
Source Project: oodt   File: StdCmdLinePrinter.java    License: Apache License 2.0 4 votes vote down vote up
protected String getOptionHelp(CmdLineOption option, String indent) {
   String argName = option.hasArgs() ? " <" + option.getArgsDescription()
         + ">" : "";
   String optionUsage = indent
         + "-"
         + StringUtils.rightPad(option.getShortOption() + ",", 7)
         + "--"
         + StringUtils.rightPad((option.getLongOption() + argName),
               49 - indent.length()) + option.getDescription();

   optionUsage = " " + optionUsage;

   if (!option.getRequirementRules().isEmpty()) {
      optionUsage += "\n"
            + getFormattedString("Requirement Rules:", 62, 113)
            + getFormattedString(option.getRequirementRules().toString(),
                  63, 113);
   }

   if (option instanceof AdvancedCmdLineOption) {
      if (((AdvancedCmdLineOption) option).hasHandler()) {
         String handlerHelp = ((AdvancedCmdLineOption) option).getHandler()
               .getHelp(option);
         if (handlerHelp != null) {
            optionUsage += "\n"
                  + getFormattedString("Handler:", 62, 113)
                  + getFormattedString(handlerHelp, 63, 113);
         }
      }
   } else if (isGroupOption(option)) {
      GroupCmdLineOption groupOption = asGroupOption(option);
      optionUsage += "\n";
      optionUsage += "   SubOptions:\n";
      optionUsage += "   > Required:\n";

      List<CmdLineOption> optionalOptions = Lists.newArrayList();
      for (GroupSubOption subOption : groupOption.getSubOptions()) {
         if (subOption.isRequired()) {
            optionUsage += getOptionHelp(subOption.getOption(), "     ");
         } else {
            optionalOptions.add(subOption.getOption());
         }
      }
      optionUsage += "   > Optional:\n";
      for (CmdLineOption optionalOption : optionalOptions) {
         optionUsage += getOptionHelp(optionalOption, "     ");
      }
   }

   return optionUsage;
}
 
Example 14
public static String getZeroTransactionEntrySequenceNumber() {
    if (ZERO_TRANSACTION_ENTRY_SEQUENCE_NUMBER == null) {
        ZERO_TRANSACTION_ENTRY_SEQUENCE_NUMBER = StringUtils.rightPad("", SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength(OriginEntryFull.class, KFSPropertyConstants.TRANSACTION_ENTRY_SEQUENCE_NUMBER), '0');
    }
    return ZERO_TRANSACTION_ENTRY_SEQUENCE_NUMBER;
}
 
Example 15
public DELTA_RESULT_TYPE do_add_delta(Connection conn,String key,int nkey,boolean incr,long delta,byte[] buf,long hv) throws IOException{
	Long value;
	long ptr;
	int res;
	long cas = (long) JcacheContext.getLocal("cas");
			
	long it = items.do_item_get(key, nkey, hv, conn);
	if(it==0){
		return DELTA_RESULT_TYPE.DELTA_ITEM_NOT_FOUND;
	}
	
	if(cas!=0&&ItemUtil.ITEM_get_cas(it)!=cas){
		items.do_item_remove(it);
		return DELTA_RESULT_TYPE.DELTA_ITEM_CAS_MISMATCH;
	}
	
	ptr = ItemUtil.ITEM_data(it);
	
	String itvalue = new String(ItemUtil.getValue(it));
	Pattern pattern = Pattern.compile("[0-9]*");
	Matcher isNum = pattern.matcher(itvalue);
	
	if(!isNum.matches()){
		items.do_item_remove(it);
		return DELTA_RESULT_TYPE.NON_NUMERIC;
	}else{
		value = Long.valueOf(itvalue);
	}
	
	if(incr){
		value += delta;
	}else{
		if(delta > value){
			value  = 0L;
		}else{
			value -= delta;
		}
	}
	System.arraycopy(BytesUtil.LongToBytes(value), 0, buf, 0, 8);
	byte[] valueByte = value.toString().getBytes(JcacheGlobalConfig.defaultCahrset);
	res = valueByte.length;
	/* refcount == 2 means we are the only ones holding the item, and it is
     * linked. We hold the item's lock in this function, so refcount cannot
     * increase. */
	if((res +2) <= ItemUtil.getNbytes(it) && ItemUtil.getRefCount(it)==2){
		/* When changing the value without replacing the item, we
           need to update the CAS on the existing item. */
        /* We also need to fiddle it in the sizes tracker in case the tracking
         * was enabled at runtime, since it relies on the CAS value to know
         * whether to remove an item or not. */
		items.item_stats_sizes_remove(it);
		ItemUtil.ITEM_set_cas(it, Settings.useCas?items.get_cas_id():0);
		items.item_stats_sizes_add(it);
		
		String pad = StringUtils.rightPad("", ItemUtil.getNbytes(it)-2-res, ' '); 
		UnSafeUtil.setBytes(ItemUtil.ITEM_data(it),
							(value.toString() + pad).getBytes(JcacheGlobalConfig.defaultCahrset),
							0, 
							ItemUtil.getNbytes(it)-2);
		
		items.do_item_update(it);
	}else if(ItemUtil.getRefCount(it)>1){
		long new_it;
		int flags = ItemUtil.ITEM_suffix_flags(it);
		new_it = items.do_item_alloc(key, nkey, flags, ItemUtil.getExpTime(it), res+2);
		if(new_it==0){
			items.do_item_remove(it);
			return DELTA_RESULT_TYPE.EOM;
		}
		ItemUtil.setValue(new_it, (value.toString() + "\r\n").getBytes(JcacheGlobalConfig.defaultCahrset));
		item_replace(it, new_it, hv);
		// Overwrite the older item's CAS with our new CAS since we're
        // returning the CAS of the old item below.
		ItemUtil.ITEM_set_cas(it, Settings.useCas?ItemUtil.ITEM_get_cas(new_it):0);
		items.do_item_remove(new_it);   /* release our reference */  
	}else{
		
		if(ItemUtil.getRefCount(it)==1){
			items.do_item_remove(it);
		}
		return DELTA_RESULT_TYPE.DELTA_ITEM_NOT_FOUND;
	}
	
	if(cas >0){
		JcacheContext.setLocal("cas", ItemUtil.ITEM_get_cas(it));/* swap the incoming CAS value */
	}
	items.do_item_remove(it);
	return DELTA_RESULT_TYPE.OK;
}
 
Example 16
public static String multipleLineRightPadWithSuffix(String field, int LINE_LENGTH, char fillPaddingWith, String suffix) {
    if (!StringUtils.isEmpty(field) && !field.endsWith(" ")) {
        field += " ";
    }

    if (StringUtils.isEmpty(suffix)) {
        return multipleLineRightPad(field, LINE_LENGTH, fillPaddingWith);
    } else if (!suffix.startsWith(" ")) {
        suffix = " " + suffix;
    }

    int LINE_LENGTH_WITH_SUFFIX = LINE_LENGTH - suffix.length();

    if (field.length() < LINE_LENGTH_WITH_SUFFIX) {
        return FenixStringTools.rightPad(field, LINE_LENGTH_WITH_SUFFIX, fillPaddingWith) + suffix;
    } else {
        final List<String> words = Arrays.asList(field.split(" "));
        int currentLineLength = 0;
        String result = "";

        for (final String word : words) {
            final String toAdd = word + " ";

            if (currentLineLength + toAdd.length() > LINE_LENGTH) {
                result = StringUtils.rightPad(result, LINE_LENGTH, ' ') + '\n';
                currentLineLength = toAdd.length();
            } else {
                currentLineLength += toAdd.length();
            }

            result += toAdd;
        }

        if (currentLineLength < LINE_LENGTH_WITH_SUFFIX) {
            return FenixStringTools.rightPad(result, result.length() + (LINE_LENGTH_WITH_SUFFIX - currentLineLength),
                    fillPaddingWith) + suffix;
        } else {
            return FenixStringTools.rightPad(result, result.length() + (LINE_LENGTH - currentLineLength), fillPaddingWith)
                    + "\n" + StringUtils.leftPad(suffix, LINE_LENGTH, fillPaddingWith);
        }
    }
}
 
Example 17
Source Project: tajo   File: TimeValue.java    License: Apache License 2.0 4 votes vote down vote up
public void setSecondsFraction(String secondsFraction) {
  this.secondsFraction = StringUtils.rightPad(secondsFraction, 3, '0');
}
 
Example 18
public String toString()
{
  String txt = StringUtils.abbreviate(bezeichnung, 30);
  return StringUtils.leftPad(NumberHelper.getAsString(konto), 5) + " " + StringUtils.rightPad(txt, 30);
}
 
Example 19
public static String getBlankFinancialSubObjectCode() {
    if (BLANK_SUB_OBJECT_CODE == null) {
        BLANK_SUB_OBJECT_CODE = StringUtils.rightPad("", SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength(GeneralLedgerPendingEntry.class, KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE), '-');
    }
    return BLANK_SUB_OBJECT_CODE;
}
 
Example 20
public static String getDashPositionNumber() {
    if (DASH_POSITION_NUMBER == null) {
        DASH_POSITION_NUMBER = StringUtils.rightPad("", SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength(LaborOriginEntry.class, KFSPropertyConstants.POSITION_NUMBER), '-');
    }
    return DASH_POSITION_NUMBER;
}