List of usage examples for org.apache.commons.lang3 StringUtils reverse
public static String reverse(final String str)
Reverses a String as per StringBuilder#reverse() .
A null String returns null .
StringUtils.reverse(null) = null StringUtils.reverse("") = "" StringUtils.reverse("bat") = "tab"
From source file:com.chiorichan.util.PermissionUtil.java
public static String getLocalName(String permNamespace) { if (!permNamespace.contains(".")) return permNamespace; int inx = StringUtils.reverse(permNamespace).indexOf("."); return permNamespace.substring(permNamespace.length() - inx); }
From source file:apm.common.utils.PrettyTimeUtils.java
/** * ****** ****** 123 10?/*from w ww . java 2s. co m*/ * * @return */ public static final String prettySeconds(int totalSeconds) { StringBuilder s = new StringBuilder(); int second = totalSeconds % 60; if (totalSeconds > 0) { s.append(""); s.append(StringUtils.reverse(String.valueOf(second))); } totalSeconds = totalSeconds / 60; int minute = totalSeconds % 60; if (totalSeconds > 0) { s.append(""); s.append(StringUtils.reverse(String.valueOf(minute))); } totalSeconds = totalSeconds / 60; int hour = totalSeconds % 24; if (totalSeconds > 0) { s.append(StringUtils.reverse("?")); s.append(StringUtils.reverse(String.valueOf(hour))); } totalSeconds = totalSeconds / 24; int day = totalSeconds % 31; if (totalSeconds > 0) { s.append(""); s.append(StringUtils.reverse(String.valueOf(day))); } totalSeconds = totalSeconds / 31; int month = totalSeconds % 12; if (totalSeconds > 0) { s.append(""); s.append(StringUtils.reverse(String.valueOf(month))); } totalSeconds = totalSeconds / 12; int year = totalSeconds; if (totalSeconds > 0) { s.append(""); s.append(StringUtils.reverse(String.valueOf(year))); } return s.reverse().toString(); }
From source file:com.lexicalscope.fluent.StringConverters.java
public static StringConverter<String> reverseString() { return new StringConverter<String>() { @Override/*from w w w .j a v a2s . c o m*/ public String convert(final String from) { return StringUtils.reverse(from); } }; }
From source file:com.inkubator.hrm.util.HrmUserInfoUtil.java
public static Boolean isValidRemoteAddress() throws Exception { HttpServletRequest httpServletRequest = (HttpServletRequest) FacesContext.getCurrentInstance() .getExternalContext().getRequest(); String ipClient = IpUtil.getIpFromRequest(httpServletRequest); String riversIp = StringUtils.reverse(ipClient); String ipHeaderReverse = StringUtils.substringAfter(riversIp, "."); String ipEnd = StringUtils.substringBefore(riversIp, "."); int ipLast = Integer.parseInt(StringUtils.reverse(ipEnd)); LOGGER.info("Nilai Ip " + IpUtil.getIpFromRequest(httpServletRequest)); String ip = StringUtils.remove(ipHeaderReverse, "."); int ipHeader = Integer.parseInt(StringUtils.reverse(ip)); IpPermitService ipPermitService = (IpPermitService) ServiceWebUtil.getService("ipPermitService"); List<IpPermit> dataToCheck = ipPermitService.getByIpHeader(ipHeader); for (IpPermit ipPermit : dataToCheck) { int fromAddres2 = ipPermit.getUntilAddress1(); int untilAddress2 = ipPermit.getUntilAddress2(); if (ipLast >= fromAddres2 && ipLast <= untilAddress2) { return Boolean.TRUE; }//from w ww . j a va 2 s . c o m } return Boolean.FALSE; }
From source file:com.threewks.thundr.pipeline.PipelineTest.java
@Test public void shouldRunBasicPipeline() { // @formatter:off List<String> results = Pipeline.of(new Op<InputStream, String>() { @Override// w w w .j a va2 s . c o m public void process(List<InputStream> in, List<String> into) { InputStream first = in.get(0); String string = readStringFromStream(first); into.addAll(Arrays.asList(StringUtils.split(string, ","))); } }).then(new BaseOp<String, String>() { @Override public String processSingle(String in) { return StringUtils.reverse(in); } }).then(new BaseOp<String, String>() { @Override public String processSingle(String in) { System.out.println(in); return in; } }).list(new ByteArrayInputStream(source.getBytes())); // @formatter:on assertThat(results.size(), is(2)); assertThat(results.get(0), is("tsriF")); assertThat(results.get(1), is("dnoceS")); }
From source file:com.sinpo.xnfc.Util.java
/** * ??/*www . j a v a 2 s . com*/ * @param str * @param blockSize ???? * @return */ public static String reverse(String str, int blockSize) { if (str != null && (str.length() % blockSize) == 0) { Log.d("REVERSE STR", str); String revStr = StringUtils.reverse(str); int len = revStr.length(); StringBuilder r = new StringBuilder(); int start = 0; int end = blockSize; do { r.append(StringUtils.reverse(StringUtils.substring(revStr, start, end))); end += blockSize; start += blockSize; } while (len - end >= 0); return r.toString(); } return null; }
From source file:com.github.jrh3k5.mojo.flume.FlumePluginTest.java
/** * If the artifact ID differs, then the two should not match. *///from w ww . ja v a 2 s. c om @Test public void testMatchesDifferentArtifactId() { when(artifact.getGroupId()).thenReturn(groupId); when(artifact.getArtifactId()).thenReturn(StringUtils.reverse(artifactId)); when(artifact.getClassifier()).thenReturn(classifier); when(artifact.getType()).thenReturn(type); assertThat(flumePlugin.matches(artifact)).isFalse(); }
From source file:com.screenslicer.core.scrape.Dissect.java
private static void dedupStrings(String[] strings, boolean fromLeft) { for (int i = 0; i < strings.length; i++) { if (strings[i] == null || strings[i].trim().isEmpty()) { return; }/*from w w w . j ava 2 s. co m*/ } int len = 0; for (int i = 0; i < strings.length; i++) { strings[i] = " " + (fromLeft ? strings[i] : StringUtils.reverse(strings[i])) + " "; } if (strings != null && strings.length > 0 && strings[0] != null) { for (int i = 0; i < strings[0].length(); i++) { char c = strings[0].charAt(i); boolean match = true; for (int j = 1; j < strings.length; j++) { if (strings[j] == null || i >= strings[j].length() || strings[j].charAt(i) != c) { match = false; break; } } if (match) { ++len; } else { break; } } } for (int i = 0; len > 0 && i < strings.length; i++) { if (!Character.isWhitespace(strings[i].charAt(len - 1))) { --len; i = 0; } } for (int i = 0; len > 0 && i < strings.length; i++) { strings[i] = strings[i].substring(len); } for (int i = 0; i < strings.length; i++) { strings[i] = (fromLeft ? strings[i] : StringUtils.reverse(strings[i])).trim(); } }
From source file:com.github.jrh3k5.mojo.flume.FlumePluginTest.java
/** * If the classifier differs, then the two should not match. *//*from www .ja v a 2s. co m*/ @Test public void testMatchesDifferentClassifier() { when(artifact.getGroupId()).thenReturn(groupId); when(artifact.getArtifactId()).thenReturn(artifactId); when(artifact.getClassifier()).thenReturn(StringUtils.reverse(classifier)); when(artifact.getType()).thenReturn(type); assertThat(flumePlugin.matches(artifact)).isFalse(); }
From source file:de.jcup.egradle.codeassist.RelevantCodeCutter.java
private String getLeftText(String code, int offset) { char[] chars = code.toCharArray(); int start = offset - 1; if (start < 0) { return StringUtils.EMPTY; }/*from w ww. j av a2 s . c o m*/ StringBuilder sb = new StringBuilder(); for (int i = start; i >= 0; i--) { char c = chars[i]; if (isDelimiter(c)) { break; } sb.append(c); } String result = StringUtils.reverse(sb.toString()); return result; }