Search in sources :

Example 6 with OptionalDouble

use of java.util.OptionalDouble in project jdk8u_jdk by JetBrains.

the class BasicDouble method testEmptyGet.

@Test(expectedExceptions = NoSuchElementException.class)
public void testEmptyGet() {
    OptionalDouble empty = OptionalDouble.empty();
    double got = empty.getAsDouble();
}
Also used : OptionalDouble(java.util.OptionalDouble) Test(org.testng.annotations.Test)

Example 7 with OptionalDouble

use of java.util.OptionalDouble in project jdk8u_jdk by JetBrains.

the class BasicDouble method testEmptyOrElseGetNull.

@Test(expectedExceptions = NullPointerException.class)
public void testEmptyOrElseGetNull() {
    OptionalDouble empty = OptionalDouble.empty();
    double got = empty.orElseGet(null);
}
Also used : OptionalDouble(java.util.OptionalDouble) Test(org.testng.annotations.Test)

Example 8 with OptionalDouble

use of java.util.OptionalDouble in project jdk8u_jdk by JetBrains.

the class BasicDouble method testEmptyOrElseThrow.

@Test(expectedExceptions = ObscureException.class)
public void testEmptyOrElseThrow() throws Exception {
    OptionalDouble empty = OptionalDouble.empty();
    double got = empty.orElseThrow(ObscureException::new);
}
Also used : OptionalDouble(java.util.OptionalDouble) Test(org.testng.annotations.Test)

Example 9 with OptionalDouble

use of java.util.OptionalDouble 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)

Example 10 with OptionalDouble

use of java.util.OptionalDouble in project searchcode-server by boyter.

the class SearchcodeLib method isMinified.

/**
     * Determine if a List<String> which is used to represent a code file contains a code file that is
     * suspected to be minified. This is for the purposes of excluding it from the index.
     */
public boolean isMinified(List<String> codeLines, String fileName) {
    String lowerFileName = fileName.toLowerCase();
    for (String extension : this.WHITELIST) {
        if (lowerFileName.endsWith("." + extension)) {
            return false;
        }
    }
    OptionalDouble average = codeLines.stream().map(x -> x.trim().replace(" ", "")).mapToInt(String::length).average();
    if (average.isPresent() && average.getAsDouble() > this.MINIFIEDLENGTH) {
        return true;
    }
    return false;
}
Also used : OptionalDouble(java.util.OptionalDouble)

Aggregations

OptionalDouble (java.util.OptionalDouble)11 Test (org.testng.annotations.Test)6 List (java.util.List)2 JSONException (com.alibaba.fastjson.JSONException)1 Format (java.text.Format)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 OptionalInt (java.util.OptionalInt)1 OptionalLong (java.util.OptionalLong)1 Set (java.util.Set)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Supplier (java.util.function.Supplier)1 Level (java.util.logging.Level)1 Logger (java.util.logging.Logger)1 Preferences (java.util.prefs.Preferences)1