我有一个包含a的JavaFX场景javafx.scene.layout.HBox.这HBox包含两个孩子,一个javafx.scene.control.ComboBox跟着一个javafx.scene.control.Spinner.用于说明我的问题的最小FXML文件是:
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Spinner?>
<?import javafx.scene.control.SpinnerValueFactory.IntegerSpinnerValueFactory?>
<?import javafx.scene.layout.HBox?>
<HBox xmlns="http://javafx.com/javafx/8.0.65"
xmlns:fx="http://javafx.com/fxml/1">
<children>
<ComboBox fx:id="myComboBox" />
<Spinner fx:id="mySpinner" editable="true">
<valueFactory>
<SpinnerValueFactory.IntegerSpinnerValueFactory
min="0" max="999" initialValue="0" />
</valueFactory>
</Spinner>
</children>
</HBox>
Run Code Online (Sandbox Code Playgroud)
在代码中,ComboBox正在填充非常长(以字符为单位)的字符串.我也指定了所需的宽度Spinner.以下代码代表我正在做的事情:
@FXML
private ComboBox<String> myComboBox;
@FXML
private Spinner<Integer> mySpinner;
@Override
public void initialize(URL location, ResourceBundle resources) {
myComboBox.getItems().setAll(
"Some very long string that takes up a very large portion" +
" of the screen. You can probably see where …Run Code Online (Sandbox Code Playgroud) 我正在阅读Ricahrd Warburton的Java 8书,他提供了以下练习:
尝试使用方法引用重写以下内容:
[...]
用于连接列表的flatMap方法
我真的不明白如何在flatMap这里申请.令我感到困惑的是,平面地图用于将a的每个元素映射Stream到另一个Stream,然后将它们连接在一起以产生更大的Stream但是在这里我们必须分开List<T>.
public static <T> List<T> concat(List<T> lst1, List<T> lst2){
//lst1.stream().flatMap() - it maps each elements
//of lst1 to stream and concatenates it for each
//element
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我有一张地图.让我们说吧
Map<Long, Train>
Run Code Online (Sandbox Code Playgroud)
每列火车都有一份清单
List<Integer> parts = train.getTrainParts()
Run Code Online (Sandbox Code Playgroud)
我有另一个清单
List<Integer> blueParts;
Run Code Online (Sandbox Code Playgroud)
我想迭代地图并收集所有至少有一个蓝色部分的列车.
这是Streams 的天真用法:
trainMap().values().stream().filter(part -> {
boolean found = false;
for (Long part : train.getTrainParts()) {
if (blueParts.conatins(part)) {
found = true;
}
}
return found;
).collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)
有什么更好的选择?流还是不流?
例如
tagDataContainer.getDeliveryGroupMap().values().stream().filter(dg -> {
Sets.SetView<Long> intersection = Sets.intersection(Sets.newHashSet(dg.getPlacements()), Sets.newHashSet(placementsToChangeStatusToPublish));
return intersection.size()>0;
}
);
Run Code Online (Sandbox Code Playgroud) IntelliJ可以重构这个:
class Foo {
static void bar() {}
static {
new Runnable() {
@Override
public void run() {
Foo.bar();
}
}.run();
}
}
Run Code Online (Sandbox Code Playgroud)
进入:
class Foo {
static void bar() {}
static {
((Runnable) Foo::bar).run();
}
}
Run Code Online (Sandbox Code Playgroud)
不是更好吗?(感谢Anna Kozlova).现在Android支持Java 8,我该如何在Android Studio中执行此操作?
当我@RepositoryRestController为一个实体创建一个实体时,相关的@RepositoryEventHandler方法不是通过Spring Boot 1.4.0.M3(也是Spring Boot 1.3.5)在Spring Data REST中触发的 - 这是一个bug,还是设计的?
我有一个Account实体@RepositoryEventHandler:
@Slf4j
@Component
@RepositoryEventHandler(Account.class)
public class AccountEventBridge {
@HandleBeforeCreate
public void handleBeforeCreate(Account account){
log.info("Before create " + account);
}
@HandleAfterCreate
public void handleAfterCreate(Account account){
log.info("Created " + account);
}
}
Run Code Online (Sandbox Code Playgroud)
在POST时它会触发它们:
curl -H "Content-Type: application/json" -X POST
-d '{"name":"aaa", "owner":{"email":"aaa@1010","password":"snap"}}'
http://localhost:8080/api/accounts
Run Code Online (Sandbox Code Playgroud)
除非我添加@RepositoryRestController:
@RepositoryRestController
public class AccountRespositoryRestController {
private final AccountRepository repository;
@Autowired
public AccountRespositoryRestController(AccountRepository repository) {
this.repository = repository; …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个方法,该方法接受Runnable类的构造函数并根据输入的构造函数以某种方式运行它.
所以我希望能够做到这样的事情:
executeInParallel(someRunnable::new)
executeInParallel(someOtherRunnable::new)
Run Code Online (Sandbox Code Playgroud)
我的问题是如何定义executeInParallel方法,以便能够传递我在参数中定义的任何Runnable构造函数?基本上我的问题是为了做到这一点我该如何定义这个方法?
void executeInParallel(??){ ... }
看来我只能将函数接口的方法作为参数,所以我不能executeInParallel用一个接受多个xRunnable::new构造函数的参数来定义我是否有办法在不使用某种工厂的情况下执行此操作图案?
我想说明我想要这样做的原因是我想传递构造函数而不是实例.我不能在executeInParallel之外生成实例,它必须在该方法内生成.我还想传递不同的构造函数,这些构造函数采用不同的参数
先感谢您
编辑 对不起,我希望这个问题更加清晰.
for (final Prices ppr : prices) {
if (!currency.getCode().equals(ppr.getCurrency().getCode())) {
continue;
}
return ppr.getPrice();
}
Run Code Online (Sandbox Code Playgroud)
上面的代码可以转换成Java流代码吗?我收到continue关键字错误...
我正在阅读Richard Warburton的Java 8书.这是我不太明白的引用:
让我们假设流框架正在将我们的工作拆分为在四核机器上并行运行:
我们的数据源被分解为四个元素块.
我们在每个线程上并行执行叶子计算工作 [...]
什么是叶子计算工作?它应该是什么意思?
问题:通过lambda表达式解决以下问题.给定一个字符串列表,创建一个地图
Key=Integer(string.length)
value=List
Run Code Online (Sandbox Code Playgroud)
如果两个字符串与长度匹配,则创建所有此类匹配字符串长度的列表.
我不知道如何为流中所有匹配的字符串长度创建列表!我尝试了以下方式,这给了我重复键的例外,这很明显.
private static void changeToMap(List<String> listString)
{
Map<Integer, String> map=listString.stream().collect(Collectors.toMap(x->x.toString().length(),x->x));
System.out.println(map);
}
Run Code Online (Sandbox Code Playgroud) java-8 ×10
java ×9
java-stream ×4
lambda ×2
android ×1
javafx ×1
javafx-8 ×1
reference ×1
spring-boot ×1
spring-data ×1