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

The following are Jave code examples for showing how to use rightPad() of the org.apache.commons.lang.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: hadoop-oss   File: TableListing.java   View Source Code Vote up 7 votes
/**
 * Return the ith row of the column as a set of wrapped strings, each at
 * most wrapWidth in length.
 */
String[] getRow(int idx) {
  String raw = rows.get(idx);
  // Line-wrap if it's too long
  String[] lines = new String[] {raw};
  if (wrap) {
    lines = WordUtils.wrap(lines[0], wrapWidth, "\n", true).split("\n");
  }
  for (int i=0; i<lines.length; i++) {
    if (justification == Justification.LEFT) {
      lines[i] = StringUtils.rightPad(lines[i], maxWidth);
    } else if (justification == Justification.RIGHT) {
      lines[i] = StringUtils.leftPad(lines[i], maxWidth);
    }
  }
  return lines;
}
 
Example 2
Project: hadoop   File: TableListing.java   View Source Code Vote up 7 votes
/**
 * Return the ith row of the column as a set of wrapped strings, each at
 * most wrapWidth in length.
 */
String[] getRow(int idx) {
  String raw = rows.get(idx);
  // Line-wrap if it's too long
  String[] lines = new String[] {raw};
  if (wrap) {
    lines = WordUtils.wrap(lines[0], wrapWidth, "\n", true).split("\n");
  }
  for (int i=0; i<lines.length; i++) {
    if (justification == Justification.LEFT) {
      lines[i] = StringUtils.rightPad(lines[i], maxWidth);
    } else if (justification == Justification.RIGHT) {
      lines[i] = StringUtils.leftPad(lines[i], maxWidth);
    }
  }
  return lines;
}
 
Example 3
Project: osc-core   File: DistributedApplianceDtoValidatorTestData.java   View Source Code Vote up 7 votes
static List<Object[]> getInvalidSecretKeyTestData() {
    String[] invalidSecretKeys = new String[]{null, "", StringUtils.rightPad("key", 156, 'e')};

    List<Object[]> result = new ArrayList<Object[]>();

    for(String invalidSecretKey : invalidSecretKeys) {
        DistributedApplianceDto daDto = createDistributedApplianceDto();
        daDto.setSecretKey(invalidSecretKey);

        String errorMessage = "Secret Key " +
                (invalidSecretKey == null || invalidSecretKey.length() < 155 ?
                        EMPTY_VALUE_ERROR_MESSAGE : INVALID_FIELD_LENGTH_ERROR_MESSAGE);

        result.add(new Object[] {daDto,  VmidcBrokerInvalidEntryException.class, errorMessage});
    }

    return result;
}
 
Example 4
Project: osc-core   File: DistributedApplianceDtoValidatorTestData.java   View Source Code Vote up 7 votes
static List<Object[]> getInvalidNameTestData() {
    String[] invalidNames = new String[]{null, "", "1ab", "#bc", "-ab", "ab12_", "ab a", StringUtils.rightPad("dtoName", 14, 'e')};

    List<Object[]> result = new ArrayList<Object[]>();

    for(String invalidName : invalidNames) {
        DistributedApplianceDto daDto = createDistributedApplianceDto();
        daDto.setName(invalidName);
        String errorMessage = invalidName == null || invalidName == "" ?
                "Distributed Appliance Name " + EMPTY_VALUE_ERROR_MESSAGE :
                    "Invalid Distributed Appliance Name: "
                    + invalidName
                    + "DA name must not exceed 13 characters, must start with a letter, and can only contain numbers, letters and dash(-).";

        Class<?> expectedException = invalidName == null || invalidName == "" ?
                VmidcBrokerInvalidEntryException.class : VmidcBrokerValidationException.class;

        result.add(new Object[] {daDto,  expectedException, errorMessage});
    }

    return result;
}
 
Example 5
Project: osc-core   File: VirtualizationConnectorDtoValidatorParameterizedTest.java   View Source Code Vote up 7 votes
static List<Object[]> getInvalidNameTestData() {
    String[] invalidNames = new String[] { null, "",
            StringUtils.rightPad("dtoName", ValidateUtil.DEFAULT_MAX_LEN + 10, 'e') };

    List<Object[]> result = new ArrayList<>();

    for (String invalidName : invalidNames) {
        VirtualizationConnectorDto vcDto = VirtualizationConnectorDtoValidatorTestData.generateOpenStackVCWithoutSDN();
        vcDto.setName(invalidName);
        String errorMessage = invalidName == null || invalidName == ""
                ? Server.PRODUCT_NAME + ": " + "Name " + EMPTY_VALUE_ERROR_MESSAGE
                        : Server.PRODUCT_NAME + ": " + "Name" + " length should not exceed " + ValidateUtil.DEFAULT_MAX_LEN
                        + " characters. The provided field exceeds this limit by "
                        + (invalidName.length() - ValidateUtil.DEFAULT_MAX_LEN) + " characters.";

        Class<?> expectedException = VmidcBrokerInvalidEntryException.class;

        result.add(new Object[] { vcDto, expectedException, errorMessage });
    }

    return result;
}
 
Example 6
Project: osc-core   File: VirtualizationConnectorDtoValidatorParameterizedTest.java   View Source Code Vote up 7 votes
static List<Object[]> getInvalidControllerPasswordTestData() {
    String[] invalidNames = new String[] { null, "",
            StringUtils.rightPad("dtoName", ValidateUtil.DEFAULT_MAX_LEN + 10, 'e') };

    List<Object[]> result = new ArrayList<Object[]>();

    for (String invalidName : invalidNames) {
        VirtualizationConnectorDto vcDto = VirtualizationConnectorDtoValidatorTestData.generateOpenStackVCWithSDN();
        vcDto.setControllerPassword(invalidName);
        String errorMessage = invalidName == null || invalidName == ""
                ? Server.PRODUCT_NAME + ": " + "Controller Password " + EMPTY_VALUE_ERROR_MESSAGE
                        : Server.PRODUCT_NAME + ": " + "Controller Password" + " length should not exceed "
                        + ValidateUtil.DEFAULT_MAX_LEN + " characters. The provided field exceeds this limit by "
                        + (invalidName.length() - ValidateUtil.DEFAULT_MAX_LEN) + " characters.";

        Class<?> expectedException = VmidcBrokerInvalidEntryException.class;

        result.add(new Object[] { vcDto, expectedException, errorMessage });
    }

    return result;
}
 
Example 7
Project: osc-core   File: VirtualizationConnectorDtoValidatorParameterizedTest.java   View Source Code Vote up 7 votes
static List<Object[]> getInvalidProviderPaswordTestData() {
    String[] invalidNames = new String[] { null, "",
            StringUtils.rightPad("dtoName", ValidateUtil.DEFAULT_MAX_LEN + 10, 'e') };

    List<Object[]> result = new ArrayList<Object[]>();

    for (String invalidName : invalidNames) {
        VirtualizationConnectorDto vcDto = VirtualizationConnectorDtoValidatorTestData.generateOpenStackVCWithSDN();
        vcDto.setProviderPassword(invalidName);
        String errorMessage = invalidName == null || invalidName == ""
                ? Server.PRODUCT_NAME + ": " + "Provider Password " + EMPTY_VALUE_ERROR_MESSAGE
                        : Server.PRODUCT_NAME + ": " + "Provider Password" + " length should not exceed "
                        + ValidateUtil.DEFAULT_MAX_LEN + " characters. The provided field exceeds this limit by "
                        + (invalidName.length() - ValidateUtil.DEFAULT_MAX_LEN) + " characters.";

        Class<?> expectedException = VmidcBrokerInvalidEntryException.class;

        result.add(new Object[] { vcDto, expectedException, errorMessage });
    }

    return result;
}
 
Example 8
Project: osc-core   File: VirtualizationConnectorDtoValidatorParameterizedTest.java   View Source Code Vote up 7 votes
static List<Object[]> getInvalidControllerUserNameTestData() throws Exception {
    String[] invalidNames = new String[] { null, "",
            StringUtils.rightPad("dtoName", ValidateUtil.DEFAULT_MAX_LEN + 10, 'e') };

    List<Object[]> result = new ArrayList<Object[]>();

    for (String invalidName : invalidNames) {
        VirtualizationConnectorDto vcDto = VirtualizationConnectorDtoValidatorTestData.generateOpenStackVCWithSDN();
        vcDto.setControllerUser(invalidName);
        String errorMessage = invalidName == null || invalidName == ""
                ? Server.PRODUCT_NAME + ": " + "Controller User Name " + EMPTY_VALUE_ERROR_MESSAGE
                        : Server.PRODUCT_NAME + ": " + "Controller User Name" + " length should not exceed "
                        + ValidateUtil.DEFAULT_MAX_LEN + " characters. The provided field exceeds this limit by "
                        + (invalidName.length() - ValidateUtil.DEFAULT_MAX_LEN) + " characters.";

        Class<?> expectedException = VmidcBrokerInvalidEntryException.class;

        result.add(new Object[] { vcDto, expectedException, errorMessage });
    }

    return result;
}
 
Example 9
Project: osc-core   File: VirtualizationConnectorDtoValidatorParameterizedTest.java   View Source Code Vote up 7 votes
static List<Object[]> getInvalidProviderUserNameTestData() {
    String[] invalidNames = new String[] { null, "",
            StringUtils.rightPad("dtoName", ValidateUtil.DEFAULT_MAX_LEN + 10, 'e') };

    List<Object[]> result = new ArrayList<Object[]>();

    for (String invalidName : invalidNames) {
        VirtualizationConnectorDto vcDto = VirtualizationConnectorDtoValidatorTestData.generateOpenStackVCWithSDN();
        vcDto.setProviderUser(invalidName);
        String errorMessage = invalidName == null || invalidName == ""
                ? Server.PRODUCT_NAME + ": " + "Provider User Name " + EMPTY_VALUE_ERROR_MESSAGE
                        : Server.PRODUCT_NAME + ": " + "Provider User Name" + " length should not exceed "
                        + ValidateUtil.DEFAULT_MAX_LEN + " characters. The provided field exceeds this limit by "
                        + (invalidName.length() - ValidateUtil.DEFAULT_MAX_LEN) + " characters.";

        Class<?> expectedException = VmidcBrokerInvalidEntryException.class;

        result.add(new Object[] { vcDto, expectedException, errorMessage });
    }

    return result;
}
 
Example 10
Project: incubator-servicecomb-java-chassis   File: Impl.java   View Source Code Vote up 6 votes
@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 11
Project: incubator-servicecomb-java-chassis   File: Impl.java   View Source Code Vote up 6 votes
@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 12
Project: incubator-servicecomb-java-chassis   File: Impl.java   View Source Code Vote up 6 votes
@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 13
Project: ralasafe   File: UserTypeManagerImpl.java   View Source Code Vote up 6 votes
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 14
Project: verify-hub   File: MatchingServiceResponseTranslatorResourceTest.java   View Source Code Vote up 6 votes
@Test
public void shouldNotReturnADtoWhenResponseIs_Nonsense() {
    final SamlResponseDto samlResponseDto = new SamlResponseDto(StringUtils.rightPad("test", 2000, "x"));

    Response clientResponse = postToSamlEngine(samlResponseDto);

    assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
    ErrorStatusDto errorStatusDto = clientResponse.readEntity(ErrorStatusDto.class);
    assertThat(errorStatusDto.getExceptionType()).isEqualTo(ExceptionType.INVALID_SAML);
}
 
Example 15
Project: osc-core   File: VirtualizationConnectorDtoValidatorParameterizedTest.java   View Source Code Vote up 6 votes
static List<Object[]> getInvalidMqPortTestData() {
    String[] invalidNames = new String[] { null, "",
            StringUtils.rightPad("dtoName", ValidateUtil.DEFAULT_MAX_LEN + 10, 'e') };

    List<Object[]> result = new ArrayList<>();

    for (String invalidName : invalidNames) {
        VirtualizationConnectorDto vcDto = VirtualizationConnectorDtoValidatorTestData.generateOpenStackVCWithoutSDN();
        vcDto.getProviderAttributes().put(ATTRIBUTE_KEY_RABBITMQ_PORT, invalidName);

        String errorMessage;
        if (invalidName == null || invalidName.equals("")) {
            errorMessage = Server.PRODUCT_NAME + ": " + "Rabbit MQ Port " + EMPTY_VALUE_ERROR_MESSAGE;
        } else if (!StringUtils.isNumeric(invalidName)) {
            errorMessage = ATTRIBUTE_KEY_RABBITMQ_PORT
                    + " expected to be an Integer. Value is: " + invalidName;
        } else {
            errorMessage = Server.PRODUCT_NAME + ": " + ATTRIBUTE_KEY_RABBITMQ_PORT
                    + " length should not exceed " + ValidateUtil.DEFAULT_MAX_LEN
                    + " characters. The provided field exceeds this limit by "
                    + (invalidName.length() - ValidateUtil.DEFAULT_MAX_LEN) + " characters.";
        }

        Class<?> expectedException = VmidcBrokerInvalidEntryException.class;

        result.add(new Object[] { vcDto, expectedException, errorMessage });
    }

    return result;
}
 
Example 16
Project: sql-first-mapper   File: MiscUtils.java   View Source Code Vote up 6 votes
/**
 * Create Javadoc from input string
 *
 * @param query   string to create javadoc from
 * @param padding number of space symbols to pad from the left
 * @return prepared javadoc string
 */
public static String prepareJavadoc(String query, int padding) {
    String pad = StringUtils.rightPad("", padding);
    StringBuilder sb = new StringBuilder(pad + "/**" + "\n");
    String[] spl = query.split("\n");
    for (String string : spl) {
        string = string.replace("*/", "* /").replaceAll("\t", "    ");
        sb.append(pad).append(" * ").append(string).append("\n");
    }
    sb.append(pad).append(" */");
    return sb.toString();

}
 
Example 17
Project: osc-core   File: ApplianceDtoValidatorTest.java   View Source Code Vote up 5 votes
@Test
public void testValidateforCreate_UsingApplianceModelTooLong_ThrowsVmidcBrokerInvalidEntryException() throws Exception {
    ApplianceDto dto = new ApplianceDto(StringUtils.rightPad("m", ValidateUtil.DEFAULT_MAX_LEN + 1, 'e'), UUID.randomUUID().toString(), UUID.randomUUID().toString());
    testValidateforCreate_UsingFieldTooLong_ThrowsVmidcBrokerInvalidEntryException(dto, "Appliance Model");
}
 
Example 18
Project: osc-core   File: ApplianceDtoValidatorTest.java   View Source Code Vote up 5 votes
@Test
public void testValidateforCreate_UsingApplianceManagerVersionTooLong_ThrowsVmidcBrokerInvalidEntryException() throws Exception {
    ApplianceDto dto = new ApplianceDto(UUID.randomUUID().toString(), UUID.randomUUID().toString(), StringUtils.rightPad("m", ValidateUtil.DEFAULT_MAX_LEN + 1, 'e'));
    testValidateforCreate_UsingFieldTooLong_ThrowsVmidcBrokerInvalidEntryException(dto, "Appliance Manager Version");
}
 
Example 19
Project: IOTAFaucet   File: IotaProvider.java   View Source Code Vote up 5 votes
public IotaProvider(IotaAPI iotaAPI, String seed) {
    this.iotaAPI = iotaAPI;
    this.seed = StringUtils.rightPad(seed, 81, "9");
}
 
Example 20
Project: aliyun-maxcompute-data-collectors   File: OraOopUtilities.java   View Source Code Vote up 5 votes
public static String padRight(String s, int n) {
  return StringUtils.rightPad(s, n);
}