我想检查List一个对象是否包含具有特定值的字段的对象.现在,我可以使用一个循环来检查,但我很好奇是否有更多的代码有效.
就像是;
if(list.contains(new Object().setName("John"))){
//Do some stuff
}
Run Code Online (Sandbox Code Playgroud)
我知道上面的代码没有做任何事情,只是为了大致展示我想要实现的目标.
另外,为了澄清,我不想使用简单循环的原因是因为此代码当前将进入循环内循环内部的循环.为了便于阅读,我不想继续为这些循环添加循环.所以我想知道是否有任何简单的(ish)替代品.
除特定元素名称外,如何定位文档中的所有元素?
例如,我想排除terminate元素.它们可以在整个文档中出现.
<root>
<terminate attr="1" />
<other>
The brown fox jumps over the fence.
<terminate>
<b>stuff</b>
</terminate>
</other>
</root>
Run Code Online (Sandbox Code Playgroud)
我尝试使用not(..)运算符没有成功,因为我使用它错了.
坦率地说谷歌'不'是艰难的!
我刚刚开始了一个项目,让我的雇主成为管理软件.我有一个琐碎,但可能很简单的查询,我似乎无法找到任何信息.
在对象之间建立双向"关系"是谨慎/良好的做法.那么,例如,一个Client对象'有一个' Site,然后Site'有一个' Client,其中Client对象是Client'有'的Site?
public class Client {
Site site;
}
public class Site {
Client client;
}
Run Code Online (Sandbox Code Playgroud)
这有什么令人反感的(没有双关语意),还是没事?我目前正在为该项目创建一个模拟UML,这一直困扰着我.
TL; DR -我该如何检查是否之一的和所有的嵌套阵列符合规定的标准是什么?
我有一个document.每个document都有一个嵌套outer对象数组,它们自己有一个嵌套inner对象列表.我需要对文档嵌套对象中至少有一个outer匹配的所有文档执行过滤.当我说的比赛,我的意思是所有的outer嵌套对象的inner对象以某种方式相匹配.这是一个示例映射供参考;
{ "document" : {
"properties" : {
"name" : {
"type" : "string"
},
"outer" : {
"type" : "nested",
"properties" : {
"inner" : {
"type" : "nested",
"properties" : {
"match" : {
"type" : "string",
"index" : "not_analyzed"
},
"type" : {
"type" : "string",
"index" : "not_analyzed"
}
}}}}}}
}
Run Code Online (Sandbox Code Playgroud)
如果文档没有 …
我使用hadoop hive 0.9.0和1.1.2以及netbeans,但是我得到了这个错误,我无法解决这个问题请帮我代码:
public class Hive_test {
private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";
@SuppressWarnings("CallToThreadDumpStack")
public static void main(String[] args) throws SQLException {
try {
Class.forName(driverName);
} catch (ClassNotFoundException e){
e.printStackTrace();
System.exit(1);
}
System.out.println("commencer la connexion");
Connection con = DriverManager.getConnection("jdbc:hive://localhost:10000/default",""," ");
Statement stmt = con.createStatement();
ResultSet res = stmt.executeQuery("select * from STATE");
while (res.next()){
System.out.println(String.valueOf(res.getInt(1)) + "\t" + res.getString(2));
System.out.println("sql terminer");
}
}
Run Code Online (Sandbox Code Playgroud)
错误如下;
error :
commencer la connexion
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at org.apache.thrift.protocol.TBinaryProtocol.readStringBody(TBinaryProtocol.java:353)
at org.apache.thrift.protocol.TBinaryProtocol.readMessageBegin(TBinaryProtocol.java:215) …Run Code Online (Sandbox Code Playgroud) 在玩循环时创建以下代码.下面的代码将Fibonacci值存储到一个数组中,然后使用for循环打印它们.
int [] numbers;
numbers = new int[25];
numbers[0] = 1;
numbers[1] = 1;
System.out.println("Initializing the array values");
for(int i = 2; i < numbers.length; i++)
{
numbers[i] = numbers[i-1] + numbers[i-2];
}
System.out.println("Printing out Fibonacci values");
for(int i = 0; i < numbers.length; i++)
{
System.out.print(numbers[i] + ", ");
}
Run Code Online (Sandbox Code Playgroud)
上面的代码工作正常.我第一次把它扔在一起,我使用增强的for循环打印出值(代码中的第二个for循环).编译很好,但是当我运行它时,我得到以下内容;
Initializing the array values
Printing out Fibonacci values
1, 1, 2, 3, 8, 34, 377, 17711, Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 34
at ArrayDemo.main(ArrayDemo.java:21)
Run Code Online (Sandbox Code Playgroud)
我不知道出了什么问题.更改第二个循环不应更改值(您会注意到斐波纳契值是错误的(即缺少值)).而且我不明白为什么简单的增强型for循环会跳过索引.现在,这不是一个大问题,因为这不是一个项目或任何东西,它只是让我感到困惑,我无法弄清楚它为什么这样做.有线索吗?
增强的for循环就像这样;
for(int i …Run Code Online (Sandbox Code Playgroud) 我一直在尝试使用Chudnovsky算法编写一个简单的程序来计算pi,但是我一直得到错误的值输出.我写的最新代码如下,输出:
9.642715619298075837448823278218780086541162343253084414940204168864066834806498471622628399332216456e11
有谁能告诉我哪里出错了.
正如彼得·德·里瓦兹指出的那样,我正在抛弃b的值,而现在的输出为:-1.76779979383639157654764981441635890608880847407921749358841620214761790018058 3600120191582474909093e-2
Apfloat sum = new Apfloat(0);
for(int k = 0; k < n; k++) {
int thrk= 3*k;
Apfloat a = ApintMath.factorial(6*k); //(6k)! * (-1)^k
a = a.multiply(ApintMath.pow(new Apint(-1),k));
Apfloat b = new Apfloat(545140134);
b = b.multiply(new Apfloat(k));
b = b.add(new Apfloat(13591409)); // 13591409 + 545140134k
Apfloat c = ApintMath.factorial(thrk); // (3k!)
Apfloat d = ApintMath.factorial(k);
d = ApfloatMath.pow(d, 3); // (k!)^3
Apfloat e = new Apfloat(640320);
e = ApfloatMath.pow(e,(thrk)); // (640320)^(3k)
a = a.multiply(b); // …Run Code Online (Sandbox Code Playgroud) 我创建了索引,并将"建议"字段的映射类型设置为完成.我无法弄清楚如何在弹性搜索(Java API)中配置完成建议的查询
我正在尝试使用此查询来实现我的实现.
"song-suggest" : {
"text" : "n",
"completion" : {
"field" : "suggest"
}
}
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止所拥有的,
CompletionSuggestionBuilder compBuilder = new CompletionSuggestionBuilder("complete");
compBuilder.text("n");
compBuilder.field("suggest");
SearchResponse searchResponse = localClient.prepareSearch(INDEX_NAME)
.setTypes("completion")
.setQuery(QueryBuilders.matchAllQuery())
.addSuggestion(compBuilder)
.execute().actionGet();
CompletionSuggestion compSuggestion = searchResponse.getSuggest().getSuggestion("complete");
Run Code Online (Sandbox Code Playgroud)
我错过了什么,做错了吗?谢谢!
根据这一环节,既scan和count已被弃用.
我正在尝试更改我的查询以反映这一点.因此,count更改很简单,只需删除搜索类型并添加size=0到请求中,但是,我不是100%scan更改.
目前我有这个查询:
var result = ElasticClient.Search<Product>(s => s
.From(0)
.Size(10)
.SearchType(SearchType.Scan)
.Scroll("4s")
.Query
(qu =>
qu.Filtered
(fil =>
fil.Filter
(f =>
f.Bool(b => b.Must(m => m.Term("filedName", "abc")))))));
Run Code Online (Sandbox Code Playgroud)
我的理解是正确的,我需要更改的是删除searchtype并添加一个sort?即:
var result = ElasticClient.Search<Product>(s => s
.From(0)
.Size(10)
.Scroll("4s")
.Sort(x => x.OnField("_doc"))
.Query
(qu =>
qu.Filtered
(fil =>
fil.Filter
(f => f.Bool(b => b.Must(m => m.Term("filedName", "abc")))))));
Run Code Online (Sandbox Code Playgroud)
我在SortSpecialField 这里看到了一个枚举,但我不确定如何在sort参数中实际使用它.
所以,我创建了一个网站的开头.如果我在Internet Explorer 8或更低版本中运行它,那么与html相关的所有(大部分)样式似乎都会消失.这是我到目前为止检查的内容;
我已经检查了W3C验证检查它运行正常且没有错误,我检查了IE8与HTML5的兼容性,我没有使用任何不兼容的东西.我已经使用IE开发工具更改了浏览器版本的Internet Explorer,它显示css属性已成功与其对应的元素配对,但它们只是没有显示在页面上.所以我已经没有东西可以试试看了.以下是整个网站(它只是很小).
指数;
<!DOCTYPE html>
<html>
<head>
<title>Your Indy Buddy</title>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8">
</head>
<body id="body">
<nav id="titlebar">
<h1><img src="Other/eve.png" style="float:left;margin-right:200px;" alt="Image Not Displayed"/>EVE ONLINE INDY BUDDY</h1>
<nav id="utilbar">
<p style="margin-left:0px;">Your Time:</p>
<form>
Email <input type="text" name="email"/>
Password <input type="text" name="password"/>
<button type="button" onclick="">Login</button>
</form>
<p style="margin-left:0px;">Eve Time : </p>
</nav>
<p>Not registered? Register</p>
</nav>
<br/>
<nav id="main">
<h2>Test</h2>
</nav>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
style.cs;
/* Reset above occluded */
h1 {font-size:40px;margin-left:10px;margin-bottom:20px;}
p {margin-top:10px;margin-left:10px;}
#body {background-image:url("Other/background.jpg");background-color:#000000;font-family:"Arial …Run Code Online (Sandbox Code Playgroud)