Search in sources :

Example 51 with Format

use of java.text.Format in project jdk8u_jdk by JetBrains.

the class TCKDateTimeFormatter method test_toFormat_parseObject_String.

//-----------------------------------------------------------------------
@Test
public void test_toFormat_parseObject_String() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    TemporalAccessor result = (TemporalAccessor) format.parseObject("ONE30");
    assertEquals(result.isSupported(DAY_OF_MONTH), true);
    assertEquals(result.getLong(DAY_OF_MONTH), 30L);
}
Also used : Format(java.text.Format) TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeFormatter(java.time.format.DateTimeFormatter) Test(org.testng.annotations.Test)

Example 52 with Format

use of java.text.Format in project jdk8u_jdk by JetBrains.

the class TCKDateTimeFormatter method test_toFormat_Query_format.

//-----------------------------------------------------------------------
@Test
public void test_toFormat_Query_format() throws Exception {
    Format format = BASIC_FORMATTER.toFormat();
    String result = format.format(LocalDate.of(2008, 6, 30));
    assertEquals(result, "ONE30");
}
Also used : Format(java.text.Format) Test(org.testng.annotations.Test)

Example 53 with Format

use of java.text.Format in project jdk8u_jdk by JetBrains.

the class TCKDateTimeFormatter method test_toFormat_format_null.

@Test(expectedExceptions = NullPointerException.class)
public void test_toFormat_format_null() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    format.format(null);
}
Also used : Format(java.text.Format) DateTimeFormatter(java.time.format.DateTimeFormatter) Test(org.testng.annotations.Test)

Example 54 with Format

use of java.text.Format in project jgnash by ccavanaugh.

the class InvestmentPerformanceSummary method toString.

@Override
public String toString() {
    StringBuilder b = new StringBuilder();
    Format percentageFormat = NumberFormat.getPercentInstance();
    ((NumberFormat) percentageFormat).setMinimumFractionDigits(2);
    final String lineSep = System.lineSeparator();
    for (SecurityPerformanceData data : performanceData.values()) {
        b.append(data.getNode().getSymbol()).append(lineSep);
        b.append("sharesHeld: ").append(data.getSharesHeld().toPlainString()).append(lineSep);
        b.append("price: ").append(data.getPrice().toPlainString()).append(lineSep);
        b.append("costBasisPerShare: ").append(data.getCostBasisPerShare().toPlainString()).append(lineSep);
        b.append("costBasisShares: ").append(data.getCostBasisShares().toPlainString()).append(lineSep);
        b.append("totalCostBasis: ").append(data.getTotalCostBasis().toPlainString()).append(lineSep);
        b.append("heldCostBasis: ").append(data.getHeldCostBasis().toPlainString()).append(lineSep);
        b.append("marketValue: ").append(data.getMarketValue().toPlainString()).append(lineSep);
        b.append("unrealizedGains: ").append(data.getUnrealizedGains().toPlainString()).append(lineSep);
        b.append("realizedGains: ").append(data.getRealizedGains().toPlainString()).append(lineSep);
        b.append("totalGains: ").append(data.getTotalGains().toPlainString()).append(lineSep);
        b.append("totalGainsPercentage: ").append(percentageFormat.format(data.getTotalGainsPercentage())).append(lineSep);
        b.append("sharesSold: ").append(data.getSharesSold().toPlainString()).append(lineSep);
        b.append("avgSalePrice: ").append(data.getAvgSalePrice().toPlainString()).append(lineSep);
        b.append("percentPortfolio: ").append(percentageFormat.format(data.getPercentPortfolio())).append(lineSep);
        b.append(lineSep);
    }
    return b.toString();
}
Also used : Format(java.text.Format) NumberFormat(java.text.NumberFormat) NumberFormat(java.text.NumberFormat)

Example 55 with Format

use of java.text.Format in project jgnash by ccavanaugh.

the class TableViewManager method getCalculatedColumnWidth.

/**
     * Determines the preferred width of the column including contents.
     *
     * @param column {@code TableColumn} to measure content
     * @return preferred width
     */
private double getCalculatedColumnWidth(final TableColumnBase<S, ?> column) {
    double maxWidth = 0;
    /* Collect all the unique cell items and remove null*/
    final Set<Object> cellItems = new HashSet<>();
    for (int i = 0; i < tableView.getItems().size(); i++) {
        cellItems.add(column.getCellData(i));
    }
    cellItems.remove(null);
    if (cellItems.size() > 0) {
        // don't try if there is no data or the stream function will throw an error
        final OptionalDouble max = cellItems.parallelStream().filter(Objects::nonNull).mapToDouble(o -> {
            final Format format = columnFormatFactory.get().call(column);
            return JavaFXUtils.getDisplayedTextWidth(format != null ? format.format(o) : o.toString(), column.getStyle());
        }).max();
        maxWidth = max.isPresent() ? max.getAsDouble() : 0;
    }
    //noinspection SuspiciousMethodCalls
    maxWidth = Math.max(maxWidth, Math.max(column.getMinWidth(), minimumColumnWidthFactory.get().call(tableView.getColumns().indexOf(column))));
    // header text width
    maxWidth = Math.max(maxWidth, JavaFXUtils.getDisplayedTextWidth(column.getText(), column.getStyle()) * BOLD_MULTIPLIER);
    return Math.ceil(maxWidth + COLUMN_PADDING);
}
Also used : Format(java.text.Format) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) OptionalDouble(java.util.OptionalDouble) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) TableColumn(javafx.scene.control.TableColumn) EncodeDecode(jgnash.util.EncodeDecode) HashSet(java.util.HashSet) TableView(javafx.scene.control.TableView) Callback(javafx.util.Callback) ObjectProperty(javafx.beans.property.ObjectProperty) NotNull(jgnash.util.NotNull) Set(java.util.Set) Logger(java.util.logging.Logger) Preferences(java.util.prefs.Preferences) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) TableColumnBase(javafx.scene.control.TableColumnBase) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) ObservableValue(javafx.beans.value.ObservableValue) ChangeListener(javafx.beans.value.ChangeListener) Format(java.text.Format) Objects(java.util.Objects) OptionalDouble(java.util.OptionalDouble) HashSet(java.util.HashSet)

Aggregations

Format (java.text.Format)57 SimpleDateFormat (java.text.SimpleDateFormat)21 DateFormat (java.text.DateFormat)17 DecimalFormat (java.text.DecimalFormat)17 Test (org.testng.annotations.Test)16 NumberFormat (java.text.NumberFormat)15 MessageFormat (java.text.MessageFormat)14 DateTimeFormatter (java.time.format.DateTimeFormatter)13 ChoiceFormat (java.text.ChoiceFormat)11 Date (java.util.Date)8 ParsePosition (java.text.ParsePosition)5 CellFormat (org.apache.poi.ss.format.CellFormat)5 Test (org.junit.Test)5 ParseException (java.text.ParseException)4 Calendar (java.util.Calendar)4 PDataType (org.apache.phoenix.schema.types.PDataType)4 TemporalAccessor (java.time.temporal.TemporalAccessor)3 IOException (java.io.IOException)2 BigDecimal (java.math.BigDecimal)2 Connection (java.sql.Connection)2