List of usage examples for org.apache.commons.lang3 StringUtils substringBefore
public static String substringBefore(final String str, final String separator)
Gets the substring before the first occurrence of a separator.
From source file:net.sf.dynamicreports.design.transformation.chartcustomizer.PercentageGroupedCategoryDataset.java
@Override public Number getValue(int row, int column) { double total = 0; String group1 = StringUtils.substringBefore((String) getRowKey(row), GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY); for (int i = 0; i < getRowCount(); i++) { Number value = dataset.getValue(i, column); if (value != null) { String group2 = StringUtils.substringBefore((String) getRowKey(i), GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY); if (group1.equals(group2)) { total += value.doubleValue(); }//w w w . ja v a 2s. co m } } Number value = dataset.getValue(row, column); if (value == null) { return 0; } double actual = value.doubleValue(); if (total > 0) { return actual / total * 100; } return 0; }
From source file:com.quancheng.saluki.core.grpc.client.internal.GrpcStubClient.java
@SuppressWarnings("unchecked") @Override// www .j a v a 2 s . c om public AbstractStub getGrpcClient(ChannelPool channelPool, int callType, int callTimeout) { String stubClassName = GrpcStubClient.this.getStubClassName(); Channel channel = null; if (StringUtils.contains(stubClassName, "$")) { try { String parentName = StringUtils.substringBefore(stubClassName, "$"); Class<?> clzz = ReflectUtils.name2class(parentName); Method method; switch (callType) { case Constants.RPCTYPE_ASYNC: method = clzz.getMethod("newFutureStub", io.grpc.Channel.class); break; case Constants.RPCTYPE_BLOCKING: method = clzz.getMethod("newBlockingStub", io.grpc.Channel.class); break; default: method = clzz.getMethod("newFutureStub", io.grpc.Channel.class); break; } channel = channelPool.borrowChannel(null); AbstractStub stubInstance = (AbstractStub) method.invoke(null, channel); return stubInstance; } catch (Exception e) { throw new IllegalArgumentException("stub definition not correctdo not edit proto generat file", e); } finally { if (channel != null) { channelPool.returnChannel(null, channel); } } } else { throw new IllegalArgumentException("stub definition not correctdo not edit proto generat file"); } }
From source file:com.coffeebeans.services.api.security.CoffeeBeansPrincipal.java
public CoffeeBeansPrincipal(String email, String username) { this.email = email; this.username = StringUtils.defaultIfEmpty(username, StringUtils.substringBefore(email, "@")); }
From source file:de.blizzy.documentr.markdown.macro.impl.GoogleDocsMacro.java
@Override public String getHtml(IMacroContext macroContext) { String macroParams = macroContext.getParameters(); String googleUrl = StringUtils.substringBefore(macroParams, " ").trim(); //$NON-NLS-1$ String width = StringUtils.substringAfter(macroParams, " ").trim(); //$NON-NLS-1$ UriComponents uriComponents = UriComponentsBuilder.fromHttpUrl(googleUrl).build(); String path = uriComponents.getPath(); MultiValueMap<String, String> params = uriComponents.getQueryParams(); if (path.startsWith("/spreadsheet/")) { //$NON-NLS-1$ String key = params.get("key").get(0); //$NON-NLS-1$ UriComponents components = UriComponentsBuilder.fromHttpUrl("https://docs.google.com/spreadsheet/pub") //$NON-NLS-1$ .queryParam("key", key) //$NON-NLS-1$ .queryParam("output", "html") //$NON-NLS-1$ //$NON-NLS-2$ .queryParam("widget", "true") //$NON-NLS-1$ //$NON-NLS-2$ .build();//from ww w .j a v a 2s .c o m return buildIframe(components); } else if (path.startsWith("/document/")) { //$NON-NLS-1$ String id = params.get("id").get(0); //$NON-NLS-1$ UriComponents components = UriComponentsBuilder.fromHttpUrl("https://docs.google.com/document/pub") //$NON-NLS-1$ .queryParam("id", id) //$NON-NLS-1$ .queryParam("embedded", "true") //$NON-NLS-1$ //$NON-NLS-2$ .build(); return buildIframe(components); } else if (path.startsWith("/presentation/")) { //$NON-NLS-1$ String id = params.get("id").get(0); //$NON-NLS-1$ UriComponents components = UriComponentsBuilder .fromHttpUrl("https://docs.google.com/presentation/embed") //$NON-NLS-1$ .queryParam("id", id) //$NON-NLS-1$ .queryParam("start", "false") //$NON-NLS-1$ //$NON-NLS-2$ .queryParam("loop", "false") //$NON-NLS-1$ //$NON-NLS-2$ .queryParam("delayms", String.valueOf(TimeUnit.MILLISECONDS.convert(3, TimeUnit.SECONDS))) //$NON-NLS-1$ .build(); return buildIframe(components); } else if (path.startsWith("/drawings/")) { //$NON-NLS-1$ String id = params.get("id").get(0); //$NON-NLS-1$ if (StringUtils.isBlank(width)) { width = "960"; //$NON-NLS-1$ } UriComponents components = UriComponentsBuilder.fromHttpUrl("https://docs.google.com/drawings/pub") //$NON-NLS-1$ .queryParam("id", id) //$NON-NLS-1$ .queryParam("w", width) //$NON-NLS-1$ .build(); return buildImg(components); } else { return null; } }
From source file:com.eryansky.common.orm.PropertyFilter.java
/** * @param filterName ,???. /* w w w .j av a 2s . c o m*/ * eg. LIKES_NAME_OR_LOGIN_NAME * @param value . */ public PropertyFilter(final String filterName, final String value) { String firstPart = StringUtils.substringBefore(filterName, "_"); String matchTypeCode = StringUtils.substring(firstPart, 0, firstPart.length() - 1); String propertyTypeCode = StringUtils.substring(firstPart, firstPart.length() - 1, firstPart.length()); try { matchType = Enum.valueOf(MatchType.class, matchTypeCode); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } try { propertyClass = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue(); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } String propertyNameStr = StringUtils.substringAfter(filterName, "_"); Assert.isTrue(StringUtils.isNotBlank(propertyNameStr), "filter??" + filterName + ",??."); propertyNames = StringUtils.splitByWholeSeparator(propertyNameStr, PropertyFilter.OR_SEPARATOR); this.matchValue = ConvertUtils.convertStringToObject(value, propertyClass); }
From source file:com.mgmtp.jfunk.data.source.ContainerDataSource.java
@Inject public ContainerDataSource(final Provider<List<? extends DataSource>> dataSourcesProvider) { this.dataSourcesProvider = dataSourcesProvider; this.name = StringUtils.uncapitalize(StringUtils.substringBefore(getClass().getSimpleName(), "DataSource")); }
From source file:cc.recommenders.names.CoReTypeName.java
private static String removeGenerics(final String typeName) { return StringUtils.substringBefore(typeName, "<"); }
From source file:com.im.web.base.PropertyFilter.java
/** * @param filterName ,???. //from w w w .j av a 2s .c o m * eg. LIKES_NAME_OR_LOGIN_NAME * @param value . */ public PropertyFilter(final String filterName, final String value) { String firstPart = StringUtils.substringBefore(filterName, "_"); String matchTypeCode = StringUtils.substring(firstPart, 0, firstPart.length() - 1); String propertyTypeCode = StringUtils.substring(firstPart, firstPart.length() - 1, firstPart.length()); try { matchType = Enum.valueOf(MatchType.class, matchTypeCode); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } try { propertyClass = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue(); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } String propertyNameStr = StringUtils.substringAfter(filterName, "_"); // Assert.isTrue(StringUtils.isNotBlank(propertyNameStr), "filter??" + filterName + ",??."); propertyNames = StringUtils.splitByWholeSeparator(propertyNameStr, PropertyFilter.OR_SEPARATOR); // this.matchValue = ConvertUtils.convertStringToObject(value, propertyClass); }
From source file:com.thinkmore.framework.orm.PropertyFilter.java
/** * @param filterName ,???. //from w ww. j a va 2 s . co m * eg. LIKES_NAME_OR_LOGIN_NAME * @param value . */ public PropertyFilter(final String filterName, final String value) { String matchTypeStr = StringUtils.substringBefore(filterName, "_"); String matchTypeCode = StringUtils.substring(matchTypeStr, 0, matchTypeStr.length() - 1); String propertyTypeCode = StringUtils.substring(matchTypeStr, matchTypeStr.length() - 1, matchTypeStr.length()); try { matchType = Enum.valueOf(MatchType.class, matchTypeCode); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } try { propertyType = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue(); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } String propertyNameStr = StringUtils.substringAfter(filterName, "_"); propertyNames = StringUtils.split(propertyNameStr, PropertyFilter.OR_SEPARATOR); Assert.isTrue(propertyNames.length > 0, "filter??" + filterName + ",??."); //entity property. this.propertyValue = ReflectionUtil.convertStringToObject(value, propertyType); }
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 w w . j av a 2s . co m } return Boolean.FALSE; }