List of usage examples for java.text FieldPosition FieldPosition
public FieldPosition(Format.Field attribute)
From source file:org.apache.kylin.common.persistence.JDBCResourceDAO.java
private String getCheckTableExistsSql(final String tableName) { final String sql = new MessageFormat(jdbcSqlQueryFormat.getCheckTableExistsSql(), Locale.ROOT) .format(new Object[] { tableName }, new StringBuffer(), new FieldPosition(0)).toString(); return sql;// ww w .jav a 2s . c o m }
From source file:org.gumtree.vis.awt.time.TimePlotPanel.java
@Override protected void drawToolTipFollower(Graphics2D g2, int x, int y) { Rectangle2D dataArea = getScreenDataArea(); if (((int) dataArea.getMinX() <= x) && (x <= (int) dataArea.getMaxX()) && ((int) dataArea.getMinY() <= y) && (y <= (int) dataArea.getMaxY())) { Date date = new Date((long) getChartX()); String text = ""; SimpleDateFormat format = new SimpleDateFormat("EEE d MMM HH:mm:ss"); StringBuffer buffer = new StringBuffer(); format.format(date, buffer, new FieldPosition(0)); text = buffer.toString();/*from w w w . j av a2 s . c o m*/ text = "(" + text + String.format(", %.2f)", getChartY()); int xLoc = x + 10; int yLoc = y + 20; double width = text.length() * 5.5; double height = 15; if (xLoc + width > dataArea.getMaxX()) { xLoc = (int) (x - width); } if (yLoc + height > dataArea.getMaxY()) { yLoc = (int) (y - height); } Rectangle2D toolTipArea = new Rectangle2D.Double(xLoc, yLoc, width, height); g2.setColor(Color.white); g2.fill(toolTipArea); g2.setColor(Color.black); g2.drawString(text, xLoc + 3, yLoc + 11); } }
From source file:org.apache.kylin.common.persistence.JDBCResourceDAO.java
private String getCreateIfNeededSql(String tableName) { String sql = new MessageFormat(jdbcSqlQueryFormat.getCreateIfNeedSql(), Locale.ROOT) .format(new Object[] { tableName, META_TABLE_KEY, META_TABLE_TS, META_TABLE_CONTENT }, new StringBuffer(), new FieldPosition(0)) .toString();//from w w w .ja va2 s . co m return sql; }
From source file:org.apache.kylin.common.persistence.JDBCResourceDAO.java
private String getCreateIndexSql(String indexName, String tableName, String indexCol) { String sql = new MessageFormat(jdbcSqlQueryFormat.getCreateIndexSql(), Locale.ROOT) .format(new Object[] { indexName, tableName, indexCol }, new StringBuffer(), new FieldPosition(0)) .toString();/* w ww. j a v a 2 s . co m*/ return sql; }
From source file:org.apache.kylin.common.persistence.JDBCResourceDAO.java
private String getKeyEqualSqlString(String tableName, boolean fetchContent, boolean fetchTimestamp) { String sql = new MessageFormat(jdbcSqlQueryFormat.getKeyEqualsSql(), Locale.ROOT) .format(new Object[] { getSelectList(fetchContent, fetchTimestamp), tableName, META_TABLE_KEY }, new StringBuffer(), new FieldPosition(0)) .toString();// w ww . j a va 2 s. c o m return sql; }
From source file:org.apache.poi.ss.format.CellNumberFormatter.java
private void writeScientific(double value, StringBuffer output, Set<StringMod> mods) { StringBuffer result = new StringBuffer(); FieldPosition fractionPos = new FieldPosition(DecimalFormat.FRACTION_FIELD); decimalFmt.format(value, result, fractionPos); writeInteger(result, output, integerSpecials, mods, integerCommas); writeFractional(result, output);/*from w w w . j a va2 s. c o m*/ /* * Exponent sign handling is complex. * * In DecimalFormat, you never put the sign in the format, and the sign only * comes out of the format if it is negative. * * In Excel, you always say whether to always show the sign ("e+") or only * show negative signs ("e-"). * * Also in Excel, where you put the sign in the format is NOT where it comes * out in the result. In the format, the sign goes with the "e"; in the * output it goes with the exponent value. That is, if you say "#e-|#" you * get "1e|-5", not "1e-|5". This makes sense I suppose, but it complicates * things. * * Finally, everything else in this formatting code assumes that the base of * the result is the original format, and that starting from that situation, * the indexes of the original special characters can be used to place the new * characters. As just described, this is not true for the exponent's sign. * <p/> * So here is how we handle it: * * (1) When parsing the format, remove the sign from after the 'e' and put it * before the first digit of the exponent (where it will be shown). * * (2) Determine the result's sign. * * (3) If it's missing, put the sign into the output to keep the result * lined up with the output. (In the result, "after the 'e'" and "before the * first digit" are the same because the result has no extra chars to be in * the way.) * * (4) In the output, remove the sign if it should not be shown ("e-" was used * and the sign is negative) or set it to the correct value. */ // (2) Determine the result's sign. int ePos = fractionPos.getEndIndex(); int signPos = ePos + 1; char expSignRes = result.charAt(signPos); if (expSignRes != '-') { // not a sign, so it's a digit, and therefore a positive exponent expSignRes = '+'; // (3) If it's missing, put the sign into the output to keep the result // lined up with the output. result.insert(signPos, '+'); } // Now the result lines up like it is supposed to with the specials' indexes ListIterator<Special> it = exponentSpecials.listIterator(1); Special expSign = it.next(); char expSignFmt = expSign.ch; // (4) In the output, remove the sign if it should not be shown or set it to // the correct value. if (expSignRes == '-' || expSignFmt == '+') mods.add(replaceMod(expSign, true, expSign, true, expSignRes)); else mods.add(deleteMod(expSign, true, expSign, true)); StringBuffer exponentNum = new StringBuffer(result.substring(signPos + 1)); writeInteger(exponentNum, output, exponentDigitSpecials, mods, false); }
From source file:org.apache.kylin.common.persistence.JDBCResourceDAO.java
private String getDeletePstatSql(String tableName) { String sql = new MessageFormat(jdbcSqlQueryFormat.getDeletePstatSql(), Locale.ROOT) .format(new Object[] { tableName, META_TABLE_KEY }, new StringBuffer(), new FieldPosition(0)) .toString();//from www . ja v a 2 s . c om return sql; }
From source file:org.apache.kylin.common.persistence.JDBCResourceDAO.java
private String getListResourceSqlString(String tableName) { String sql = new MessageFormat(jdbcSqlQueryFormat.getListResourceSql(), Locale.ROOT) .format(new Object[] { META_TABLE_KEY, tableName, META_TABLE_KEY }, new StringBuffer(), new FieldPosition(0)) .toString();/* w w w. j a v a 2 s . co m*/ return sql; }
From source file:org.apache.kylin.common.persistence.JDBCResourceDAO.java
private String getAllResourceSqlString(String tableName) { String sql = new MessageFormat(jdbcSqlQueryFormat.getAllResourceSql(), Locale.ROOT).format( new Object[] { getSelectList(true, true), tableName, META_TABLE_KEY, META_TABLE_TS, META_TABLE_TS }, new StringBuffer(), new FieldPosition(0)).toString(); return sql;//from w ww. j a v a 2 s . c om }
From source file:org.apache.kylin.common.persistence.JDBCResourceDAO.java
private String getReplaceSql(String tableName) { String sql = new MessageFormat(jdbcSqlQueryFormat.getReplaceSql(), Locale.ROOT) .format(new Object[] { tableName, META_TABLE_TS, META_TABLE_CONTENT, META_TABLE_KEY }, new StringBuffer(), new FieldPosition(0)) .toString();// w ww . java 2 s . c o m return sql; }