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();
}
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);
}
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);
}
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);
}
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;
}
Aggregations