我对溪流很新,所以请帮帮我(并且温柔).
我想做的是以下内容.我有一个BufferedReader
从一个文件读取,其中每行看起来像这样:"a,b".例如:
示例输入文件
"a,b"
"d,e"
"f,g"
我想将其转换为LinkedList<String[]>
:
例 LinkedList<String[]>
[{"a","b"},{"c","d"},{"f","g"}]
你会如何使用流方法?
这是我试过的:
List numbers = reader.lines().map(s -> s.split("[\\W]")).collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)
这不起作用.我的IDE提供以下反馈:
Incompatible types. Required List but 'collect' was inferred to R: no instance(s) of type variable(s) T exist so that List<T> conforms to List
Run Code Online (Sandbox Code Playgroud)
它显示......我仍在努力想出流.
我想确定显示点集合所需的最小区域.简单的方法是循环遍历集合,如下所示:
int minX = Integer.MAX_VALUE;
int maxX = Integer.MIN_VALUE;
int minY = Integer.MAX_VALUE;
int maxY = Integer.MIN_VALUE;
for (Point point: points) {
if (point.x < minX) {
minX = point.x;
}
if (point.x > maxX) {
maxX = point.x;
}
if (point.y < minY) {
minY = point.y;
}
if (point.y > maxY) {
maxY = point.y;
}
}
Run Code Online (Sandbox Code Playgroud)
我开始了解溪流.要做到这一点,您可以执行以下操作:
int minX = points.stream().mapToInt(point -> point.x).min().orElse(-1);
int maxX = points.stream().mapToInt(point -> point.x).max().orElse(-1);
int minY = points.stream().mapToInt(point -> point.y).min().orElse(-1);
int maxY …
Run Code Online (Sandbox Code Playgroud) I am creating a game where objects implement interfaces for animations. I have a parent interface for the animations. Here is a shortened version:
public interface Animates<S extends Animator> {
S createAnimator(long animationTime);
}
Run Code Online (Sandbox Code Playgroud)
In addition, I have multiple interfaces that extend this interface. Two examples:
public interface AnimatesPaint extends Animates<PaintAnimator> {
PaintAnimator createPaintAnimator(long animationTime);
default PaintAnimator createAnimator(long animationTime) {
return createPaintAnimator(animationTime);
}
}
Run Code Online (Sandbox Code Playgroud)
and
public interface AnimatesPosition extends Animates<PositionAnimator> {
PositionAnimator createPositionAnimator(long animationTime);
@Override
default PositionAnimator createAnimator(long animationTime) { …
Run Code Online (Sandbox Code Playgroud) 在GitHub中,当我访问时,我会看到不同颜色的分支:[见解] - [网络].有些人在blue
,有些人在green
.我找不到解释.
有谁知道不同的颜色是什么意思?还有其他口味吗?像红色,橙色,紫色......
如何测试在画布上绘制内容的方法。例如,对于 Android 应用程序,我有以下代码:
@Override
public void draw(Canvas canvas) {
canvas.drawRect(rect, paint);
}
Run Code Online (Sandbox Code Playgroud)
这当然是一个非常简单的例子,但仍然是:我如何测试是否Rect
绘制了正确的结果?换句话说,如何检查 UI 是否显示正确的内容。
我想我可以检查屏幕上的所有像素,看看它们是否具有正确的属性,但我想这是一种非常幼稚的方法:)
好的,我不知道如何描述这个.我创建了一个名为ScreenAreas的类,它定义了屏幕上的特定区域.后来,我正在绘制这些ScreenAreas.
我想做的是将Paint属性(Color,strokeWidth,Shaddowsettings等)耦合到这些ScreenAreas,这样我再也不需要重新绘制所有这些属性.
这是我的ScreenArea类:import android.graphics.Canvas; import android.graphics.Paint;
public class ScreenArea {
private int xMin;
private int yMin;
private int xMax;
private int yMax;
private Paint paint;
public ScreenArea(int x1, int x2, int y1, int y2, Paint paint) {
this.setXMin(x1);
this.setXMax(x2);
this.setYMin(y1);
this.setYMax(y2);
this.paint = paint;
}
// I removed the getters and setters for clarity
public void draw(Canvas canvas){
canvas.drawRect(this.xMin, this.yMin, this.xMax, this.yMax, this.paint);
}
}
Run Code Online (Sandbox Code Playgroud)
在我的主要课程中,我使用以下方法构建它们:
paint.setColor(Color.rgb(10,10,10));
area1 = new ScreenArea (
0,
0,
100,
100,
paint);
paint.setColor(Color.rgb(100,100,100));
area2 = …
Run Code Online (Sandbox Code Playgroud) 说我有一堆恶棍.它们的特点是它们有多好,坏或难看.
static class Villain {
String name;
int good;
int bad;
int ugly;
Villain(String name, int good, int bad, int ugly) {
this.name = name;
this.good = good;
this.bad = bad;
this.ugly = ugly;
}
}
Run Code Online (Sandbox Code Playgroud)
好的,遇到帮派:
List<Villain> villains = new ArrayList<>();
villains.add(new Villain("Bob", 2, 2, 1));
villains.add(new Villain("Charley", 2, 1, 2));
villains.add(new Villain("Dave", 2, 1, 1));
villains.add(new Villain("Andy", 2, 2, 2));
villains.add(new Villain("Eddy", 1, 2, 2));
villains.add(new Villain("Franz", 1, 2, 1));
villains.add(new Villain("Guy", 1, 1, 2));
villains.add(new Villain("Harry", 1, …
Run Code Online (Sandbox Code Playgroud) 我从Angular开始。我正在创建一个使用两个组件的非常简单的应用程序。一个默认的应用程序组件和该应用程序组件的html文件中使用的第二个组件。
但是,在运行该应用程序时(有关文件,请参见下面的文件),我得到以下输出:
应用程序组件
./server.component.html
在我的情况下,而不是html文件中的实际内容:
应用程序组件
服务器组件
有人知道我在做什么错吗?
这是我的模块:(app.module.ts)
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import { ServerComponent } from './server/server.component';
@NgModule({
declarations: [
AppComponent,
ServerComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)
我的主要组件的html文件(app.component.html)
<p>App Coponent</p>
<hr>
<app-server></app-server>
Run Code Online (Sandbox Code Playgroud)
服务器组件(server / server.component.ts)
import …
Run Code Online (Sandbox Code Playgroud)