Search in sources :

Example 76 with FieldPosition

use of java.text.FieldPosition in project ACS by ACS-Community.

the class LogProcessorTest method createLog.

private ILogEntry createLog(String logMsg) throws Exception {
    ACSLogParser parser = ACSLogParserFactory.getParser();
    long now = Calendar.getInstance().getTimeInMillis();
    SimpleDateFormat df = new IsoDateFormat();
    Date dt = new Date(now);
    StringBuffer dateSB = new StringBuffer();
    FieldPosition pos = new FieldPosition(0);
    df.format(dt, dateSB, pos);
    StringBuilder logStr = new StringBuilder("<Info TimeStamp=\"");
    logStr.append(dateSB.toString());
    logStr.append("\" Routine=\"CacheTest::testGet\" Host=\"this\" Process=\"test\" Thread=\"main\" Context=\"\"><![CDATA[");
    logStr.append(logMsg);
    logStr.append("]]></Info>");
    ILogEntry newLog = parser.parse(logStr.toString());
    return newLog;
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) ACSLogParser(alma.acs.logging.engine.parser.ACSLogParser) IsoDateFormat(alma.acs.util.IsoDateFormat) FieldPosition(java.text.FieldPosition) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 77 with FieldPosition

use of java.text.FieldPosition in project robovm by robovm.

the class OldDecimalFormatTest method test_setGroupingUse.

public void test_setGroupingUse() {
    DecimalFormat format = new DecimalFormat();
    StringBuffer buf = new StringBuffer();
    format.setGroupingUsed(false);
    format.format(new Long(1970), buf, new FieldPosition(0));
    assertEquals("1970", buf.toString());
    assertFalse(format.isGroupingUsed());
    format.format(new Long(1970), buf, new FieldPosition(0));
    assertEquals("19701970", buf.toString());
    assertFalse(format.isGroupingUsed());
    format.setGroupingUsed(true);
    format.format(new Long(1970), buf, new FieldPosition(0));
    assertEquals("197019701,970", buf.toString());
    assertTrue(format.isGroupingUsed());
}
Also used : Support_DecimalFormat(tests.support.Support_DecimalFormat) DecimalFormat(java.text.DecimalFormat) FieldPosition(java.text.FieldPosition)

Example 78 with FieldPosition

use of java.text.FieldPosition in project poi by apache.

the class TestExcelStyleDateFormatter method test60369.

/**
     * [Bug 60369] Month format 'MMMMM' issue with TEXT-formula and Java 8
     */
@Test
public void test60369() throws ParseException {
    // Setting up the locale to be tested together with a list of asserted unicode-formatted results and put them in a map.
    Locale germanLocale = Locale.GERMAN;
    List<String> germanResultList = Arrays.asList("J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D");
    Locale russianLocale = new Locale("ru", "RU");
    List<String> russianResultList = Arrays.asList("я", "ф", "м", "а", "м", "и", "и", "а", "с", "о", "н", "д");
    Locale austrianLocale = new Locale("de", "AT");
    List<String> austrianResultList = Arrays.asList("J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D");
    Locale englishLocale = Locale.UK;
    List<String> englishResultList = Arrays.asList("J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D");
    Locale frenchLocale = Locale.FRENCH;
    List<String> frenchResultList = Arrays.asList("j", "f", "m", "a", "m", "j", "j", "a", "s", "o", "n", "d");
    Locale chineseLocale = Locale.CHINESE;
    List<String> chineseResultList = Arrays.asList("一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十", "十");
    Locale turkishLocale = new Locale("tr", "TR");
    List<String> turkishResultList = Arrays.asList("O", "Ş", "M", "N", "M", "H", "T", "A", "E", "E", "K", "A");
    Locale hungarianLocale = new Locale("hu", "HU");
    List<String> hungarianResultList = Arrays.asList("j", "f", "m", "á", "m", "j", "j", "a", "s", "o", "n", "d");
    Locale indianLocale = new Locale("en", "IN");
    List<String> indianResultList = Arrays.asList("J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D");
    Locale indonesianLocale = new Locale("in", "ID");
    List<String> indonesianResultList = Arrays.asList("J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D");
    Map<Locale, List<String>> testMap = new HashMap<Locale, List<String>>();
    testMap.put(germanLocale, germanResultList);
    testMap.put(russianLocale, russianResultList);
    testMap.put(austrianLocale, austrianResultList);
    testMap.put(englishLocale, englishResultList);
    testMap.put(frenchLocale, frenchResultList);
    testMap.put(chineseLocale, chineseResultList);
    testMap.put(turkishLocale, turkishResultList);
    testMap.put(hungarianLocale, hungarianResultList);
    testMap.put(indianLocale, indianResultList);
    testMap.put(indonesianLocale, indonesianResultList);
    // We have to set up dates as well.
    SimpleDateFormat testDateFormat = new SimpleDateFormat("dd.MM.yyyy", Locale.ROOT);
    List<Date> testDates = Arrays.asList(testDateFormat.parse("12.01.1980"), testDateFormat.parse("11.02.1995"), testDateFormat.parse("10.03.2045"), testDateFormat.parse("09.04.2016"), testDateFormat.parse("08.05.2017"), testDateFormat.parse("07.06.1945"), testDateFormat.parse("06.07.1998"), testDateFormat.parse("05.08.2099"), testDateFormat.parse("04.09.1988"), testDateFormat.parse("03.10.2023"), testDateFormat.parse("02.11.1978"), testDateFormat.parse("01.12.1890"));
    // Let's iterate over the test setup.
    for (Locale locale : testMap.keySet()) {
        //System.err.println("Locale: " + locale);
        ExcelStyleDateFormatter formatter = new ExcelStyleDateFormatter(EXCEL_DATE_FORMAT, new DateFormatSymbols(locale));
        for (int i = 0; i < 12; i++) {
            // Call the method to be tested!
            String result = formatter.format(testDates.get(i), new StringBuffer(), new FieldPosition(java.text.DateFormat.MONTH_FIELD)).toString();
            //System.err.println(result +  " - " + getUnicode(result.charAt(0)));
            assertEquals(getUnicode(testMap.get(locale).get(i).charAt(0)), getUnicode(result.charAt(0)));
        }
    }
}
Also used : Locale(java.util.Locale) HashMap(java.util.HashMap) FieldPosition(java.text.FieldPosition) Date(java.util.Date) List(java.util.List) DateFormatSymbols(java.text.DateFormatSymbols) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 79 with FieldPosition

use of java.text.FieldPosition in project dbeaver by dbeaver.

the class DateTimeDataFormatter method init.

@Override
public void init(DBSTypedObject type, Locale locale, Map<Object, Object> properties) {
    pattern = CommonUtils.toString(properties.get(PROP_PATTERN));
    dateFormat = new ExtendedDateFormat(pattern, locale);
    buffer = new StringBuffer();
    position = new FieldPosition(0);
}
Also used : ExtendedDateFormat(org.jkiss.utils.time.ExtendedDateFormat) FieldPosition(java.text.FieldPosition)

Example 80 with FieldPosition

use of java.text.FieldPosition in project jaffa-framework by jaffa-projects.

the class MaxLengthValidator method checkLength.

/**
 * This method will ensure that the input Number does not exceed the specified limits.
 * @param input The number whose length is to be checked.
 * @param intSize The upper limit on the number of digits allowed before the decimal.
 * @param fracSize The upper limit on the number of digits allowed after the decimal.
 * @return a true if the input Number is within the specified limits.
 */
private boolean checkLength(Number input, Integer intSize, Integer fracSize) {
    if (input != null && (intSize != null || fracSize != null)) {
        double value = Math.abs(input.doubleValue());
        if (intSize != null) {
            double intLimit = Math.pow(10, intSize.intValue());
            if ((long) value >= (long) intLimit)
                return false;
        }
        if (fracSize != null) {
            // @todo: should find a much more efficient way of finding the no. of fractional digits
            StringBuffer buf = new StringBuffer();
            FieldPosition fp = new FieldPosition(NumberFormat.FRACTION_FIELD);
            NumberFormat df = NumberFormat.getNumberInstance();
            df.setGroupingUsed(false);
            // THIS SHOULD BE SUFFICIENT
            df.setMaximumFractionDigits(20);
            df.format(value, buf, fp);
            String fracString = buf.substring(fp.getBeginIndex(), fp.getEndIndex());
            if (fracString != null && fracString.length() > fracSize.intValue())
                return false;
        }
    }
    return true;
}
Also used : FieldPosition(java.text.FieldPosition) NumberFormat(java.text.NumberFormat)

Aggregations

FieldPosition (java.text.FieldPosition)100 Date (java.util.Date)31 SimpleDateFormat (java.text.SimpleDateFormat)28 DecimalFormat (java.text.DecimalFormat)12 NumberFormat (java.text.NumberFormat)12 ParsePosition (java.text.ParsePosition)12 IsoDateFormat (alma.acs.util.IsoDateFormat)9 Test (org.junit.Test)9 ILogEntry (com.cosylab.logging.engine.log.ILogEntry)8 Format (java.text.Format)8 MessageFormat (java.text.MessageFormat)8 DateFormat (java.text.DateFormat)6 ACSLogParser (alma.acs.logging.engine.parser.ACSLogParser)5 IOException (java.io.IOException)3 ParseException (java.text.ParseException)3 Calendar (java.util.Calendar)3 GregorianCalendar (java.util.GregorianCalendar)3 Vector (java.util.Vector)3 ExtendedDateFormat (org.jkiss.utils.time.ExtendedDateFormat)3 LogTypeHelper (com.cosylab.logging.engine.log.LogTypeHelper)2