我想运行一个通过 Docker 运行 ES 镜像的容器测试。\n经过一番研究,我发现https://www.testcontainers.org/并且他们还有一个内置的ES 模块。
\n\n因为我的开发环境在端口 9200 和 9300 中使用 ES,所以我更喜欢使用其他端口进行测试,让\xe2\x80\x99s 说 1200 和 1300。\n因此,要从 CLI 运行 docker 映像,我使用以下命令:
\n\ndocker run -p 1200:9200 -p 1300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.6.2
我尝试使用测试容器来做到这一点,例如:
\n\nstatic ElasticsearchContainer esContainer =\n new ElasticsearchContainer("docker.elastic.co/elasticsearch/elasticsearch:7.6.2")\n .withExposedPorts(1200, 9200)\n .withExposedPorts(1300, 9300)\n .withEnv("discovery.type", "single-node");\n // .waitingFor(Wait.forHttp("/")); // Wait until elastic start \xe2\x80\x93 cause an error\n\n@BeforeClass\npublic static void initEsDockerImage() {\n esContainer.start();\n esContainer.isRunning();\n}\nRun Code Online (Sandbox Code Playgroud)\n\nesContainer.isRunning() 中的断点:
\n\n端口是 32384,运行esContainer.getHttpHostAddress()return localhost/127.0.0.1:32847 并从 docker 仪表板运行:\n无论如何,无法与两者(1200 …
我画一幅画来测试:

而且我想知道我在黑色圆圈中有多少斑点,每个斑点的大小是多少(所有斑点都是〜白色).
例如,在这种情况下,我有12个点:

我知道如何找到白色像素,并且很容易从左侧验证序列:
int whitePixels = 0;
for (int i = 0; i < height; ++i)
{
uchar * pixel = image.ptr<uchar>(i);
for (int j = 0; j < width; ++j)
{
if (j>0 && pixel[j-1]==0) // to group pixels for one spot
whitePixels++;
}
}
Run Code Online (Sandbox Code Playgroud)
但很明显,这段代码不够好(blob可以对角线等).
所以,底线,我需要帮助:我如何定义blob?
谢谢
我正在对加速度计传感器进行采样,并使用库(4.0.1)实时呈现图表Graph View。
该应用程序运行良好,只是图表错误:
正如您在图片中看到的,Z 轴(洋红色)的值为 ~9.8,但在图表中显示为 ~15,Y 轴(绿色)的值为 0.2,但在图表中我们在零和相同的想法下与 X 轴。
这是我的代码:
SensorManager sensorManager;
TextView tvX, tvY, tvZ;
GraphView graph;
LineGraphSeries<DataPoint> seriesX, seriesY, seriesZ;
long startTime;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_runtime_graph);
tvX = (TextView) findViewById(R.id.tvAcc_X); // color : blue
tvY = (TextView) findViewById(R.id.tvAcc_Y); // color : green
tvZ = (TextView) findViewById(R.id.tvAcc_Z); // color : magenta
graph = (GraphView) findViewById(R.id.graph);
seriesX = new LineGraphSeries<>();
seriesY = new LineGraphSeries<>();
seriesZ = new LineGraphSeries<>();
seriesX.setColor(Color.BLUE);
seriesY.setColor(Color.GREEN);
seriesZ.setColor(Color.MAGENTA);
graph.addSeries(seriesX); …Run Code Online (Sandbox Code Playgroud) 我想建立一个方法int getIndexOfFirstFound(String text, String[] words)。
该方法接收文本和单词数组,并应返回找到的第一个单词的索引。
我知道用简单的迭代来做,就像这样:
for (String word : words) {
if (text.indexOf(word) != -1) return text.indexOf(word);
}
return -1;
Run Code Online (Sandbox Code Playgroud)
但是对于我的培训,如果可能的话,我会看看如何使用 lambda 来做到这一点......我知道我可以检查字符串是否包含数组中的一个单词:Arrays.stream(words).parallel().anyMatch(text::contains)但我不知道如何返回索引..
很高兴知道如何用现代方式找到第一个找到的单词索引,谢谢!
PS示例:
Text= "你好我是你的短信,你好吗?"
Words= [“你的”,“是”]
结果应该是“你的”(10)的索引
我想获得splitContainer.Panel2下所有按钮和标签的背景颜色.当我尝试它时,我发现我没有成功运行任何控件(在Panel2下)我尝试这个代码:
foreach (Control c in ((Control)splitContainer.Panel2).Controls)
{
if ((c is Button) || (c is Label))
MessageBox.Show("Name: " + c.Name + " Back Color: " + c.BackColor);
}
Run Code Online (Sandbox Code Playgroud)
如何在splitContainer.Panel2下获取所有标签和按钮的所有背景颜色?
编辑:
问题是基于真实场景,我简化了用例:
假设我们有一个带有0到999之间值的微调器和循环视图.另外,对于常规的回收者滑动选项,用户也可以从微调器中选择一个数字,并且回收器将滚动到索引.
问题:当当前页面和新的微调器值之间的差值很大时,滚动视图需要花费大量时间(例如,我们在位置0,现在用户从微调器400中选择).
下面是代码(项目布局仅包含textview):
public class MainActivity extends AppCompatActivity {
RecyclerView recyclerView;
Spinner spinner;
List<Integer> items = new ArrayList<>();
ItemAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// init "database"
for (int i = 0; i < 1000; i++)
items.add(i);
// Spinner
spinner = (Spinner) findViewById(R.id.spinner);
final ArrayAdapter<Integer> spinnerAdapter = new ArrayAdapter<Integer>(this, R.layout.support_simple_spinner_dropdown_item, items);
spinner.setAdapter(spinnerAdapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
recyclerView.smoothScrollToPosition(i);
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) …Run Code Online (Sandbox Code Playgroud) android android-animation recycler-adapter android-recyclerview