您将如何在Java中实现二叉树节点类和二叉树类以支持最有效(从运行时角度来看)相等检查方法(也必须实现):
boolean equal(Node<T> root1, Node<T> root2) {}
Run Code Online (Sandbox Code Playgroud)
要么
boolean equal(Tree t1, Tree t2) {}
Run Code Online (Sandbox Code Playgroud)
首先,我创建了Node类,如下所示:
public class Node<T> {
private Node<T> left;
private Node<T> right;
private T data;
// standard getters and setters
}
Run Code Online (Sandbox Code Playgroud)
然后是equals方法,它将2个根节点作为参数并运行标准的递归比较:
public boolean equals(Node<T> root1, Node<T> root2) {
boolean rootEqual = false;
boolean lEqual = false;
boolean rEqual = false;
if (root1 != null && root2 != null) {
rootEqual = root1.getData().equals(root2.getData());
if (root1.getLeft()!=null && root2.getLeft() != null) {
// compare the left
lEqual = equals(root1.getLeft(), …Run Code Online (Sandbox Code Playgroud) int a = Integer.MIN_VALUE;
int b = -a;
System.out.println("a = "+a + " | b = "+b);
Run Code Online (Sandbox Code Playgroud)
结果:
a = -2147483648 | b = -2147483648
我期待b是一个正数.
我有一个事件流和一个key-val存储.值大小受4Kb限制.事件发生率不是很高 - 每天最多几百次.
在这个值中,我需要存储一个数据结构的序列化表示,它提供了一个有效的机制,用于读取,存储和更新3个月内的聚合事件计数,每日和每周聚合以及1/2小时的滑动窗口.
对于简单事件计数聚合和事件计数标准偏差,解决方案需要有效地执行以下任务.(下面提到的所有任务的最长期限为3个月):
我想知道:是否有任何java开源框架可以帮助实现上述?
我也很欣赏设计建议:设计模式等.
使用标准java API从头开始实现解决方案并不困难,但在此之前我会欣赏一些开源框架建议(如果有的话).
除了一些理论文章,基于SQL的解决方案和IBM(非开源工具包称为SPL)之外,谷歌搜索解决方案并没有引导我.
我面临的问题如下:
鉴于两个多边形定义了迷宫的边界和两者之间的路径(见下图),我想知道何时越过迷宫的边界.
关于我的投入:
我需要根据在限制区域内花费的时间来计算该路径的分数.
最好的方法是什么?(算法/技术/库)我没有技术限制所以解决方案可以是任何东西,例如Java,C,Perl(这是我最喜欢的)等等
我开始研究解决方案,但后来我意识到这个问题在过去已经被解决了数百万次并且没有理由"重新发明轮子":)
我是地理/几何问题的新手,我非常感谢我应该采取什么方法的建议.
干杯

我正在尝试创建基于Spring的解决方案,以便在MySQL 5.5服务器上运行批量SQL查询."查询"是指任何编译的SQL语句,因此SQL批处理作业可以包含例如几个CREATE TABLE,DELETE和INSERT语句.
我正在使用Spring Batch来达到这个目的.
我transactionManager配置如下.
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
Run Code Online (Sandbox Code Playgroud)
和dataSource:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${batch.jdbc.driver}" />
<property name="url" value="${batch.jdbc.url}" />
<property name="username" value="${batch.jdbc.user}" />
<property name="password" value="${batch.jdbc.password}" />
<property name="maxIdle" value="10" />
<property name="maxActive" value="100" />
<property name="maxWait" value="10000" />
<property name="validationQuery" value="select 1" />
<property name="testOnBorrow" value="false" />
<property name="testWhileIdle" value="true" />
<property name="timeBetweenEvictionRunsMillis" value="1200000" />
<property name="minEvictableIdleTimeMillis" value="1800000" />
<property name="numTestsPerEvictionRun" value="5" …Run Code Online (Sandbox Code Playgroud) 我想知道是否有任何标准API JodaTime来比较DateTime具有指定容差的2个对象?我正在寻找一个单线程,最好使用Joda标准API.不是像这篇文章中的时间aritmethic表达式.
理想情况下,它会是这样的:
boolean areNearlyEqual = SomeJodaAPIClass.equal(dt1, dt2, maxTolerance);
Run Code Online (Sandbox Code Playgroud)
谢谢!
我正在尝试实现以下功能:
然后逐行读取CSV文件:
我相信请求 - 回复模式适合该法案.我安装了ActiveMQ,下载了camel并尝试使用他们的jms项目.
配置组件,队列和测试连接(工作)后,我试图弄清楚实际上如何实现请求 - 回复?我没有找到任何好的例子
我有一个RouteBuilder
RouteBuilder
public class MyRouteBuilder extends RouteBuilder {
public static void main(String[] args) throws Exception {
new Main().run(args);
}
public void configure() {
from("file:src/data?noop=true")
.to("activemq:RequestQ");
from("activemq:RequestQ?exchangePattern=InOut&timeToLive=5000")
.inOut("activemq:RequestQ", "bean:myBean?method=someMethod");
}
}
Run Code Online (Sandbox Code Playgroud)
骆驼的context.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<package>org.apache.camel.example.spring</package>
</camelContext>
<bean id="jmsConnectionFactory"
class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616" />
</bean>
<bean id="pooledConnectionFactory"
class="org.apache.activemq.pool.PooledConnectionFactory"
init-method="start" destroy-method="stop">
<property name="maxConnections" value="8" />
<property name="connectionFactory" ref="jmsConnectionFactory" />
</bean> …Run Code Online (Sandbox Code Playgroud) 我需要将一个BigInteger参数传递给SQL查询.(在Postgres 9.2上)我在DAO中有这个代码:
public List<PersonInfo> select(String id) {
BigInteger bigIntId = new BigInteger(id);
JdbcTemplate select = new JdbcTemplate(dataSource);
return select
.query("SELECT * FROM PE.SUPPLIER_INPUT_DATA WHERE ID = ?",
new Object[] { bigIntId },
new PersonRowMapper());
}
Run Code Online (Sandbox Code Playgroud)
我收到以下异常:
{"error":"Error invoking getPersonInfoById.[org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback;
bad SQL grammar [SELECT * FROM PE.SUPPLIER_INPUT_DATA WHERE ID = ?];
nested exception is org.postgresql.util.PSQLException:
Can't infer the SQL type to use for an instance of java.math.BigInteger.
Use setObject() with an explicit Types value to specify the type to use.]"} …Run Code Online (Sandbox Code Playgroud) 无法在规格中找到答案.
所以,我想知道:我可以在蜂巢中做这样的事情吗?
insert into table my_table
with a as
(
select *
from ...
where ...
),
b as
(
select *
from ...
where ...
)
select
a.a,
a.b,
a.c,
b.a,
b.b,
b.c
from a join b on (a.a=b.a);
Run Code Online (Sandbox Code Playgroud) 我在电话采访中被问到以下问题:
给定以下类定义:
public class ClassA {
public ClassA(int x) {
// do some calculationand initialize the state
}
}
Run Code Online (Sandbox Code Playgroud)
及其子类,使用随机整数生成器初始化超类.
public class ClassB extends ClassA {
public ClassB() {
super(StaticUtilityClass.someRandomIntegerValGenerator())
}
}
Run Code Online (Sandbox Code Playgroud)
你需要截取x的值(someRandomIntegerValGenerator产生的随机int)并将其存储在ClassB成员中.ClassA无法更改.我最终不知道如何做到这一点,因为ClassB构造函数中的第一个调用需要调用super().直到调用了super(),没有ClassB的状态,并且someRandomIntegerValGenerator生成的值不能分配给任何ClassB成员.我唯一的方向是使用ThreadLocal,但我认为它应该是一个更简单的解决方案.
有什么想法吗?
java ×9
algorithm ×2
jdbc ×2
aggregate ×1
apache-camel ×1
architecture ×1
binary-tree ×1
constructor ×1
date ×1
geolocation ×1
geospatial ×1
hadoop ×1
hive ×1
jms ×1
jodatime ×1
perl ×1
postgresql ×1
spring ×1
spring-batch ×1
sql ×1
transactions ×1