我正在尝试使用Guava的新Range功能来获取日期范围
Range<Date> dateRange = Ranges.range(start, BoundType.CLOSED, end, BoundType.CLOSED);
Run Code Online (Sandbox Code Playgroud)
我的目标是获得此日期范围内的小时数.所以我创建了一个像这样的DiscreteDomain:
private static final DiscreteDomain<Date> HOURS = new DiscreteDomain<Date>() {
public Date next(Date value) {
return addHours(value, 1);
}
private Date addHours(Date value, int i) {
Calendar cal = Calendar.getInstance();
cal.setTime(value);
cal.add(Calendar.HOUR_OF_DAY, i);
return cal.getTime();
}
public Date previous(Date value) {
return addHours(value, -1);
}
public long distance(Date start, Date end) {
Calendar cal1 = Calendar.getInstance();
cal1.setTime(start);
Calendar cal2 = Calendar.getInstance();
cal2.setTime(end);
return cal2.getTimeInMillis() - cal1.getTimeInMillis();
}
public Date minValue() …Run Code Online (Sandbox Code Playgroud) 代码(编译):
for (Method m : ImmutableList.class.getMethods()) {
System.out.println(m);
}
ImmutableList.copyOf(Arrays.asList(new PlayerLevel[0]));
Run Code Online (Sandbox Code Playgroud)
输出(注释和缩写):
public final void com.google.common.collect.ImmutableList.add(int,java.lang.Object)
----> public static com.google.common.collect.ImmutableList com.google.common.collect.ImmutableList.copyOf(java.lang.Iterable)
public static com.google.common.collect.ImmutableList com.google.common.collect.ImmutableList.copyOf(java.util.Iterator)
(lots of other methods)
java.lang.NoSuchMethodError: com.google.common.collect.ImmutableList.copyOf(Ljava/util/Collection;)Lcom/google/common/collect/ImmutableList;
Run Code Online (Sandbox Code Playgroud)
咦?
(如果日志不够清楚,我得到一个错误,说这ImmutableList.copyOf(List)不是一个方法,但通过循环遍历所有方法,我看到有一个copyOf(Iterable),和List implements Iterable.)
我刚刚通过搜索缓存API 找到了Guava(它非常适合我的需求).但是在阅读wiki和Javadoc时出现了一个问题- CacheBuilder可以采用什么设置的默认值?该Javadoc中的国家"这些功能都是可选的"和"创建一个新的CacheBuilder实例使用默认设置,包括强大的键,坚定的价值观,以及任何形式的自动驱逐."
在我看来,一个很好的默认值maximumSize是相对于Runtime.getRuntime().freeMemory();
最后,我想要一个使用给定系统上可用内存的缓存.所以我需要一个驱逐策略,询问有多少freeMemory()可用(可能相对于Runtime.getRuntime().maxMemory())
在WebSphere Application Server中,我看到了两个可以操作的线程池.有一个名为"默认",另一个名为"WebContainer",每个都有最小和最大大小.
这些线程池用于什么?在我的应用程序中,我使用Java的ExecutorService来推动单独的线程 - 我将从哪些池中提取?
我在WebSphere 6.1上使用Gson 1.6和Spring Framework 3.0作为Java Web应用程序.我有一些Spring bean,实际的实例是CGLIB代理.当我尝试通过Gson序列化这些bean时,该类的非原始属性不是序列化的.取而代之的是:
{
"CGLIB$BOUND":true,
"CGLIB$CONSTRUCTED":true,
"booleanProperty":true,
"anotherBooleanProperty":true,
}
Run Code Online (Sandbox Code Playgroud)
在那里我期待更像的东西
{
"stringProperty":"stringValue"
"integerObjectProperty":17,
"booleanProperty":true,
"anotherBooleanProperty":true,
}
Run Code Online (Sandbox Code Playgroud)
当我序列化非代理POJO时,输出完全符合我的预期.如何让Gson生成我期望的输出?
我收到以下代码的错误:
Iterables.any(Lists.<String>newArrayList(), new Predicate<String>() {
@Override
public boolean apply(final String arg0) {
// TODO Auto-generated method stub
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
错误:
Iterable<T>, Predicate<? super T>类型Iterables中的方法any()不适用于arguments(ArrayList<String>, newPredicate<String>(){})
我究竟做错了什么?我觉得我犯了一个愚蠢的错误.
java ×5
guava ×4
caching ×1
cglib ×1
classpath ×1
date-range ×1
gson ×1
heap-memory ×1
json ×1
memory ×1
spring ×1
threadpool ×1
websphere ×1