我需要在数据库中存储逻辑条件.例如:(condition1 || condition2) && condition3应存储在数据库中.
我计划设计一个表[ ExpressionTree ]来处理结构:
Id
condition
combinationId
nextId(FK->[Condition2Combination.Id])
operator (AND, OR, null)
Run Code Online (Sandbox Code Playgroud)
如果表[ExpressionTree]中的(condition1 || condition2)&& condition3,则记录应为:
Id conditionId combinationId nextId operator
1 condition1 combination1 2 OR
2 condition2 combination1 3 AND
3 condition3 combination1 null null
Run Code Online (Sandbox Code Playgroud)
但解决方案并不好,你的建议是什么?谢谢!
我写了一个简单的类来演示链样式方法设计:
public class Cal {
private Cal(){}
private boolean isCheckArguments = false;
public static Cal useAbs() {
return new Cal(){
@Override int check(int i) {
return Math.abs(i);
}};
}
public static Cal useNormal() {
return new Cal();
}
public Cal checkArguments() {
isCheckArguments =true;
return this;
}
int check(int i){ return i;}
public int plus(int i, int j) {
if(isCheckArguments && i<j){
throw new IllegalArgumentException("i<j!");
}
return check(i+j);
}
}
Run Code Online (Sandbox Code Playgroud)
所以客户端代码可以是:
Cal cal = Cal.useAbs().checkArguments();
int sum = cal.plus(100,2);//IllegalArgumentException occurs …Run Code Online (Sandbox Code Playgroud) 在番石榴图书馆,我很困惑为什么Cache.asMap()不符合Cache.size(),除非Cache.cleanUp()被称为.
Cache<Object, Object> cache = CacheBuilder.newBuilder()
.expireAfterWrite(1, TimeUnit.SECONDS)
.build();
cache.get(...);
...
//After some seconds, all entries are expired.
//cache.asMap() is EMPTY Map, but cache.size() != 0
Run Code Online (Sandbox Code Playgroud)
所以我的问题是:这Cache.asMap()是不一致的错误Cache.size()吗?虽然我注意到javadoc Cache.size()是:
/**
* Returns the **approximate** number of entries in this cache.
*/
Run Code Online (Sandbox Code Playgroud)
我猜它可能与并发环境有关.那到底Cache.cleanUp()做了什么?
例如,数据库表中有一个整数列.然后在java模型中,它可以映射为原始int和Integer.我的问题是在这种情况下int和Integer有什么区别?和性能问题?谢谢!
如果Collection定义hasNext()而不是iterator().hasNext(),我们可以更容易地编写循环:
while(collection.hasNext()){…}
Run Code Online (Sandbox Code Playgroud)
代替:
Iterator it= collection.iterator();
While(it.hasNext()){…}
Run Code Online (Sandbox Code Playgroud)
当然,我知道循环的简单方法for(E e:collection)存在.
为什么接口Iterator存在?
我们可能会注意到许多下载站点提供了md5字符串.例如,当我下载ABC.zip时,还有一个md5字符串,如:" 2743a6a9fe6f873df1c7ed8ac91df5d7 *ABC.zip".我知道它背后的想法,它是防止文件伪造的摘要算法.
我的问题是用户如何计算ABC.zip的 md5字符串,并将其与网站提供的值进行比较?任何现有工具生成md5字符串?
我仍然是Java编程和JUnit测试的新手.我使用了junit-4.5附带的NetBeans 6.9.1(但我已将junit-4.8.2添加到我的库中).
我有许多测试类,每个类中都有许多@Test方法.
当我运行一个特定的Test类时,它一次运行一个@Test方法.我还创建了一个测试套件
@RunWith(Suite.class)
@Suite.SuiteClasses(value = {
TestClassA.class,
TestClassB.class,
TestClassC.class})
public class NewTestSuite {
}
Run Code Online (Sandbox Code Playgroud)
它将遍历我的每个测试类,并在每次运行时运行每个@Test方法.
我的问题是:我可以同时运行测试类吗?或者,在每个测试类中,是否可以同时运行@Test方法?
这样做可以让我比一次一个地运行类和方法更快地完成所有测试.
谢谢!
我搜索了互联网上的" 多路插座 ",但未能发现多路插座和普通插座行为之间的区别.
普通套接字也可以在两个方向上进行通信(读写流).
我想我必须理解多路复用概念的错误,欢迎您对多路通信的看法,谢谢!
编辑:我使用Java来实现Multiplex套接字.
我通过在jconsole中调用com.sun.management.HotSpotDiagnostic MXBean的dumpHeap操作来手动执行堆转储.所以我得到了一个转储文件.
我的问题:jconsole可以读取转储文件吗?如果没有,哪个工具可以读取它?谢谢!
编辑:现在我知道jconsole不提供读取功能,我想知道为什么jconsole只写没有读取功能的转储文件.(这不是我的问题,我只是关于它的问题)
我需要在java中实现具有最大大小的缓存,希望使用内存中缓存的实际大小而不是缓存中的元素数量来实现.此缓存基本上将String作为键,String作为值.我已经使用java的LinkedHashMap结构实现了缓存,但问题是如何知道缓存的实际大小,以便我可以调整策略以在大小太大时删除对象.
想要使用检测包的getObjectSize()计算它,但似乎没有按预期工作.
当我执行getObjectSize(一个字符串)时,无论字符串的大小是多少,它都返回相同的大小:32.我猜它只是使用字符串的引用大小或类似的东西,而不是内容.所以不知道如何有效地解决这个问题.
你有什么想法 ?
非常感谢!