Java Code Examples for java.text.DecimalFormatSymbols#getGroupingSeparator()
The following examples show how to use
java.text.DecimalFormatSymbols#getGroupingSeparator() .
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 File: ParsingFieldUpdateProcessorsTest.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testParseIntNonRootLocale() throws Exception { final DecimalFormatSymbols ru_RU = DecimalFormatSymbols.getInstance(new Locale("ru","RU")); final char groupChar = ru_RU.getGroupingSeparator(); int value = 1089883491; String intString1 = "1089883491"; String intString2 = "1"+groupChar+"089"+groupChar+"883"+groupChar+"491"; IndexSchema schema = h.getCore().getLatestSchema(); assertNotNull(schema.getFieldOrNull("int_i")); // should match dynamic field "*_i" assertNull(schema.getFieldOrNull("not_in_schema")); SolrInputDocument d = processAdd("parse-int-russian-no-run-processor", doc(f("id", "113"), f("int_i", intString1), f("not_in_schema", intString2))); assertNotNull(d); assertThat(d.getFieldValue("int_i"), IS_INTEGER); assertEquals(value, ((Integer)d.getFieldValue("int_i")).intValue()); assertThat(d.getFieldValue("not_in_schema"), IS_INTEGER); assertEquals(value, ((Integer)d.getFieldValue("not_in_schema")).intValue()); }
Example 2
Source File: ParsingFieldUpdateProcessorsTest.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testParseLongNonRootLocale() throws Exception { final DecimalFormatSymbols ru_RU = DecimalFormatSymbols.getInstance(new Locale("ru","RU")); final char groupChar = ru_RU.getGroupingSeparator(); long value = 1089883491L; String longString1 = "1089883491"; String longString2 = "1"+groupChar+"089"+groupChar+"883"+groupChar+"491"; IndexSchema schema = h.getCore().getLatestSchema(); assertNotNull(schema.getFieldOrNull("long_l")); // should match dynamic field "*_l" assertNull(schema.getFieldOrNull("not_in_schema")); SolrInputDocument d = processAdd("parse-long-russian-no-run-processor", doc(f("id", "113"), f("long_l", longString1), f("not_in_schema", longString2))); assertNotNull(d); assertThat(d.getFieldValue("long_l"), IS_LONG); assertEquals(value, ((Long)d.getFieldValue("long_l")).longValue()); assertThat(d.getFieldValue("not_in_schema"), IS_LONG); assertEquals(value, ((Long)d.getFieldValue("not_in_schema")).longValue()); }
Example 3
Source File: NumberUtils.java From OpenEstate-IO with Apache License 2.0 | 6 votes |
/** * Test, if a string contains a parsable number. * * @param value the value to check * @param locale the locale, against which the value is checked * (checks locale specific decimal and grouping separators) * @return true, if the provided value contains of numbers */ public static boolean isNumeric(String value, Locale locale) { if (value == null) return false; int start = 0; final DecimalFormatSymbols symbols = (locale != null) ? DecimalFormatSymbols.getInstance(locale) : DecimalFormatSymbols.getInstance(); if (value.startsWith("+") || value.startsWith("-")) start++; boolean fraction = false; for (int i = start; i < value.length(); i++) { final char c = value.charAt(i); if (c == symbols.getDecimalSeparator() && !fraction) { fraction = true; continue; } if (c == symbols.getGroupingSeparator() && !fraction) { continue; } if (!Character.isDigit(c)) { return false; } } return true; }
Example 4
Source File: StringValue.java From jackcess with Apache License 2.0 | 6 votes |
private static String toCanonicalNumberFormat(LocaleContext ctx, String tmpVal) { // convert to standard numeric format: // - discard any grouping separators // - convert decimal separator to '.' DecimalFormatSymbols syms = ctx.getNumericConfig().getDecimalFormatSymbols(); char groupSepChar = syms.getGroupingSeparator(); tmpVal = StringUtils.remove(tmpVal, groupSepChar); char decSepChar = syms.getDecimalSeparator(); if((decSepChar != ValueSupport.CANON_DEC_SEP) && (tmpVal.indexOf(decSepChar) >= 0)) { tmpVal = tmpVal.replace(decSepChar, ValueSupport.CANON_DEC_SEP); } return tmpVal; }
Example 5
Source File: ConvertExcelToCSVProcessorTest.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testCustomValueSeparatorWithEL() throws Exception { Map<String, String> attributes = new HashMap<String, String>(); attributes.put("csv.delimiter", "|"); testRunner.enqueue(new File("src/test/resources/dataformatting.xlsx").toPath(), attributes); testRunner.setProperty(CSVUtils.VALUE_SEPARATOR, "${csv.delimiter}"); testRunner.setProperty(ConvertExcelToCSVProcessor.FORMAT_VALUES, "true"); testRunner.run(); testRunner.assertTransferCount(ConvertExcelToCSVProcessor.SUCCESS, 1); testRunner.assertTransferCount(ConvertExcelToCSVProcessor.ORIGINAL, 1); testRunner.assertTransferCount(ConvertExcelToCSVProcessor.FAILURE, 0); MockFlowFile ff = testRunner.getFlowFilesForRelationship(ConvertExcelToCSVProcessor.SUCCESS).get(0); Long rowsSheet = new Long(ff.getAttribute(ConvertExcelToCSVProcessor.ROW_NUM)); assertTrue(rowsSheet == 9); LocalDateTime localDt = LocalDateTime.of(2017, 1, 1, 12, 0, 0); DecimalFormatSymbols decimalFormatSymbols = DecimalFormatSymbols.getInstance(); String valueSeparator = testRunner.getProcessContext().getProperty(CSVUtils.VALUE_SEPARATOR).evaluateAttributeExpressions(ff).getValue(); String decimalSeparator = (String.valueOf(decimalFormatSymbols.getDecimalSeparator()).equals(valueSeparator)) ? ("\\" + decimalFormatSymbols.getDecimalSeparator()) : String.valueOf(decimalFormatSymbols.getDecimalSeparator()); String groupingSeparator = String.valueOf(decimalFormatSymbols.getGroupingSeparator()).equals(valueSeparator) ? "\\" + decimalFormatSymbols.getGroupingSeparator() : String.valueOf(decimalFormatSymbols.getGroupingSeparator()); ff.assertContentEquals(String.format("Numbers|Timestamps|Money\n" + "1234%1$s456|" + DateTimeFormatter.ofPattern("d/M/yy").format(localDt) + "|$ 123%1$s45\n" + "1234%1$s46|" + DateTimeFormatter.ofPattern("hh:mm:ss a").format(localDt) + "|£ 123%1$s45\n" + "1234%1$s5|" + DateTimeFormatter.ofPattern("EEEE, MMMM dd, yyyy").format(localDt) + "|¥ 123%1$s45\n" + "1%2$s234%1$s46|" + DateTimeFormatter.ofPattern("d/M/yy HH:mm").format(localDt) + "|$ 1%2$s023%1$s45\n" + "1%2$s234%1$s4560|" + DateTimeFormatter.ofPattern("hh:mm a").format(localDt) + "|£ 1%2$s023%1$s45\n" + "9%1$s88E+08|" + DateTimeFormatter.ofPattern("yyyy/MM/dd/ HH:mm").format(localDt) + "|¥ 1%2$s023%1$s45\n" + "9%1$s877E+08||\n" + "9%1$s8765E+08||\n", decimalSeparator, groupingSeparator)); }
Example 6
Source File: ConvertExcelToCSVProcessorTest.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testSkipColumns() throws Exception { testRunner.enqueue(new File("src/test/resources/dataformatting.xlsx").toPath()); testRunner.setProperty(ConvertExcelToCSVProcessor.COLUMNS_TO_SKIP, "2"); testRunner.setProperty(ConvertExcelToCSVProcessor.FORMAT_VALUES, "true"); testRunner.run(); testRunner.assertTransferCount(ConvertExcelToCSVProcessor.SUCCESS, 1); testRunner.assertTransferCount(ConvertExcelToCSVProcessor.ORIGINAL, 1); testRunner.assertTransferCount(ConvertExcelToCSVProcessor.FAILURE, 0); MockFlowFile ff = testRunner.getFlowFilesForRelationship(ConvertExcelToCSVProcessor.SUCCESS).get(0); Long rowsSheet = new Long(ff.getAttribute(ConvertExcelToCSVProcessor.ROW_NUM)); assertTrue(rowsSheet == 9); DecimalFormatSymbols decimalFormatSymbols = DecimalFormatSymbols.getInstance(); String decimalSeparator = decimalFormatSymbols.getDecimalSeparator() == ',' ? "\\," : String.valueOf(decimalFormatSymbols.getDecimalSeparator()); String groupingSeparator = decimalFormatSymbols.getGroupingSeparator() == ',' ? "\\," : String.valueOf(decimalFormatSymbols.getGroupingSeparator()); ff.assertContentEquals(String.format("Numbers,Money\n" + "1234%1$s456,$ 123%1$s45\n" + "1234%1$s46,£ 123%1$s45\n" + "1234%1$s5,¥ 123%1$s45\n" + "1%2$s234%1$s46,$ 1%2$s023%1$s45\n" + "1%2$s234%1$s4560,£ 1%2$s023%1$s45\n" + "9%1$s88E+08,¥ 1%2$s023%1$s45\n" + "9%1$s877E+08,\n" + "9%1$s8765E+08,\n", decimalSeparator, groupingSeparator)); }
Example 7
Source File: ConvertExcelToCSVProcessorTest.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testSkipRowsWithEL() throws Exception { Map<String, String> attributes = new HashMap<String, String>(); attributes.put("rowsToSkip", "2"); testRunner.enqueue(new File("src/test/resources/dataformatting.xlsx").toPath(), attributes); testRunner.setProperty(ConvertExcelToCSVProcessor.ROWS_TO_SKIP, "${rowsToSkip}"); testRunner.setProperty(ConvertExcelToCSVProcessor.FORMAT_VALUES, "true"); testRunner.run(); testRunner.assertTransferCount(ConvertExcelToCSVProcessor.SUCCESS, 1); testRunner.assertTransferCount(ConvertExcelToCSVProcessor.ORIGINAL, 1); testRunner.assertTransferCount(ConvertExcelToCSVProcessor.FAILURE, 0); MockFlowFile ff = testRunner.getFlowFilesForRelationship(ConvertExcelToCSVProcessor.SUCCESS).get(0); Long rowsSheet = new Long(ff.getAttribute(ConvertExcelToCSVProcessor.ROW_NUM)); assertEquals("Row count does match expected value.", "7", rowsSheet.toString()); LocalDateTime localDt = LocalDateTime.of(2017, 1, 1, 12, 0, 0); DecimalFormatSymbols decimalFormatSymbols = DecimalFormatSymbols.getInstance(); String decimalSeparator = decimalFormatSymbols.getDecimalSeparator() == ',' ? "\\," : String.valueOf(decimalFormatSymbols.getDecimalSeparator()); String groupingSeparator = decimalFormatSymbols.getGroupingSeparator() == ',' ? "\\," : String.valueOf(decimalFormatSymbols.getGroupingSeparator()); ff.assertContentEquals(String.format("1234%1$s46," + DateTimeFormatter.ofPattern("hh:mm:ss a").format(localDt) + ",£ 123%1$s45\n" + "1234%1$s5," + DateTimeFormatter.ofPattern("EEEE\\, MMMM dd\\, yyyy").format(localDt) + ",¥ 123%1$s45\n" + "1%2$s234%1$s46," + DateTimeFormatter.ofPattern("d/M/yy HH:mm").format(localDt) + ",$ 1%2$s023%1$s45\n" + "1%2$s234%1$s4560," + DateTimeFormatter.ofPattern("hh:mm a").format(localDt) + ",£ 1%2$s023%1$s45\n" + "9%1$s88E+08," + DateTimeFormatter.ofPattern("yyyy/MM/dd/ HH:mm").format(localDt) + ",¥ 1%2$s023%1$s45\n" + "9%1$s877E+08,,\n" + "9%1$s8765E+08,,\n", decimalSeparator, groupingSeparator)); }
Example 8
Source File: ConvertExcelToCSVProcessorTest.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testSkipRows() throws Exception { testRunner.enqueue(new File("src/test/resources/dataformatting.xlsx").toPath()); testRunner.setProperty(ConvertExcelToCSVProcessor.ROWS_TO_SKIP, "2"); testRunner.setProperty(ConvertExcelToCSVProcessor.FORMAT_VALUES, "true"); testRunner.run(); testRunner.assertTransferCount(ConvertExcelToCSVProcessor.SUCCESS, 1); testRunner.assertTransferCount(ConvertExcelToCSVProcessor.ORIGINAL, 1); testRunner.assertTransferCount(ConvertExcelToCSVProcessor.FAILURE, 0); MockFlowFile ff = testRunner.getFlowFilesForRelationship(ConvertExcelToCSVProcessor.SUCCESS).get(0); Long rowsSheet = new Long(ff.getAttribute(ConvertExcelToCSVProcessor.ROW_NUM)); assertEquals("Row count does match expected value.", "7", rowsSheet.toString()); LocalDateTime localDt = LocalDateTime.of(2017, 1, 1, 12, 0, 0); DecimalFormatSymbols decimalFormatSymbols = DecimalFormatSymbols.getInstance(); String decimalSeparator = decimalFormatSymbols.getDecimalSeparator() == ',' ? "\\," : String.valueOf(decimalFormatSymbols.getDecimalSeparator()); String groupingSeparator = decimalFormatSymbols.getGroupingSeparator() == ',' ? "\\," : String.valueOf(decimalFormatSymbols.getGroupingSeparator()); ff.assertContentEquals(String.format("1234%1$s46," + DateTimeFormatter.ofPattern("hh:mm:ss a").format(localDt) + ",£ 123%1$s45\n" + "1234%1$s5," + DateTimeFormatter.ofPattern("EEEE\\, MMMM dd\\, yyyy").format(localDt) + ",¥ 123%1$s45\n" + "1%2$s234%1$s46," + DateTimeFormatter.ofPattern("d/M/yy HH:mm").format(localDt) + ",$ 1%2$s023%1$s45\n" + "1%2$s234%1$s4560," + DateTimeFormatter.ofPattern("hh:mm a").format(localDt) + ",£ 1%2$s023%1$s45\n" + "9%1$s88E+08," + DateTimeFormatter.ofPattern("yyyy/MM/dd/ HH:mm").format(localDt) + ",¥ 1%2$s023%1$s45\n" + "9%1$s877E+08,,\n" + "9%1$s8765E+08,,\n", decimalSeparator, groupingSeparator)); }
Example 9
Source File: ConvertExcelToCSVProcessorTest.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testQuoting() throws Exception { testRunner.enqueue(new File("src/test/resources/dataformatting.xlsx").toPath()); testRunner.setProperty(CSVUtils.QUOTE_MODE, CSVUtils.QUOTE_MINIMAL); testRunner.setProperty(ConvertExcelToCSVProcessor.FORMAT_VALUES, "true"); testRunner.run(); testRunner.assertTransferCount(ConvertExcelToCSVProcessor.SUCCESS, 1); testRunner.assertTransferCount(ConvertExcelToCSVProcessor.ORIGINAL, 1); testRunner.assertTransferCount(ConvertExcelToCSVProcessor.FAILURE, 0); MockFlowFile ff = testRunner.getFlowFilesForRelationship(ConvertExcelToCSVProcessor.SUCCESS).get(0); Long rowsSheet = new Long(ff.getAttribute(ConvertExcelToCSVProcessor.ROW_NUM)); assertTrue(rowsSheet == 9); LocalDateTime localDt = LocalDateTime.of(2017, 1, 1, 12, 0, 0); DecimalFormatSymbols decimalFormatSymbols = DecimalFormatSymbols.getInstance(); char decimalSeparator = decimalFormatSymbols.getDecimalSeparator(); char groupingSeparator = decimalFormatSymbols.getGroupingSeparator(); ff.assertContentEquals("Numbers,Timestamps,Money\n" + addQuotingIfNeeded(String.format("1234%1$s456", decimalSeparator)) + "," + DateTimeFormatter.ofPattern("d/M/yy").format(localDt) + "," + addQuotingIfNeeded(String.format("$ 123%1$s45", decimalSeparator)) + "\n" + addQuotingIfNeeded(String.format("1234%1$s46", decimalSeparator)) + "," + DateTimeFormatter.ofPattern("hh:mm:ss a").format(localDt) + "," + addQuotingIfNeeded(String.format("£ 123%1$s45", decimalSeparator)) + "\n" + addQuotingIfNeeded(String.format("1234%1$s5", decimalSeparator)) + ",\"" + DateTimeFormatter.ofPattern("EEEE, MMMM dd, yyyy").format(localDt) + "\"," + addQuotingIfNeeded(String.format("¥ 123%1$s45", decimalSeparator)) + "\n" + addQuotingIfNeeded(String.format("1%2$s234%1$s46", decimalSeparator, groupingSeparator)) + "," + DateTimeFormatter.ofPattern("d/M/yy HH:mm").format(localDt) + "," + addQuotingIfNeeded(String.format("$ 1%2$s023%1$s45", decimalSeparator, groupingSeparator)) + "\n" + addQuotingIfNeeded(String.format("1%2$s234%1$s4560", decimalSeparator, groupingSeparator)) + "," + DateTimeFormatter.ofPattern("hh:mm a").format(localDt) + "," + addQuotingIfNeeded(String.format("£ 1%2$s023%1$s45", decimalSeparator, groupingSeparator)) + "\n" + addQuotingIfNeeded(String.format("9%1$s88E+08", decimalSeparator)) + "," + DateTimeFormatter.ofPattern("yyyy/MM/dd/ HH:mm").format(localDt) + "," + addQuotingIfNeeded(String.format("¥ 1%2$s023%1$s45", decimalSeparator, groupingSeparator)) + "\n" + addQuotingIfNeeded(String.format("9%1$s877E+08", decimalSeparator)) + ",,\n" + addQuotingIfNeeded(String.format("9%1$s8765E+08", decimalSeparator)) + ",,\n"); }
Example 10
Source File: ConvertExcelToCSVProcessorTest.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testCustomDelimiters() throws Exception { testRunner.enqueue(new File("src/test/resources/dataformatting.xlsx").toPath()); testRunner.setProperty(CSVUtils.VALUE_SEPARATOR, "|"); testRunner.setProperty(CSVUtils.RECORD_SEPARATOR, "\\r\\n"); testRunner.setProperty(ConvertExcelToCSVProcessor.FORMAT_VALUES, "true"); testRunner.run(); testRunner.assertTransferCount(ConvertExcelToCSVProcessor.SUCCESS, 1); testRunner.assertTransferCount(ConvertExcelToCSVProcessor.ORIGINAL, 1); testRunner.assertTransferCount(ConvertExcelToCSVProcessor.FAILURE, 0); MockFlowFile ff = testRunner.getFlowFilesForRelationship(ConvertExcelToCSVProcessor.SUCCESS).get(0); Long rowsSheet = new Long(ff.getAttribute(ConvertExcelToCSVProcessor.ROW_NUM)); assertTrue(rowsSheet == 9); LocalDateTime localDt = LocalDateTime.of(2017, 1, 1, 12, 0, 0); DecimalFormatSymbols decimalFormatSymbols = DecimalFormatSymbols.getInstance(); String valueSeparator = testRunner.getProcessContext().getProperty(CSVUtils.VALUE_SEPARATOR).evaluateAttributeExpressions(ff).getValue(); String decimalSeparator = (String.valueOf(decimalFormatSymbols.getDecimalSeparator()).equals(valueSeparator)) ? ("\\" + decimalFormatSymbols.getDecimalSeparator()) : String.valueOf(decimalFormatSymbols.getDecimalSeparator()); String groupingSeparator = String.valueOf(decimalFormatSymbols.getGroupingSeparator()).equals(valueSeparator) ? "\\" + decimalFormatSymbols.getGroupingSeparator() : String.valueOf(decimalFormatSymbols.getGroupingSeparator()); ff.assertContentEquals(String.format("Numbers|Timestamps|Money\r\n" + "1234%1$s456|" + DateTimeFormatter.ofPattern("d/M/yy").format(localDt) + "|$ 123%1$s45\r\n" + "1234%1$s46|" + DateTimeFormatter.ofPattern("hh:mm:ss a").format(localDt) + "|£ 123%1$s45\r\n" + "1234%1$s5|" + DateTimeFormatter.ofPattern("EEEE, MMMM dd, yyyy").format(localDt) + "|¥ 123%1$s45\r\n" + "1%2$s234%1$s46|" + DateTimeFormatter.ofPattern("d/M/yy HH:mm").format(localDt) + "|$ 1%2$s023%1$s45\r\n" + "1%2$s234%1$s4560|" + DateTimeFormatter.ofPattern("hh:mm a").format(localDt) + "|£ 1%2$s023%1$s45\r\n" + "9%1$s88E+08|" + DateTimeFormatter.ofPattern("yyyy/MM/dd/ HH:mm").format(localDt) + "|¥ 1%2$s023%1$s45\r\n" + "9%1$s877E+08||\r\n" + "9%1$s8765E+08||\r\n", decimalSeparator, groupingSeparator)); }
Example 11
Source File: NumberUtil.java From sakai with Educational Community License v2.0 | 5 votes |
/** * @param origin number that is needed to validate * @param locale specific geographic location to validate format on origin param * @return true if number format is valid for that locale */ public static boolean isValidLocaleDouble(final String origin, Locale locale) { final DecimalFormat df = (DecimalFormat) NumberFormat.getInstance(locale); final DecimalFormatSymbols fs = df.getDecimalFormatSymbols(); final String doublePattern = "\\d+\\" + fs.getGroupingSeparator() + "\\d\\d\\d\\" + fs.getDecimalSeparator() + "\\d+|\\d+\\" + fs.getDecimalSeparator() + "\\d+|\\d+\\" + fs.getGroupingSeparator() + "\\d\\d\\d|\\d+"; return origin.matches(doublePattern); }
Example 12
Source File: NumberUtil.java From sakai with Educational Community License v2.0 | 5 votes |
/** * @param origin number that is needed to validate * @param locale specific geographic location to validate format on origin param * @return true if number format is valid for that locale */ public static boolean isValidLocaleDouble(final String origin, Locale locale) { final DecimalFormat df = (DecimalFormat) NumberFormat.getInstance(locale); final DecimalFormatSymbols fs = df.getDecimalFormatSymbols(); final String doublePattern = "\\d+\\" + fs.getGroupingSeparator() + "\\d\\d\\d\\" + fs.getDecimalSeparator() + "\\d+|\\d+\\" + fs.getDecimalSeparator() + "\\d+|\\d+\\" + fs.getGroupingSeparator() + "\\d\\d\\d|\\d+"; return origin.matches(doublePattern); }
Example 13
Source File: DefaultMonetaryAmountFormat.java From jsr354-ri with Apache License 2.0 | 5 votes |
private String getNumberPattern(String token, DecimalFormat format) { // Parse the token for int first = -1; int last = -1; DecimalFormatSymbols syms = format.getDecimalFormatSymbols(); char[] chars = token.toCharArray(); int nonMatching = 0; for(int i=0; i<chars.length;i++){ if(chars[i] ==syms.getMonetaryDecimalSeparator() || chars[i] ==syms.getMonetaryDecimalSeparator() || chars[i] ==syms.getDecimalSeparator() || chars[i] ==syms.getGroupingSeparator() || chars[i] ==syms.getMinusSign() || chars[i] ==syms.getPercent() || chars[i] ==syms.getPerMill() || chars[i] ==syms.getZeroDigit() || chars[i] ==syms.getDigit()){ if(first<0)first = i; last = i; nonMatching = 0; }else{ nonMatching++; } if(last!=-1 && first<last && nonMatching>2){ break; } } if(last!=-1 && first<last){ return token.substring(first, last+1); } return null; }
Example 14
Source File: ScaleUtilTest.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Gets the expected value. * * @param expectedValue the expected value * @return the expected value */ private static String getExpectedValue(String expectedValue) { DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance(); DecimalFormatSymbols symbols = format.getDecimalFormatSymbols(); char sep = symbols.getGroupingSeparator(); return expectedValue.replace(',', sep); }
Example 15
Source File: ConvertExcelToCSVProcessorTest.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testSkipColumnsWithEL() throws Exception { Map<String, String> attributes = new HashMap<String, String>(); attributes.put("columnsToSkip", "2"); testRunner.enqueue(new File("src/test/resources/dataformatting.xlsx").toPath(), attributes); testRunner.setProperty(ConvertExcelToCSVProcessor.COLUMNS_TO_SKIP, "${columnsToSkip}"); testRunner.setProperty(ConvertExcelToCSVProcessor.FORMAT_VALUES, "true"); testRunner.run(); testRunner.assertTransferCount(ConvertExcelToCSVProcessor.SUCCESS, 1); testRunner.assertTransferCount(ConvertExcelToCSVProcessor.ORIGINAL, 1); testRunner.assertTransferCount(ConvertExcelToCSVProcessor.FAILURE, 0); MockFlowFile ff = testRunner.getFlowFilesForRelationship(ConvertExcelToCSVProcessor.SUCCESS).get(0); Long rowsSheet = new Long(ff.getAttribute(ConvertExcelToCSVProcessor.ROW_NUM)); assertTrue(rowsSheet == 9); DecimalFormatSymbols decimalFormatSymbols = DecimalFormatSymbols.getInstance(); String decimalSeparator = decimalFormatSymbols.getDecimalSeparator() == ',' ? "\\," : String.valueOf(decimalFormatSymbols.getDecimalSeparator()); String groupingSeparator = decimalFormatSymbols.getGroupingSeparator() == ',' ? "\\," : String.valueOf(decimalFormatSymbols.getGroupingSeparator()); ff.assertContentEquals(String.format("Numbers,Money\n" + "1234%1$s456,$ 123%1$s45\n" + "1234%1$s46,£ 123%1$s45\n" + "1234%1$s5,¥ 123%1$s45\n" + "1%2$s234%1$s46,$ 1%2$s023%1$s45\n" + "1%2$s234%1$s4560,£ 1%2$s023%1$s45\n" + "9%1$s88E+08,¥ 1%2$s023%1$s45\n" + "9%1$s877E+08,\n" + "9%1$s8765E+08,\n", decimalSeparator, groupingSeparator)); }
Example 16
Source File: UserSessionLocale.java From metasfresh-webui-api-legacy with GNU General Public License v3.0 | 5 votes |
private UserSessionLocale(final String adLanguage) { final Language language = Language.getLanguage(adLanguage); if (language == null) { throw new IllegalArgumentException("No language found for " + adLanguage); } this.adLanguage = language.getAD_Language(); final DecimalFormat decimalFormat = DisplayType.getNumberFormat(DisplayType.Amount, language); final DecimalFormatSymbols decimalFormatSymbols = decimalFormat.getDecimalFormatSymbols(); numberDecimalSeparator = decimalFormatSymbols.getDecimalSeparator(); numberGroupingSeparator = decimalFormatSymbols.getGroupingSeparator(); }
Example 17
Source File: ConvertExcelToCSVProcessorTest.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testCustomEscapeCharWithEL() throws Exception { Map<String, String> attributes = new HashMap<String, String>(); attributes.put("csv.escape", "^"); testRunner.enqueue(new File("src/test/resources/dataformatting.xlsx").toPath(), attributes); testRunner.setProperty(CSVUtils.ESCAPE_CHAR, "${csv.escape}"); testRunner.setProperty(ConvertExcelToCSVProcessor.FORMAT_VALUES, "true"); testRunner.run(); testRunner.assertTransferCount(ConvertExcelToCSVProcessor.SUCCESS, 1); testRunner.assertTransferCount(ConvertExcelToCSVProcessor.ORIGINAL, 1); testRunner.assertTransferCount(ConvertExcelToCSVProcessor.FAILURE, 0); MockFlowFile ff = testRunner.getFlowFilesForRelationship(ConvertExcelToCSVProcessor.SUCCESS).get(0); Long rowsSheet = new Long(ff.getAttribute(ConvertExcelToCSVProcessor.ROW_NUM)); assertTrue(rowsSheet == 9); LocalDateTime localDt = LocalDateTime.of(2017, 1, 1, 12, 0, 0); DecimalFormatSymbols decimalFormatSymbols = DecimalFormatSymbols.getInstance(); String escapeCharValue = testRunner.getProcessContext().getProperty(CSVUtils.ESCAPE_CHAR).evaluateAttributeExpressions(ff).getValue(); String decimalSeparator = String.valueOf(decimalFormatSymbols.getDecimalSeparator()).equals(",") ? escapeCharValue + decimalFormatSymbols.getDecimalSeparator() : String.valueOf(decimalFormatSymbols.getDecimalSeparator()); String groupingSeparator = String.valueOf(decimalFormatSymbols.getGroupingSeparator()).equals(",") ? escapeCharValue + decimalFormatSymbols.getGroupingSeparator() : String.valueOf(decimalFormatSymbols.getGroupingSeparator()); ff.assertContentEquals(String.format("Numbers,Timestamps,Money\n" + "1234%1$s456," + DateTimeFormatter.ofPattern("d/M/yy").format(localDt) + ",$ 123%1$s45\n" + "1234%1$s46," + DateTimeFormatter.ofPattern("hh:mm:ss a").format(localDt) + ",£ 123%1$s45\n" + "1234%1$s5," + DateTimeFormatter.ofPattern(String.format("EEEE%1$s, MMMM dd%1$s, yyyy", escapeCharValue)).format(localDt) + ",¥ 123%1$s45\n" + "1%2$s234%1$s46," + DateTimeFormatter.ofPattern("d/M/yy HH:mm").format(localDt) + ",$ 1%2$s023%1$s45\n" + "1%2$s234%1$s4560," + DateTimeFormatter.ofPattern("hh:mm a").format(localDt) + ",£ 1%2$s023%1$s45\n" + "9%1$s88E+08," + DateTimeFormatter.ofPattern("yyyy/MM/dd/ HH:mm").format(localDt) + ",¥ 1%2$s023%1$s45\n" + "9%1$s877E+08,,\n" + "9%1$s8765E+08,,\n", decimalSeparator, groupingSeparator)); }
Example 18
Source File: GeneralUtilities.java From Knowage-Server with GNU Affero General Public License v3.0 | 5 votes |
public static char getGroupingSeparator(Locale locale) { DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance(locale); DecimalFormatSymbols decimalFormatSymbols = df.getDecimalFormatSymbols(); logger.debug("IN"); char thousands = decimalFormatSymbols.getGroupingSeparator(); logger.debug("OUT"); return thousands; }
Example 19
Source File: CellNumberFormatter.java From lams with GNU General Public License v2.0 | 5 votes |
private String localiseFormat(String format) { DecimalFormatSymbols dfs = getDecimalFormatSymbols(); if(format.contains(",") && dfs.getGroupingSeparator() != ',') { if(format.contains(".") && dfs.getDecimalSeparator() != '.') { format = replaceLast(format, "\\.", "[DECIMAL_SEPARATOR]"); format = format.replace(',', dfs.getGroupingSeparator()) .replace("[DECIMAL_SEPARATOR]", Character.toString(dfs.getDecimalSeparator())); } else { format = format.replace(',', dfs.getGroupingSeparator()); } } else if(format.contains(".") && dfs.getDecimalSeparator() != '.') { format = format.replace('.', dfs.getDecimalSeparator()); } return format; }
Example 20
Source File: ConvertExcelToCSVProcessorTest.java From nifi with Apache License 2.0 | 4 votes |
@Test public void testCustomQuoteCharWithEL() throws Exception { Map<String, String> attributes = new HashMap<String, String>(); attributes.put("csv.quote", "'"); testRunner.enqueue(new File("src/test/resources/dataformatting.xlsx").toPath(), attributes); testRunner.setProperty(CSVUtils.QUOTE_CHAR, "${csv.quote}"); testRunner.setProperty(ConvertExcelToCSVProcessor.FORMAT_VALUES, "true"); testRunner.setProperty(CSVUtils.QUOTE_MODE, CSVUtils.QUOTE_ALL); testRunner.run(); testRunner.assertTransferCount(ConvertExcelToCSVProcessor.SUCCESS, 1); testRunner.assertTransferCount(ConvertExcelToCSVProcessor.ORIGINAL, 1); testRunner.assertTransferCount(ConvertExcelToCSVProcessor.FAILURE, 0); MockFlowFile ff = testRunner.getFlowFilesForRelationship(ConvertExcelToCSVProcessor.SUCCESS).get(0); Long rowsSheet = new Long(ff.getAttribute(ConvertExcelToCSVProcessor.ROW_NUM)); assertTrue(rowsSheet == 9); LocalDateTime localDt = LocalDateTime.of(2017, 1, 1, 12, 0, 0); String quoteCharValue = testRunner.getProcessContext().getProperty(CSVUtils.QUOTE_CHAR).evaluateAttributeExpressions(ff).getValue(); DecimalFormatSymbols decimalFormatSymbols = DecimalFormatSymbols.getInstance(); char decimalSeparator = decimalFormatSymbols.getDecimalSeparator(); char groupingSeparator = decimalFormatSymbols.getGroupingSeparator(); ff.assertContentEquals("'Numbers','Timestamps','Money'\n" + addQuotingIfNeeded(String.format("1234%1$s456", decimalSeparator), ",", quoteCharValue, true) + "," + quoteCharValue + DateTimeFormatter.ofPattern("d/M/yy").format(localDt) + quoteCharValue + "," + addQuotingIfNeeded(String.format("$ 123%1$s45", decimalSeparator), ",", quoteCharValue, true) + "\n" + addQuotingIfNeeded(String.format("1234%1$s46", decimalSeparator), ",", quoteCharValue, true) + "," + quoteCharValue + DateTimeFormatter.ofPattern("hh:mm:ss a").format(localDt) + quoteCharValue + "," + addQuotingIfNeeded(String.format("£ 123%1$s45", decimalSeparator), ",", quoteCharValue, true) + "\n" + addQuotingIfNeeded(String.format("1234%1$s5", decimalSeparator), ",", quoteCharValue, true) + "," + quoteCharValue + DateTimeFormatter.ofPattern("EEEE, MMMM dd, yyyy").format(localDt) + quoteCharValue + "," + addQuotingIfNeeded(String.format("¥ 123%1$s45", decimalSeparator), ",", quoteCharValue, true) + "\n" + addQuotingIfNeeded(String.format("1%2$s234%1$s46", decimalSeparator, groupingSeparator), ",", quoteCharValue, true) + "," + quoteCharValue + DateTimeFormatter.ofPattern("d/M/yy HH:mm").format(localDt) + quoteCharValue + "," + addQuotingIfNeeded(String.format("$ 1%2$s023%1$s45", decimalSeparator, groupingSeparator), ",", quoteCharValue, true) + "\n" + addQuotingIfNeeded(String.format("1%2$s234%1$s4560", decimalSeparator, groupingSeparator), ",", quoteCharValue, true) + "," + quoteCharValue + DateTimeFormatter.ofPattern("hh:mm a").format(localDt) + quoteCharValue + "," + addQuotingIfNeeded(String.format("£ 1%2$s023%1$s45", decimalSeparator, groupingSeparator), ",", quoteCharValue, true) + "\n" + addQuotingIfNeeded(String.format("9%1$s88E+08", decimalSeparator), ",", quoteCharValue, true) + "," + quoteCharValue + DateTimeFormatter.ofPattern("yyyy/MM/dd/ HH:mm").format(localDt) + quoteCharValue + "," + addQuotingIfNeeded(String.format("¥ 1%2$s023%1$s45", decimalSeparator, groupingSeparator), ",", quoteCharValue, true) + "\n" + addQuotingIfNeeded(String.format("9%1$s877E+08", decimalSeparator), ",", quoteCharValue, true) + ",,\n" + addQuotingIfNeeded(String.format("9%1$s8765E+08", decimalSeparator), ",", quoteCharValue, true) + ",,\n"); }