我有一个Foo对象流.
class Foo {
private int variableCount;
public Foo(int vars) {
this.variableCount = vars;
}
public Integer getVariableCount() {
return variableCount;
}
}
Run Code Online (Sandbox Code Playgroud)
我想要一个列表,Foo它们都具有最低的variableCount.
例如
new Foo(3), new Foo(3), new Foo(2), new Foo(1), new Foo(1)
Run Code Online (Sandbox Code Playgroud)
我只希望流返回最后2 Foo秒
我试过用分组进行收集
.collect(Collectors.groupingBy((Foo foo) -> {
return foo.getVariableCount();
})
Run Code Online (Sandbox Code Playgroud)
这会返回一个Map<Integer, List<Foo>>,我不知道如何将其转换为我想要的.
提前致谢
我无法理解以下代码的行为。任何理解的帮助将不胜感激。
class Binder {
<T> void bind(Class<T> clazz, Type<T> type) {
System.out.println("clazz type");
}
<T> void bind(T obj, Type<T> type) {
System.out.println("obj type");
}
}
class Type<T> {
Type(T obj) { }
}
Binder binder = new Binder();
binder.bind(String.class, new Type<String>("x")) //works
binder.bind(Object.class, new Type<Object>(new Object())) //ambiguous
Run Code Online (Sandbox Code Playgroud)
上面的代码将失败
ERROR: reference to bind is ambiguous
both method <T>bind(java.lang.Class<T>,Type<T>) in Binder and method <T>bind(T,Type<T>) in Binder match
Run Code Online (Sandbox Code Playgroud)
如果我要删除每个方法的第二个参数,则两个绑定调用都将执行第一个方法
class Binder {
<T> void bind(Class<T> clazz) {
System.out.println("clazz");
}
<T> void bind(T obj) …Run Code Online (Sandbox Code Playgroud) 所以我设置了一个服务来从用户上传的文件中导入大量数据.我希望用户能够在处理文件时继续在网站上工作.我通过创建一个线程来完成这个.
Thread.start {
//work done here
}
Run Code Online (Sandbox Code Playgroud)
现在问题出现了,我不希望同时运行多个线程.这是我尝试过的:
class SomeService {
Thread thread = new Thread()
def serviceMethod() {
if (!thread?.isAlive()) {
thread.start {
//Do work here
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是,这不起作用.thread.isAlive()总是返回假.有关如何实现这一目标的任何想法?
所以我正在尝试使用Angular实现自定义确认框.理想情况下,我只想添加一个属性来启用该功能.例:
<button type="button" ng-click="delete(foo)">Delete</button> -> <button type="button" ng-click="delete(foo)" ng-confirm="Are you sure you want to delete this foo?">Delete</button>
Run Code Online (Sandbox Code Playgroud)
(foo在fooList中的ng-repeat ... foo里面...)
因此,我所遇到的所有问题都围绕着通常发生在不同按钮上的点击事件.我有一个单独的指令"confirmBox",它将创建我的模态(不使用引导程序)并处理所有显示/隐藏/等.
我目前使用的是要求我改变我的ng-click功能,我真的想摆脱它:
目前的实施:
<button ... ng-click="confirm('Are you sure you want to delete this foo?, 'delete', foo)">Delete</button>
var confirmModule = angular.module('confirm', []);
confirmModule.run(function($rootScope) {
$rootScope.confirm = function(text, func, obj) {
$rootScope.$broadcast('confirm', func, obj, text);
};
});
confirmModule.directive('confirmBox', function($parse) {
return {
restrict: 'A',
template: myModalTemplate,
link: function(scope, element, attrs){
element.hide();
var noBtn = element.find("[name='no']");
noBtn.bind("click", function() {
element.hide();
});
scope.$on("confirm", function(event, …Run Code Online (Sandbox Code Playgroud) 所以基本上我有这样的事情:
[a: ["c","d"], b: ["e","f"]]
Run Code Online (Sandbox Code Playgroud)
每个列表中的项目数量是任意的.如果只有一个项目,则列表不再是列表,而是一个字符串.
我想把它变成:
[ [a:"c", b:"e"], [a:"d",b:"f"] ]
Run Code Online (Sandbox Code Playgroud)
我真的不在乎解决方案是否使用Groovy方法.谢谢你的帮助!