List of usage examples for org.apache.commons.lang StringUtils indexOf
public static int indexOf(String str, String searchStr)
Finds the first index within a String, handling null
.
From source file:com.hangum.tadpole.commons.util.NumberFormatUtils.java
/** * , ??./*from ww w .j av a 2 s . c o m*/ * @param value * @return */ public static String commaFormat(double value) { // String tmpVal = String.format("%.2f", value); DecimalFormat df = new DecimalFormat("#,###.##"); String tmpVal = df.format(value).toString(); if (-1 == StringUtils.indexOf(tmpVal, ".00")) { return tmpVal; } else { return StringUtils.replaceOnce(tmpVal, ".00", ""); } }
From source file:com.intel.cosbench.config.common.KVConfigParser.java
private static void addConfigEntry(String entry, Configuration config) { int pos = StringUtils.indexOf(entry, '='); if (pos < 0) logger.warn("cannot parse config entry {}", entry); String key = StringUtils.trim(StringUtils.left(entry, pos)); String value = StringUtils.trim(StringUtils.right(entry, entry.length() - pos - 1)); logger.debug("key=" + key + ";value=" + value); config.setProperty(key, value);//from w ww .ja v a 2 s.c o m }
From source file:com.hangum.tadpole.rdb.core.editors.main.PartQueryUtil.java
/** * ? DBMS? SELECT ? ?.//from w w w . j a v a2s .c o m * * @return */ public static String makeSelect(UserDBDAO userDB, String originalQuery, int startResultPos, int endResultPos) { String requestQuery = ""; if (DBDefine.MYSQL_DEFAULT == DBDefine.getDBDefine(userDB.getTypes())) { requestQuery = String.format(MySQLDMLTemplate.TMP_GET_PARTDATA, originalQuery, startResultPos, endResultPos); } else if (DBDefine.ORACLE_DEFAULT == DBDefine.getDBDefine(userDB.getTypes())) { if (StringUtils.indexOf(originalQuery.toLowerCase(), "where") == -1) { requestQuery = String.format(OracleDMLTemplate.TMP_GET_PARTDATA, originalQuery, startResultPos, endResultPos); } else { requestQuery = originalQuery; } } else if (DBDefine.SQLite_DEFAULT == DBDefine.getDBDefine(userDB.getTypes())) { requestQuery = String.format(SQLiteDMLTemplate.TMP_GET_PARTDATA, originalQuery, startResultPos, endResultPos); } else if (DBDefine.CUBRID_DEFAULT == DBDefine.getDBDefine(userDB.getTypes())) { // // https://github.com/hangum/TadpoleForDBTools/issues/12 ? ? ? ? ? ? . // // if( StringUtils.indexOf(originalQuery, "where") == -1 ) { // requestQuery = String.format(CubridDMLTemplate.TMP_GET_PARTDATA, originalQuery, startResultPos, endResultPos); // } else { requestQuery = originalQuery; // } // ? ? dbms ? . } else { requestQuery = originalQuery; } return requestQuery; }
From source file:com.prowidesoftware.swift.model.field.AmountResolver.java
/** * get the amount of the given field by reading it's components pattern. * The first index of 'N', number, is returned as amount. * <em>See the returns notes</em> * * @param f the field where to extract the amount, must not be null * * @return a BigDecimal with the number found in the first numeric component or <code>null</code> if there is * no numeric component in the field. It may also return null if Field.getComponent(index,Number.class) fails * for that component/*from w w w . j av a 2s .c o m*/ * @see Field#getComponentAs(int, Class) * @since 7.8 */ public static BigDecimal amount(final Field f) { Validate.notNull(f); final int i = StringUtils.indexOf(f.componentsPattern(), 'N'); if (i >= 0) { final Number n = (Number) f.getComponentAs(i + 1, Number.class); if (n == null) { log.warning("getComponentAs(" + (i + 1) + ", Number.class) returned null for field " + f); return null; } return new BigDecimal(n.toString()); } return null; }
From source file:com.thoughtworks.go.server.web.i18n.CurrentStatus.java
public static CurrentStatus getProjectBuildStatus(String statusStr) { for (int i = 0; i < STATUSES.length; i++) { CurrentStatus status = STATUSES[i]; if (StringUtils.indexOf(statusStr, status.getCruiseStatus()) == 0) { return status; }/*from ww w .ja v a 2 s .com*/ } return DISCONTINUED; }
From source file:com.antsdb.saltedfish.sql.vdm.FuncLocate.java
@Override public long eval(VdmContext ctx, Heap heap, Parameters params, long pRecord) { long pString = this.parameters.get(1).eval(ctx, heap, params, pRecord); if (pString == 0) { return 0; }//from www. j a v a2s . c om long pSubstr = this.parameters.get(0).eval(ctx, heap, params, pRecord); if (pSubstr == 0) { return 0; } String str = (String) FishObject.get(heap, AutoCaster.toString(heap, pString)); String substr = (String) FishObject.get(heap, AutoCaster.toString(heap, pSubstr)); int pos = StringUtils.indexOf(str, substr) + 1; return FishObject.allocSet(heap, pos); }
From source file:hydrograph.ui.common.util.ExternalSchemaUtil.java
/** * Converts UI grid-row object to its equivalent Jaxb Object * // w w w . j a v a 2 s. c o m * @param gridRow * @return */ public Field convertGridRowToJaxbSchemaField(GridRow gridRow) { Field field = new Field(); if (StringUtils.indexOf(gridRow.getFieldName(), "}") - StringUtils.indexOf(gridRow.getFieldName(), "@{") >= 3) { Utils.INSTANCE.loadProperties(); String paramValue = Utils.INSTANCE.getParamValueForRunSql(gridRow.getFieldName()); field.setName(paramValue); } else { field.setName(gridRow.getFieldName()); } field.setType(FieldDataTypes.fromValue(gridRow.getDataTypeValue())); if (gridRow instanceof XPathGridRow) { if (StringUtils.isNotBlank(((XPathGridRow) gridRow).getXPath())) { field.setAbsoluteOrRelativeXpath((((XPathGridRow) gridRow).getXPath())); } } if (StringUtils.isNotBlank(gridRow.getDateFormat())) { field.setFormat(gridRow.getDateFormat()); } if (StringUtils.isNotBlank(gridRow.getPrecision())) { field.setPrecision(Integer.parseInt(gridRow.getPrecision())); } if (StringUtils.isNotBlank(gridRow.getScale())) { field.setScale(Integer.parseInt(gridRow.getScale())); } if (gridRow.getScaleTypeValue() != null) { if (!gridRow.getScaleTypeValue().equals("") && !gridRow.getScaleTypeValue().equals(Messages.SCALE_TYPE_NONE)) { field.setScaleType(ScaleTypes.fromValue(gridRow.getScaleTypeValue())); } } if (StringUtils.isNotBlank(gridRow.getDescription())) { field.setDescription(gridRow.getDescription()); } if (gridRow instanceof FixedWidthGridRow) { if (StringUtils.isNotBlank(((FixedWidthGridRow) gridRow).getLength())) { field.setLength(new BigInteger(((FixedWidthGridRow) gridRow).getLength())); } } if (gridRow instanceof MixedSchemeGridRow) { if (StringUtils.isNotBlank(((MixedSchemeGridRow) gridRow).getLength())) { field.setLength(new BigInteger(((MixedSchemeGridRow) gridRow).getLength())); } if (StringUtils.isNotBlank(((MixedSchemeGridRow) gridRow).getDelimiter())) { field.setDelimiter((((MixedSchemeGridRow) gridRow).getDelimiter())); } } if (gridRow instanceof GenerateRecordSchemaGridRow) { if (StringUtils.isNotBlank(((GenerateRecordSchemaGridRow) gridRow).getLength())) { field.setLength(new BigInteger(((GenerateRecordSchemaGridRow) gridRow).getLength())); } if (StringUtils.isNotBlank(((GenerateRecordSchemaGridRow) gridRow).getRangeFrom())) { field.setRangeFrom((((GenerateRecordSchemaGridRow) gridRow).getRangeFrom())); } if (StringUtils.isNotBlank(((GenerateRecordSchemaGridRow) gridRow).getRangeTo())) { field.setRangeTo(((GenerateRecordSchemaGridRow) gridRow).getRangeTo()); } if (StringUtils.isNotBlank(((GenerateRecordSchemaGridRow) gridRow).getDefaultValue())) { field.setDefault(((GenerateRecordSchemaGridRow) gridRow).getDefaultValue()); } } return field; }
From source file:com.intel.cosbench.driver.generator.HistogramIntGenerator.java
private static HistogramIntGenerator tryParse(String pattern) { pattern = StringUtils.substringBetween(pattern, "(", ")"); String[] args = StringUtils.split(pattern, ','); ArrayList<Bucket> bucketsList = new ArrayList<Bucket>(); for (String arg : args) { int v1 = StringUtils.indexOf(arg, '|'); int v2 = StringUtils.lastIndexOf(arg, '|'); boolean isOpenRange = ((v2 - v1) == 1) ? true : false; String[] values = StringUtils.split(arg, '|'); int lower, upper, weight; if (isOpenRange) { lower = Integer.parseInt(values[0]); upper = UniformIntGenerator.getMAXupper(); weight = Integer.parseInt(values[1]); } else if (values.length != 3) { throw new IllegalArgumentException(); } else {/* w ww . j a v a 2s .com*/ lower = Integer.parseInt(values[0]); upper = Integer.parseInt(values[1]); weight = Integer.parseInt(values[2]); } bucketsList.add(new Bucket(lower, upper, weight)); } if (bucketsList.isEmpty()) { throw new IllegalArgumentException(); } Collections.sort(bucketsList, new LowerComparator()); final Bucket[] buckets = bucketsList.toArray(new Bucket[0]); int cumulativeWeight = 0; for (Bucket bucket : buckets) { cumulativeWeight += bucket.weight; bucket.cumulativeWeight = cumulativeWeight; } return new HistogramIntGenerator(buckets); }
From source file:com.edgenius.wiki.ext.tabs.TabMacro.java
public void execute(StringBuffer buffer, MacroParameter params) throws MalformedMacroException { String tabKey = params.getParam(Macro.GROUP_KEY); RenderContext context = params.getRenderContext(); if (StringUtils.indexOf(tabKey, '-') == -1) { errorGroup(buffer, params, tabKey); } else {/*from www. j av a2 s.c om*/ String[] keys = tabKey.split("-"); if (keys.length != 2) { errorGroup(buffer, params, tabKey); } else { String grpKey = keys[0]; String name = StringUtils.trim(params.getParam(NameConstants.NAME)); if (StringUtils.isBlank(name)) { //default name name = DEFAULT_TAB_NAME; } //OK, save tabKey and tabName information into Global parameter, used by TabsHandler Map<String, Map<String, String>> tabsMap = (Map<String, Map<String, String>>) context .getGlobalParam(TabsHandler.class.getName()); if (tabsMap == null) { tabsMap = new HashMap<String, Map<String, String>>(); context.putGlobalParam(TabsHandler.class.getName(), tabsMap); } Map<String, String> tabList = tabsMap.get(grpKey); if (tabList == null) { //ordered - so LinkedHashMap tabList = new LinkedHashMap<String, String>(); tabsMap.put(grpKey, tabList); } tabList.put(tabKey, name); if (RenderContext.RENDER_TARGET_EXPORT.equals(context.getRenderTarget()) || RenderContext.RENDER_TARGET_PLAIN_VIEW.equals(context.getRenderTarget())) { //for print and export, tab name will be just before the content body buffer.append("<div class=\"macroTabName\">").append(name).append("</div>"); } //use "tab-"+tabKey as div ID, so that TabsHanlder can process render tabs correctly. String content = params.getContent(); buffer.append("<div class=\"macroTab\" id=\"tab-").append(tabKey).append("\" name=\"").append(name) .append("\">").append(content).append("</div>"); } } }
From source file:fr.paris.lutece.portal.service.page.PortletCacheService.java
/** * {@inheritDoc}/*from w ww . j av a2 s .c o m*/ */ public void processPortletEvent(PortletEvent event) { String strKey = "[" + CACHE_PORTLET_PREFIX + event.getPortletId() + "]"; for (String strKeyTemp : (List<String>) getCache().getKeys()) { if (StringUtils.indexOf(strKeyTemp, strKey) != -1) { getCache().remove(strKeyTemp); } } }