List of usage examples for org.apache.commons.lang3 StringUtils length
public static int length(final CharSequence cs)
From source file:minor.commodity.CommodityQuote.java
@Override public void validate() { if (StringUtils.isEmpty(getCticker())) { addFieldError("cticker", "Commodity Quote cannot be blank"); }/* w ww.j a v a 2 s. c o m*/ if (StringUtils.isNumeric(getCticker())) { addFieldError("cticker", "Commodity Quote cannot be numeric"); } if (StringUtils.length(getCticker()) > 12) { addFieldError("cticker", "Invalid Ticker length"); } }
From source file:de.dominikschadow.duke.encounters.validators.PasswordChangeValidator.java
@Override public void validate(Object target, Errors errors) { validator.validate(target, errors);// w ww .j av a2s . co m PasswordChange passwordChange = (PasswordChange) target; if (!userService.confirmPassword(passwordChange.getCurrentPassword())) { errors.rejectValue("currentPassword", Constants.CURRENT_PASSWORD_NOT_CORRECT_ERROR_CODE); } if (StringUtils.length(passwordChange.getNewPassword()) < 10) { errors.rejectValue("newPassword", Constants.UNSAFE_PASSWORD_ERROR_CODE); } if (!passwordChange.getNewPassword().equals(passwordChange.getNewPasswordConfirmation())) { errors.rejectValue("newPassword", Constants.PASSWORDS_DONT_MATCH_ERROR_CODE); } }
From source file:com.amazon.speech.speechlet.verifier.OutputSpeechSpeechletResponseVerifier.java
@Override public boolean verify(SpeechletResponseEnvelope responseEnvelope, Session session) { if (responseEnvelope == null || responseEnvelope.getResponse() == null) { return true; }/*w w w . j a v a 2 s . com*/ OutputSpeech outputSpeech = responseEnvelope.getResponse().getOutputSpeech(); String speechContent = null; if (outputSpeech instanceof PlainTextOutputSpeech) { speechContent = ((PlainTextOutputSpeech) outputSpeech).getText(); } else if (outputSpeech instanceof SsmlOutputSpeech) { speechContent = ((SsmlOutputSpeech) outputSpeech).getSsml(); } int speechContentLength = StringUtils.length(speechContent); if (speechContentLength > MAX_SPEECH_SIZE) { log.warn("OutputSpeech with size {} exceeds the maximum allowed size of {} and " + "will be rejected by the Alexa service", speechContentLength, MAX_SPEECH_SIZE); } // We are currently not enforcing response checks. Always return true. return true; }
From source file:com.alibaba.dubbo.qos.textui.TTree.java
@Override public String rendering() { final StringBuilder treeSB = new StringBuilder(); recursive(0, true, "", root, new Callback() { @Override//w w w . j a va 2s. co m public void callback(int deep, boolean isLast, String prefix, Node node) { final boolean hasChild = !node.children.isEmpty(); final String stepString = isLast ? STEP_FIRST_CHAR : STEP_NORMAL_CHAR; final int stepStringLength = StringUtils.length(stepString); treeSB.append(prefix).append(stepString); int costPrefixLength = 0; if (hasChild) { treeSB.append("+"); } if (isPrintCost && !node.isRoot()) { final String costPrefix = String.format("[%s,%sms]", (node.endTimestamp - root.beginTimestamp), (node.endTimestamp - node.beginTimestamp)); costPrefixLength = StringUtils.length(costPrefix); treeSB.append(costPrefix); } final Scanner scanner = new Scanner(new StringReader(node.data.toString())); try { boolean isFirst = true; while (scanner.hasNextLine()) { if (isFirst) { treeSB.append(scanner.nextLine()).append("\n"); isFirst = false; } else { treeSB.append(prefix).append(repeat(' ', stepStringLength)) .append(hasChild ? "|" : EMPTY).append(repeat(' ', costPrefixLength)) .append(scanner.nextLine()).append("\n"); } } } finally { scanner.close(); } } }); return treeSB.toString(); }
From source file:io.github.lxgaming.teleportbow.commands.AbstractCommand.java
@Override public final Optional<Text> getShortDescription(CommandSource commandSource) { if (StringUtils.length(getDescription()) > 53) { return Optional.of(Text.of(StringUtils.substring(getDescription(), 0, 50), "...")); }//from w w w. j a v a2 s. c om return Optional.of(Text.of(StringUtils.defaultIfBlank(getDescription(), "No description provided"))); }
From source file:ch.cyberduck.core.http.LoggingHttpRequestExecutor.java
@Override protected HttpResponse doSendRequest(final HttpRequest request, final HttpClientConnection conn, final HttpContext context) throws IOException, HttpException { synchronized (listener) { listener.log(TranscriptListener.Type.request, request.getRequestLine().toString()); for (Header header : request.getAllHeaders()) { switch (header.getName()) { case HttpHeaders.AUTHORIZATION: case "X-Auth-Key": case "X-Auth-Token": listener.log(TranscriptListener.Type.request, String.format("%s: %s", header.getName(), StringUtils.repeat("*", Integer.min(8, StringUtils.length(header.getValue()))))); break; default: listener.log(TranscriptListener.Type.request, header.toString()); break; }/*from w ww . j a v a 2 s. c o m*/ } } return super.doSendRequest(request, conn, context); }
From source file:com.adguard.filter.rules.FilterRule.java
/** * Creates filter rule./*www . ja va 2s. c o m*/ * If this rule text is not valid - returns null. * * @param ruleText Rule text * @return Filter rule of the proper type */ public static FilterRule createRule(String ruleText) { ruleText = StringUtils.trim(ruleText); if (StringUtils.isBlank(ruleText) || StringUtils.length(ruleText) < MIN_RULE_LENGTH || StringUtils.startsWith(ruleText, COMMENT) || StringUtils.startsWith(ruleText, META_START) || StringUtils.contains(ruleText, MASK_OBSOLETE_SCRIPT_INJECTION) || StringUtils.contains(ruleText, MASK_OBSOLETE_STYLE_INJECTION)) { return null; } try { if (StringUtils.startsWith(ruleText, MASK_WHITE_LIST)) { return new UrlFilterRule(ruleText); } if (StringUtils.contains(ruleText, MASK_CONTENT_RULE)) { return new ContentFilterRule(ruleText); } if (StringUtils.contains(ruleText, MASK_CSS_RULE) || StringUtils.contains(ruleText, MASK_CSS_EXCEPTION_RULE) || StringUtils.contains(ruleText, MASK_CSS_INJECT_RULE) || StringUtils.contains(ruleText, MASK_CSS_INJECT_EXCEPTION_RULE)) { return new CssFilterRule(ruleText); } if (StringUtils.contains(ruleText, MASK_SCRIPT_RULE)) { return new ScriptFilterRule(ruleText); } return new UrlFilterRule(ruleText); } catch (Exception ex) { LoggerFactory.getLogger(FilterRule.class).warn("Error creating filter rule {}:\r\n{}", ruleText, ex); return null; } }
From source file:com.santhoshknn.sudoku.GridExtractor.java
/** * Parses the supplied input to extract a 9x9 grid of integers substituting * the supplied x with a 0// w ww . j a va 2s . co m * * @param input * @return extracted gridresponse */ public GridResponse parse(final String input) { int[][] grid = new int[9][9]; String error = null; GridResponse response = new GridResponse(); log.info("Parsing supplied input string to create sudoku grid"); // Strip whitespaces if any String sanitized = StringUtils.deleteWhitespace(input); // Fail early. Check if the length is 161 (81 + 80 commas) if (StringUtils.isBlank(sanitized) || StringUtils.length(sanitized) != GRID_SIZE) { error = INPUT_LENGTH_INVALID; } else { String[] tokens = sanitized.split(","); int row = 0, col = 0; for (int k = 0; k < 81; k++) { // tokens = 81 if (StringUtils.equals("x", tokens[k])) grid[row][col] = 0; else if (StringUtils.isNumeric(tokens[k])) { // What if the user enters a number > 9? However, accept 0 // since it could mean an empty cell int number = Integer.parseInt(tokens[k]); if (number > 9) { error = INVALID_NUMBER_ERROR + ":" + number; break; } grid[row][col] = number; } else { // Invalid character. Fail error = INVALID_CHAR_ERROR; break; } col++; if ((k + 1) % 9 == 0) { // Update row & reset column row++; col = 0; } } } if (null == error) response.setGrid(grid); else { response.setError(error); log.error(error); } return response; }
From source file:de.jfachwert.pruefung.Mod10Verfahren.java
/** * Liefert true zurueck, wenn der uebergebene Wert gueltig ist. * * @param wert Fachwert oder gekapselter Wert * @return true oder false//www. ja va 2s . c o m */ @Override public boolean isValid(String wert) { if (StringUtils.length(wert) < 1) { return false; } else { return getPruefziffer(wert).equals(berechnePruefziffer(wert.substring(0, wert.length() - 1))); } }
From source file:com.amazon.speech.speechlet.verifier.CardSpeechletResponseVerifier.java
/** * Checks the length of the card elements and it logs a warning if the card size exceeds * {@value #MAX_CARD_SIZE} characters.// ww w . j ava2s . c om * * @param cardElements * the elements of the card */ private void verifyCardSize(String... cardElements) { int cardSize = 0; for (String element : cardElements) { cardSize += StringUtils.length(element); } if (cardSize > MAX_CARD_SIZE) { log.warn("Card with size {} exceeds the maximum allowed size of {} and will be " + "rejected by the Alexa service", cardSize, MAX_CARD_SIZE); } }