Java Code Examples for org.apache.commons.lang3.StringUtils#reverse()
The following examples show how to use
org.apache.commons.lang3.StringUtils#reverse() .
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: jtwig-core File: ReverseFunction.java License: Apache License 2.0 | 6 votes |
@Override public Object execute(FunctionRequest request) { request.minimumNumberOfArguments(1).maximumNumberOfArguments(1); Object input = request.get(0); Converter.Result<WrappedCollection> collectionResult = request.getEnvironment() .getValueEnvironment().getCollectionConverter() .convert(input); if (collectionResult.isDefined()) { return reverse(collectionResult.get().values()); } else if (input instanceof String) { return StringUtils.reverse((String) input); } else { return input; } }
Example 2
Source Project: ari-proxy File: PersistentCache.java License: GNU Affero General Public License v3.0 | 5 votes |
protected Future<HealthReport> provideHealthReport(final String key) { final String testValue = StringUtils.reverse(key); return persistenceStore.set(key, testValue).flatMap(v -> persistenceStore.get(key)).transformValue(tryOfValue -> tryOfValue .map(maybeValue -> maybeValue.map(v -> testValue.equals(v) ? Try.success(HealthReport.ok()) : Try.success(HealthReport.error(String.format("RedisCheck: %s does not match expected %s", v, testValue))) ) .getOrElse(() -> Try.success(HealthReport.error("RedisCheck: empty result on get()")))) .getOrElseGet(t -> Try.success(HealthReport.error("RedisCheck: " + t.getMessage())))); }
Example 3
Source Project: microservice_coffeeshop File: OrderAssembler.java License: Apache License 2.0 | 5 votes |
private String createOrderId(Long userId, String placeholder) { userId = userId == null ? 0 : userId; String user = StringUtils.reverse(String.format("%02d", Long.valueOf(userId.longValue() % 8194))); String random = String.valueOf(Integer.toHexString(secureRandom.nextInt(1000000) + 1234567)); String time = formatter.format(ZonedDateTime.now(CHINA)); String timeStr = Long.toHexString(Long.parseLong(time)); StringBuilder sb = new StringBuilder(); sb.append(user).append(timeStr).append(random).append(placeholder); return sb.toString(); }
Example 4
Source Project: fingen File: NumericEditText.java License: Apache License 2.0 | 5 votes |
/** * Add grouping separators to string * * @param original original string, may already contains incorrect grouping separators * @return string with correct grouping separators */ private String format(final String original) { final String[] parts = original.split("\\" + mDecimalSeparator, -1); String number = parts[0] // since we split with limit -1 there will always be at least 1 part .replaceAll(mNumberFilterRegex, "") .replaceFirst(LEADING_ZERO_FILTER_REGEX, ""); // only add grouping separators for non custom decimal separator if (!hasCustomDecimalSeparator) { // add grouping separators, need to reverse back and forth since Java regex does not support // right to left matching number = StringUtils.reverse( StringUtils.reverse(number).replaceAll("(.{3})", "$1" + GROUPING_SEPARATOR)); // remove leading grouping separator if any number = StringUtils.removeStart(number, String.valueOf(GROUPING_SEPARATOR)); } // add fraction part if any if (parts.length > 1) { if (parts[1].length() > 4) { number += mDecimalSeparator + parts[1].substring(0, 3); } else { number += mDecimalSeparator + parts[1]; } } return number; }
Example 5
Source Project: liiklus File: ExampleRecordPreProcessor.java License: MIT License | 5 votes |
@Override public CompletionStage<Envelope> preProcess(Envelope envelope) { String value = StandardCharsets.UTF_8.decode(envelope.getValue()).toString(); String reversed = StringUtils.reverse(value); return CompletableFuture.completedFuture( envelope.withValue(ByteBuffer.wrap(reversed.getBytes())) ); }
Example 6
Source Project: baleen File: CasRegistryNumber.java License: Apache License 2.0 | 5 votes |
@Override protected Chemical create(JCas jCas, Matcher matcher) { // Check checksum Integer checkDigit = Integer.valueOf(matcher.group(3)); String part1 = matcher.group(1); String part2 = matcher.group(2); part1 = StringUtils.reverse(part1); Integer sum = Integer.valueOf(part2.substring(1, 2)) + (2 * Integer.valueOf(part2.substring(0, 1))); Integer pos = 0; while (pos < part1.length()) { Integer x = Integer.valueOf(part1.substring(pos, pos + 1)); sum += (pos + 3) * x; pos++; } if (sum % 10 != checkDigit) { getMonitor().debug("Pattern matching CAS format found, but check digit is incorrect"); return null; } Chemical c = new Chemical(jCas); c.setSubType("CAS"); return c; }
Example 7
Source Project: CalculatorInputView File: NumericEditText.java License: Apache License 2.0 | 5 votes |
/** * Add grouping separators to string * * @param original original string, may already contains incorrect grouping separators * @return string with correct grouping separators */ private String format(final String original) { final String[] parts = original.split("\\" + mDecimalSeparator, -1); String number = parts[0] // since we split with limit -1 there will always be at least 1 part .replaceAll(mNumberFilterRegex, "") .replaceFirst(LEADING_ZERO_FILTER_REGEX, ""); // only add grouping separators for non custom decimal separator if (!hasCustomDecimalSeparator) { // add grouping separators, need to reverse back and forth since Java regex does not support // right to left matching number = StringUtils.reverse( StringUtils.reverse(number).replaceAll("(.{3})", "$1" + GROUPING_SEPARATOR)); // remove leading grouping separator if any number = StringUtils.removeStart(number, String.valueOf(GROUPING_SEPARATOR)); } // add fraction part if any if (parts.length > 1) { if (parts[1].length() > 2) { number += mDecimalSeparator + parts[1].substring(parts[1].length() - 2, parts[1].length()); } else { number += mDecimalSeparator + parts[1]; } } return number; }
Example 8
Source Project: vscrawler File: Reverse.java License: Apache License 2.0 | 4 votes |
@Override protected String handleSingleStr(String input) { return StringUtils.reverse(input); }
Example 9
Source Project: tutorials File: ReverseStringExamples.java License: MIT License | 4 votes |
public static String reverseUsingApacheCommons(String input) { return StringUtils.reverse(input); }
Example 10
Source Project: tutorials File: StringUtilsUnitTest.java License: MIT License | 4 votes |
@Test public void givenString_whenReversingCharacters_thenCorrect() { String originalString = "baeldung"; String reversedString = StringUtils.reverse(originalString); assertEquals("gnudleab", reversedString); }
Example 11
Source Project: levelup-java-examples File: ReverseAString.java License: Apache License 2.0 | 3 votes |
@Test public void reverse_a_string_with_apache_commons() { String reversedString = StringUtils.reverse(PHRASE); assertEquals(PHRASE_REVERSE, reversedString); }
Example 12
Source Project: incubator-pinot File: StringFunctions.java License: Apache License 2.0 | 2 votes |
/** * @see StringBuilder#reverse() * @param input * @return reversed input in from end to start */ @ScalarFunction static String reverse(String input) { return StringUtils.reverse(input); }