下面列出了org.apache.commons.lang3.StringUtils#isAlpha ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Extract unit and actual value from resource value.
* @param resourceValue Value of the resource
* @return Array containing unit and value. [0]=unit, [1]=value
* @throws IllegalArgumentException if units contain non alpha characters
*/
private static String[] parseResourceValue(String resourceValue) {
String[] resource = new String[2];
int i = 0;
for (; i < resourceValue.length(); i++) {
if (Character.isAlphabetic(resourceValue.charAt(i))) {
break;
}
}
String units = resourceValue.substring(i);
if (StringUtils.isAlpha(units) || units.equals("")) {
resource[0] = units;
resource[1] = resourceValue.substring(0, i);
return resource;
} else {
throw new IllegalArgumentException("Units '" + units + "'"
+ " contains non alphabet characters, which is not allowed.");
}
}
@Nullable
private Tuple2<Integer, String> getInsertionPointAndQuery(int searchPoint) {
String input = myCodeArea.getText();
int insertionPoint = getInsertionPoint(searchPoint, input);
if (searchPoint > input.length()) {
searchPoint = input.length();
}
if (insertionPoint > searchPoint) {
new StringIndexOutOfBoundsException("Cannot extract query from subtext \"" + input.substring(0, insertionPoint) + "\"").printStackTrace();
return null;
}
// don't trim, if there is any whitespace we abort
input = input.substring(insertionPoint, searchPoint);
return StringUtils.isAlpha(input) ? Tuples.t(insertionPoint, input.trim()) : null;
}
public static String patchVersion(String modVersion) {
modVersion = modVersion.replaceAll(Pattern.quote("(" + NEMChecker.getMcVersion() + ")"), "");
modVersion = modVersion.replaceAll(Pattern.quote("[" + NEMChecker.getMcVersion() + "]"), "");
modVersion = modVersion.replaceAll("[\\)\\]]", "").replaceAll("[\\(\\[]", ".");
modVersion = modVersion.replaceAll(Pattern.quote("_" + NEMChecker.getMcVersion()), "");
modVersion = modVersion.replaceAll(Pattern.quote(NEMChecker.getMcVersion() + "_"), "");
modVersion = modVersion.replaceAll(Pattern.quote(NEMChecker.getMcVersion() + "-"), "");
modVersion = modVersion.replaceAll("^v", "").replaceAll("^V", "");
modVersion = modVersion.replaceAll(" build ", ".").replaceAll("\\s","");
int index = modVersion.lastIndexOf('-');
if (index != -1)
{
String lastPart = modVersion.substring(index + 1);
if (StringUtils.isAlpha(lastPart))
modVersion = modVersion.substring(0, index);
}
return modVersion;
}
public static boolean isAlpha(Object obj) {
if (obj == null){
return false;
}
if (!(obj instanceof String)){
return false;
}
String s = obj.toString();
if ("".equals(s)) {
return false;
}
return StringUtils.isAlpha(s);
}
@Override
public Iterable<Customer> findCustomersByFNameLName(String firstName, String lastName) throws CustomerSerivceClientException {
if(StringUtils.isEmpty(firstName) || StringUtils.isEmpty(lastName)) {
throw new CustomerSerivceClientException("Missing required parameter!");
} else if (!StringUtils.isAlpha(firstName) || !StringUtils.isAlpha(lastName)) {
throw new CustomerSerivceClientException("First and/or last name is not in proper format!");
}
return repo.findCustomersByFirstNameAndLastName(firstName, lastName);
}
@Override
public Iterable<Customer> findCustomersByFNameLName(String firstName, String lastName) throws CustomerSerivceClientException {
if(StringUtils.isEmpty(firstName) || StringUtils.isEmpty(lastName)) {
throw new CustomerSerivceClientException("Missing required parameter!");
} else if (!StringUtils.isAlpha(firstName) || !StringUtils.isAlpha(lastName)) {
throw new CustomerSerivceClientException("First and/or last name is not in proper format!");
}
return repo.findCustomersByFirstNameAndLastName(firstName, lastName);
}
@Override
public Iterable<Customer> findCustomersByFNameLName(String firstName, String lastName) throws CustomerSerivceClientException {
if(StringUtils.isEmpty(firstName) || StringUtils.isEmpty(lastName)) {
throw new CustomerSerivceClientException("Missing required parameter!");
} else if (!StringUtils.isAlpha(firstName) || !StringUtils.isAlpha(lastName)) {
throw new CustomerSerivceClientException("First and/or last name is not in proper format!");
}
return repo.findCustomersByFirstNameAndLastName(firstName, lastName);
}
public Boolean isAlpha(String text) {
if (text == null) {
return null;
}
return StringUtils.isAlpha(text);
}
public static boolean isAlpha(Object obj) {
if (obj == null){
return false;
}
if (!(obj instanceof String)){
return false;
}
String s = obj.toString();
if ("".equals(s)) {
return false;
}
return StringUtils.isAlpha(s);
}
/**
* Initializes the call button.
*/
private void initSMSButton()
{
if(parentWindow.hasOperationSet(OperationSetSmsMessaging.class)
&& !StringUtils.isAlpha(parentWindow.getCurrentSearchText()))
{
if (smsButton != null && smsButton.getParent() != null)
return;
smsButton = new JButton(GuiActivator.getResources()
.getI18NString("service.gui.SEND_SMS"));
smsButton.setIcon(GuiActivator.getResources()
.getImage("service.gui.icons.SMS_BUTTON_ICON"));
buttonPanel.add(smsButton);
smsButton.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
final String searchText
= parentWindow.getCurrentSearchText();
if(searchText == null)
return;
SMSManager.sendSMS(smsButton, searchText);
}
});
}
else
{
if(smsButton != null)
buttonPanel.remove(smsButton);
}
}
@Override
protected boolean handle(CharSequence str) {
return StringUtils.isAlpha(str);
}