我正在使用XML,JAXB因为我正在解组并将XML编组为Java对象,反之亦然.现在我试图根据我们的模式验证我们的XML(test.xsd).假设我的XML中缺少任何必需字段,那么我想知道在针对模式test.xsd验证XML之后缺少哪个字段.
public void unmarshal(final InputStream is) {
final XMLInputFactory factory = XMLInputFactory.newInstance();
final XMLStreamReader reader = factory.createXMLStreamReader(is);
Object req = unmarshaller.unmarshal(reader);
// how would I validate here?
}
Run Code Online (Sandbox Code Playgroud)
我如何根据test.xsd架构验证我的XML.我的test.xsd架构路径是 -
C:\工作空间\一个\ 2\3\SRC \主\的java\COM \包\ SERV\AP\VersionOne的\ test.xsd
更新:加载test.xsd为:
Schema schema = factorySchema.newSchema(new File("C:\\workspace\\one\\two\\three\\src\\main\\java\\com\\package\\serv\\ap\\versionOne\\test.xsd"));
Run Code Online (Sandbox Code Playgroud) 我如何检查IP地址是否属于私有类别?
if(isPrivateIPAddress(ipAddress)) {
//do something
}
Run Code Online (Sandbox Code Playgroud)
任何建议将不胜感激.
更新的答案
private static boolean isPrivateIPAddress(String ipAddress) {
InetAddress ia = null;
try {
InetAddress ad = InetAddress.getByName(ipAddress);
byte[] ip = ad.getAddress();
ia = InetAddress.getByAddress(ip);
} catch (UnknownHostException e) {
e.printStackTrace();
}
return ia.isSiteLocalAddress();
}
Run Code Online (Sandbox Code Playgroud)
我写了这个方法,它对我来说很好.但有没有这种方法不起作用的情况?我只是想确保它适用于每个案例.
我试图运行以下查询,这导致我 postgres error: division by zero
select
request_count,
response_count,
(response_count*100) / (request_count+response_count) AS proportion
from total_dummy_table;
Run Code Online (Sandbox Code Playgroud)
如何避免和解决division by zero错误?
尝试使用以下查询修复,但获得与上面相同的结果
SELECT
request_count,
response_count,
(response_count*100) / (request_count) AS proportion
FROM
total_dummy_table
ORDER BY
(response_count*100) /(CASE request_count WHEN 0 Then NULL ELSE request_count END) DESC NULLS FIRST
Run Code Online (Sandbox Code Playgroud)
请告诉我我在哪里做错了,或者我该如何解决这个问题.谢谢!
结果期望:
查询应该返回如下所示的内容:
Request_count | Response_count | Proportion
1603423 | 585706 | 36.52
Run Code Online (Sandbox Code Playgroud)
快速注释:表total_dummy_table没有列名proportion,该列名是结果的加法,其中计算了比例.
这是Hive中的第一个表 - 它包含有关我们正在购买的项目的信息.
CREATE EXTERNAL TABLE IF NOT EXISTS Table1 (This is the MAIN table through which comparisons need to be made)
(
ITEM_ID BIGINT,
CREATED_TIME STRING,
BUYER_ID BIGINT
)
Run Code Online (Sandbox Code Playgroud)
这是上面第一个表格中的数据
**ITEM_ID** **CREATED_TIME** **BUYER_ID**
220003038067 2012-06-21 1015826235
300003861266 2012-06-21 1015826235
140002997245 2012-06-14 1015826235
200002448035 2012-06-08 1015826235
260003553381 2012-06-07 1015826235
Run Code Online (Sandbox Code Playgroud)
这是Hive中的第二个表 - 它还包含有关我们正在购买的项目的信息.
CREATE EXTERNAL TABLE IF NOT EXISTS Table2
(
USER_ID BIGINT,
PURCHASED_ITEM ARRAY<STRUCT<PRODUCT_ID: BIGINT,TIMESTAMPS:STRING>>
)
Run Code Online (Sandbox Code Playgroud)
这是上表中的数据 -
**USER_ID** **PURCHASED_ITEM**
1015826235 [{"product_id":220003038067,"timestamps":"1340321132000"}, {"product_id":300003861266,"timestamps":"1340271857000"}, {"product_id":140002997245,"timestamps":"1339694926000"}, {"product_id":200002448035,"timestamps":"1339172659000"}, {"product_id":260003553381,"timestamps":"1339072514000"}]
Run Code Online (Sandbox Code Playgroud)
我已将数据减少到只有一个BUYER_ID(USER_ID),以使问题易于理解.
问题陈述-
我需要比较Table2 …
这是我的下面函数,我在其中传递时间戳,我只需要从时间戳返回的日期而不是小时和秒.以下代码我得到 -
private String toDate(long timestamp) {
Date date = new Date (timestamp * 1000);
return DateFormat.getInstance().format(date).toString();
}
Run Code Online (Sandbox Code Playgroud)
这是我得到的输出.
11/4/01 11:27 PM
Run Code Online (Sandbox Code Playgroud)
但我只需要这样的日期
2001-11-04
Run Code Online (Sandbox Code Playgroud)
有什么建议?
我正在为我的春季应用程序编写一些junit测试.下面是我的应用程序,它实现了InitializingBean接口,
public class InitializeFramework implements InitializingBean {
@Override
public void afterPropertiesSet() throws Exception {
try {
} catch (Exception e) {
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想afterPropertiesSet从我的junit测试中调用方法但不知何故,我无法理解这样做的正确方法是什么?我想,我可以用反射来调用这种方法,但我不认为,这是一种正确的方法吗?
任何人都可以为我提供一个简单的例子来说明如何编写一个简单的junit测试来测试类中的afterPropertiesSet方法InitializeFramework吗?
我最近开始在我们的Cassandra用例中使用Datastax Java驱动程序......我们将使用Datastax Java驱动程序读取/写入Cassandra ...
我成功地能够使用Datastax Java驱动程序创建Cassandra连接......但是我想知道,在生成环境中是否还有其他设置可以使用Datastax Java驱动程序在与Cassandra建立连接时获得更好的性能?
/**
* Creating Cassandra connection using Datastax driver
*
*/
private DatastaxConnection() {
try{
builder = Cluster.builder();
builder.addContactPoint("some-node");
// Can anybody explain me what does below piece of code do?
builder.poolingOptions().setCoreConnectionsPerHost(
HostDistance.LOCAL,
builder.poolingOptions().getMaxConnectionsPerHost(HostDistance.LOCAL));
// And also what does below piece of code is doing?
cluster = builder
.withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE)
.withReconnectionPolicy(new ConstantReconnectionPolicy(100L))
.build();
StringBuilder s = new StringBuilder();
Set<Host> allHosts = cluster.getMetadata().getAllHosts();
for (Host h : allHosts) {
s.append("[");
s.append(h.getDatacenter());
s.append("-");
s.append(h.getRack());
s.append("-");
s.append(h.getAddress());
s.append("]"); …Run Code Online (Sandbox Code Playgroud) echo "Total items: `echo $QUERY1 | awk '{print $1}'`"
echo "Total Error: `echo $QUERY1 | awk '{print $2}'`"
echo "Percentage: $QUERY2"
Run Code Online (Sandbox Code Playgroud)
如何使用单个电子邮件发送这三件事mail command.因此,每当我收到任何电子邮件时,邮件正文应如下所示,每行应该有一个echo语句 -
Total items:- Some Number
Total Error:- Some Number
Percentage:- Some Number
Run Code Online (Sandbox Code Playgroud)
我在跑步 SunOS
bash-3.00$ uname -a
SunOS lvsaishdc3in0001 5.10 Generic_142901-02 i86pc i386 i86pc
Run Code Online (Sandbox Code Playgroud) 我打算为Zookeeper使用Python kazoo库.这一切都是关于Python问题,而不是zookeeper,我想这意味着如何正确使用Python kazoo ..
我对python完全不熟悉所以我不知道如何开始以及如何使用kazoo与zookeeper连接.
这是我开始使用kazoo为Zookeeper阅读的文档.
http://kazoo.readthedocs.org/en/latest/install.html
在那个wiki中,他们要求安装kazoo.他们正在使用一些pip命令?
pip在这做什么?我目前正在使用Windows,所以我安装了cygwin并安装了python.我使用的是Python 2.7.3
host@D-SJC-00542612 ~
$ python
Python 2.7.3 (default, Dec 18 2012, 13:50:09)
[GCC 4.5.3] on cygwin
Run Code Online (Sandbox Code Playgroud)
现在我所做的是 - 我完全按照上面的网站复制了这个命令 - pip install kazoo并在我的cygwin命令提示符下运行它.
host@D-SJC-00542612 ~
$ pip install kazoo
Downloading/unpacking kazoo
Running setup.py egg_info for package kazoo
warning: no previously-included files found matching '.gitignore'
warning: no previously-included files found matching '.travis.yml'
warning: no previously-included files found matching 'Makefile'
warning: no previously-included files found matching 'run_failure.py'
warning: no previously-included files matching …Run Code Online (Sandbox Code Playgroud) 我正在开发一个项目,我需要在节点上维护一个监视器,并且节点也是子节点.我尝试过使用PathCache,但我不确定如何在这里观看儿童的孩子?
这里我的根节点是 - "/my/test"我正在使用下面的代码监视该节点.我想做的是,让手表保持在"/my/test"znode上.假设这些节点被添加到我的根节点 -
"/my/test/test1"
"/my/test/test2"
"/my/test/test3"
Run Code Online (Sandbox Code Playgroud)
然后,我应该得到通知(直到这部分我能使其工作),但如果有新的节点被添加,更新或删除来"/my/test/test1","/my/test/test2"和"/my/test/test3"那我也应该得到通知,这是我无法理解如何将部分让它起作用.
每当我加入任何新的节点"/my/test",例如"/my/test/test1","/my/test/test2","/my/test/test3"那么手表被触发同用下面的代码.但是,如果我要添加任何新节点,"/my/test/test1"或者"/my/test/test2"没有手表被触发,我不知道如何添加代码呢?有什么想法可以做到这一点?
可能如果有人在过去这样做了..所以任何一个例子对我都有很大的帮助..
以下是我的代码,适用于"/my/test"儿童,但不适用于儿童"/my/test/test1"等等.
private static final String PATH = "/my/test";
public static void main(String[] args) {
CuratorFramework client = null;
PathChildrenCache cache = null;
try {
client = CuratorClient.createSimple("localhost:2181");
client.start();
// in this example we will cache data. Notice that this is optional.
cache = new …Run Code Online (Sandbox Code Playgroud)