是否可以将纯Jdk8中的List分区为相等的块(子列表).
我知道可以使用Guava Lists类,但是我们可以使用纯Jdk吗?我不想在我的项目中添加新的jar,仅用于一个用例.
解决方案:
tagir-valeev提出了迄今为止最好的解决方案:
我还发现了其他三种可能性,但它们只适用于少数情况:
1.Collectors.partitioningBy()将列表拆分为2个子列表 - 如下所示:
intList.stream().collect(Collectors.partitioningBy(s -> s > 6));
List<List<Integer>> subSets = new ArrayList<List<Integer>>(groups.values());
Run Code Online (Sandbox Code Playgroud)
2.Collectors.groupingBy()将我们的列表拆分为多个分区:
Map<Integer, List<Integer>> groups =
intList.stream().collect(Collectors.groupingBy(s -> (s - 1) / 3));
List<List<Integer>> subSets = new ArrayList<List<Integer>>(groups.values());
Run Code Online (Sandbox Code Playgroud)
3.分离器分离:
List<Integer> intList = Lists.newArrayList(1, 2, 3, 0, 4, 5, 6, 0, 7, 8);
int[] indexes =
Stream.of(IntStream.of(-1), IntStream.range(0, intList.size())
.filter(i -> intList.get(i) == 0), IntStream.of(intList.size()))
.flatMapToInt(s -> s).toArray();
List<List<Integer>> subSets =
IntStream.range(0, indexes.length - 1)
.mapToObj(i …Run Code Online (Sandbox Code Playgroud) $interval当我改变路线时,我的问题仍然存在.
这是代码:
x = 2;
var multiply = function () {
x = x * 2;
if (x == 134217728) {
$interval.cancel($scope.stop);
$scope.stop = 0;
}
}
$scope.Result = function () {
$scope.stop = $interval(multiply, 1000);
}
$scope.Result();
Run Code Online (Sandbox Code Playgroud)
什么时候x<134217728,我改变路线移动到另一页.问题是$interval路线改变后不会停止.我将promise存储stop在$scope模型中的变量中.我认为$scope在路线改变后不会破坏,这就是$interval继续的原因.
我该如何解决这个问题?
我有一个带有以下代码的引导程序表.
<table id="tblPendingRequests" data-height="300">
<thead>
<tr>
<th data-field="Version">Version</th>
<th data-field="Env">Env</th>
<th data-field="Release">Release</th>
<th data-field="CreatedBy">Created By</th>
<th data-field="Action">Action</th>
</tr>
</thead>
</table>
Run Code Online (Sandbox Code Playgroud)
以下也参考了.
<script src="~/Scripts/bootstrap-table.js"></script>
<link href="~/Content/bootstrap-table.min.css" rel="stylesheet" />
Run Code Online (Sandbox Code Playgroud)
和我的jquery代码来加载数据
function loadData()
{
$(function () {
$('#tblPendingRequests').bootstrapTable({
});
});
}
Run Code Online (Sandbox Code Playgroud)
然后我将一些数据加载到此表.像这样:
var mydata = { "Version": data[index].DeploymentName, "Env": data[index].EnvName,
"Release":data[index].ReleaseName, "CreatedBy": data[index].UpdatedBy "Action": ActionButton };
testData.push(mydata);
updateData(testData);
function updateData(myData) {
$('#tblPendingRequests').bootstrapTable("append", myData);
}
Run Code Online (Sandbox Code Playgroud)
它正确地绘制数据.我在页面上有一个项目下拉列表.在项目名称的更改中,我想用新数据填充此表.它没有发生.它将数据附加到我不想要的现有表数据.
如何刷新表并在表中加载新数据.
我尝试使用 WebClient 通过 REST 调用另一个服务,但总是收到错误:
org.springframework.web.reactive.function.UnsupportedMediaTypeException:不支持内容类型“application/json”
所有分配都具有相同版本的依赖项,通过 Postman 调用资源效果很好。问题是当第一个应用程序充当代理(客户端)尝试调用第二个应用程序(服务)时
我的服务器资源:
@RequestMapping(value = "/properties")
@PutMapping(consumes = APPLICATION_JSON_UTF8_VALUE)
@ResponseStatus(CREATED)
public void saveProperty(@Valid @RequestBody PropertyForm form) {
service.save(new PropertyImpl(form));
}
Run Code Online (Sandbox Code Playgroud)
我的客户资源:
WebClient client = WebClient.create(serviceUrl);
Mono<Void> save(PropertyForm form) {
return client.put()
.uri("properties")
.contentType(MediaType.APPLICATION_JSON_UTF8)
.body(BodyInserters.fromObject(form))
.retrieve()
.bodyToMono(Void.class);
}
Run Code Online (Sandbox Code Playgroud)
我的 build.gradle 文件:
dependencies {
compile "org.springframework.boot:spring-boot-starter-reactor-netty:2.0.4.RELEASE"
compile "org.springframework.boot:spring-boot-starter-web:2.0.4.RELEASE"
compile "org.springframework:spring-webflux:5.0.4.RELEASE"
compile "javax.xml.bind:jaxb-api:2.3.0"
}
Run Code Online (Sandbox Code Playgroud)
我是否缺少一些依赖项来启用 JSON contentType?这个例子很简单,但对我来说也很成问题。
表格型号:
class PropertyForm {
private String group;
private String key;
private String value;
// getters & setters
}
Run Code Online (Sandbox Code Playgroud)
来源: …
我有这个HTML
<div class='parent'>
<div class='child'></div>
</div>
Run Code Online (Sandbox Code Playgroud)
我想向parent元素添加mouseover和mouseout事件,但问题是当光标悬停childelemet时它会触发mouseout事件,尽管它仍然在parent元素内部.我怎么能避免这个让mouseout事件只在光标离开parent项目时触发.
$(body).on('mouseover', '.parent' , function(){ /* do somthing */});
$(body).on('mouseout', '.parent' , function(){ /* do another somthing */});
Run Code Online (Sandbox Code Playgroud) 对于我使用以下模板的套房:
@RunWith(JUnitPlatform.class)
@SelectPackages("com.services.configuration")
@ExcludeTags({IntegrationTags.JPA, IntegrationTags.REST})
public class UnitTestSuite {
}
Run Code Online (Sandbox Code Playgroud)
@RunWith 是 JUnit 4 依赖项,它来自
compile "org.junit.platform:junit-platform-runner:1.0.2"
Run Code Online (Sandbox Code Playgroud)
是否可以在没有 JUnit 4 依赖项的情况下拥有 JUnit 5 套件?这样我就可以从我的依赖项中删除 JUnit 4?
不能用适当的@ExtendsWith扩展名替换吗?我只需要套房。
我遇到了这个符号的问题 - (不是 - ).当我使用tolowercase()功能时,它显示 .我不知道如何解决这个问题.请帮忙.谢谢.
public String content = "noise—tap, tap—plash, plash—as";
this.content = this.content.toLowerCase();
System.out.println(this.content);
Run Code Online (Sandbox Code Playgroud)
输出:noise tap,tap plash,plash as
我想将font-awesome中的fa-sort图标添加到rails应用程序中.我正在使用bootstrap和haml,我似乎无法弄清楚如何正确设置它.我想要旁边的排序图标.我在括号结束前尝试了结尾:class => fa_icon:sort)但是,这不起作用.然后,我尝试在表头下方添加.feature-icon.fa.fa-sort,这也不能正常工作.我已经添加了正确的gem,并在application.css结构中调用了它的依赖项,但由于显而易见的原因,无法想出这一点,请说清楚.谢谢.
%th= link_to Org.human_attribute_name(:department), params.merge(sort_field: :dept, sort_order: sort_order)
%th= link_to Org.human_attribute_name(:name), params.merge(sort_field: :name, sort_order: sort_order)
Run Code Online (Sandbox Code Playgroud) 我目前正在阅读类加载器及其层次结构功能。如果我调用下面的代码 -
ClassA a= Class.forName("com.test.ClassA")
Run Code Online (Sandbox Code Playgroud)
根据我的理解,现在它将在应用程序类加载器的帮助下初始化并加载到内存中。我有以下问题:
我有一个这样的结构形式:
<form role="search" method="get" id="searchform" action="">
<input type="text" name="s" id="s" placeholder="Search..." />
<input type="submit" id="searchsubmit" />
</form>
Run Code Online (Sandbox Code Playgroud)
我需要在您单击输入字段时更改后台提交按钮.怎么做?
java ×4
jquery ×3
css ×2
angularjs ×1
class ×1
classloader ×1
font-awesome ×1
haml ×1
html ×1
java-8 ×1
javascript ×1
junit-runner ×1
junit4 ×1
junit5 ×1
partitioning ×1
rest ×1
spring-boot ×1
spring-web ×1