我刚刚开始使用google的Guava集合(ComparisonChain和Objects).在我的pojo我覆盖了equals方法,所以我先做了这个:
return ComparisonChain.start()
.compare(this.id, other.id)
.result() == 0;
Run Code Online (Sandbox Code Playgroud)
但是,我意识到我也可以使用它:
return Objects.equal(this.id, other.id);
Run Code Online (Sandbox Code Playgroud)
我没有看到比较链何时更好,因为你可以轻松添加更多条件,如下所示:
return Objects.equal(this.name, other.name)
&& Objects.equal(this.number, other.number);
Run Code Online (Sandbox Code Playgroud)
如果您特别需要返回int,我可以看到的唯一好处.它有两个额外的方法调用(开始和结果),并且对于菜鸟来说更复杂.
我错过了ComparisonChain有明显的好处吗?
(是的,我也用适当的覆盖哈希码Objects.hashcode())
试图设置jenkins及其容器部署插件.
但是,我收到以下stacktrace:
ERROR: Publisher hudson.plugins.deploy.DeployPublisher aborted due to exception
org.codehaus.cargo.container.ContainerException: Failed to deploy [/myHome/jenkins/jobs/myAPP/workspace/target/ROOT.war]
at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.deploy(AbstractTomcatManagerDeployer.java:111)
at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:187)
at hudson.plugins.deploy.CargoContainerAdapter.deploy(CargoContainerAdapter.java:60)
at hudson.plugins.deploy.CargoContainerAdapter$1.invoke(CargoContainerAdapter.java:86)
at hudson.plugins.deploy.CargoContainerAdapter$1.invoke(CargoContainerAdapter.java:73)
at hudson.FilePath.act(FilePath.java:784)
at hudson.FilePath.act(FilePath.java:766)
at hudson.plugins.deploy.CargoContainerAdapter.redeploy(CargoContainerAdapter.java:73)
at hudson.plugins.deploy.DeployPublisher.perform(DeployPublisher.java:45)
at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:36)
at hudson.model.AbstractBuild$AbstractRunner.perform(AbstractBuild.java:700)
at hudson.model.AbstractBuild$AbstractRunner.performAllBuildSteps(AbstractBuild.java:675)
at hudson.maven.MavenModuleSetBuild$RunnerImpl.post2(MavenModuleSetBuild.java:998)
at hudson.model.AbstractBuild$AbstractRunner.post(AbstractBuild.java:622)
at hudson.model.Run.run(Run.java:1429)
at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:481)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:238)
Caused by: org.codehaus.cargo.container.tomcat.internal.TomcatManagerException: FAIL - Failed to deploy application at context path /ROOT
Run Code Online (Sandbox Code Playgroud)
哪个不是真的有用,我可以使用tomcat管理器手动部署,也可以使用命令行选项复制war文件.但我无法让自动部署工作.
我正在使用tomcat url,http://localhost:8080/当部署当前没有app时,部署失败.
任何帮助感激不尽,谢谢.
运行下面的代码会导致错误消息Bad type on operand stack.
public static void main(String args[]) {
TransformService transformService = (inputs) -> {
return new ArrayList<String>(3) {{
add("one");
add("two");
add("three");
}};
};
Collection<Integer> inputs = new HashSet<Integer>(2) {{
add(5);
add(7);
}};
Collection<String> results = transformService.transform(inputs);
System.out.println(results.size());
}
public interface TransformService {
Collection<String> transform(Collection<Integer> inputs);
}
Run Code Online (Sandbox Code Playgroud)
但是,删除lamda中的双括号初始化(匿名内部类)允许代码按预期运行,为什么?以下作品:
public class SecondLambda {
public static void main(String args[]) {
TransformService transformService = (inputs) -> {
Collection<String> results = new ArrayList<String>(3);
results.add("one");
results.add("two");
results.add("three");
return results;
};
Collection<Integer> …Run Code Online (Sandbox Code Playgroud) 每次打开任何上下文定义文件时,我都会看到此消息:

并给出以下选项:

我选择哪个选项似乎没关系我仍然会看到消息...?我在WEB-INF中有一个spring-servlet.xml,它自己导入3个不同的文件(hibernate.xml,security.xml和beans.xml,它们存储在我的资源目录中并定义与其名称相关的bean).
一切都工作正常,只是想知道消息应该表示什么?
我正在构建堆积的条形图,但是,当我为轴指定最小值时,条形的渲染会扭曲,并且轴的比例/步长是错误的。我添加的行系列确实按预期工作。
当我向轴提供最小值/最大值时:
NumericAxis<MarketDataDetailsDecorator> axis = new NumericAxis<>();
axis.setPosition(Chart.Position.BOTTOM);
axis.setMinimum(995); // only this line
axis.setMaximum(1016);// and this line get added
Run Code Online (Sandbox Code Playgroud)
您可以看到条形图在完全不同的值上工作,但是蓝线仍然正确。此外,在一个非线性方式轴增量它步骤:995997999,1001,1003,1006,1008,1010,1012,1014,1016
这是一个错误还是两个错误-还是我在api中缺少了某些内容?
这是一个突出问题的要点:https : //gist.github.com/NimChimpsky/b4dc3dddc629ffefc7be2469eaa87d3a
我正在尝试显示条形图的放大版本,值的范围是1002.5-1005.5,第一个图是正确的,但是第二个图似乎是在随机分配值?
我正在使用create-drop选项进行开发,在部署到mysql数据库时(使用hibernate 4)我得到以下输出:
15:18:07,715 ERROR SchemaExport:426 - HHH000389: Unsuccessful: alter table my_table drop foreign key FKD42DEFE312AC02F1
15:18:07,715 ERROR SchemaExport:427 - Table 'my_db.my_table' doesn't exist
Run Code Online (Sandbox Code Playgroud)
它似乎试图在创建表之前改变它.表和FK已成功创建.是什么导致错误消息?
Foo看起来有这个:
@ManyToMany
private Set<User> favouritedBy;
Run Code Online (Sandbox Code Playgroud)
用户有这个:
@ManyToMany(mappedBy = "favouritedBy")
private Set<Foo> favourites = new HashSet<Foo>();
public Set<Foo> getFavourites() {
return favourite;
}
Run Code Online (Sandbox Code Playgroud)
并且fooService具有此功能,通过tranactional方法在会话打开时访问lazyloaded集合:
@Transactional(readOnly = true)
public Set<Foo> getFavourites(User user) {
user = dao.get(User.class, user.getId()); //the dao gets a session
Set<Foo> favourites = user.getFavourites();//but the session is not here and the exception is thrown?
return favourties;
}
Run Code Online (Sandbox Code Playgroud)
编辑 修复它,不使用条件:
Set<Foo> favourites = new HashSet<Foo>(user.getFavourites());
Run Code Online (Sandbox Code Playgroud)
这用标准修复了它
Session session = sessionFactory.getCurrentSession();
final Criteria crit = session.createCriteria(Foo.class);
crit.setFetchMode("favourites", FetchMode.JOIN);
crit.add(Property.forName("id").eq(id));
return (Foo) crit.uniqueResult();
Run Code Online (Sandbox Code Playgroud) Set<Badge> availableBadges = myService.getAvailableBadges();
List<Badge> allBadges = Arrays.asList(Badge.values());
allBadges.removeAll(availableBadges);
/* Badge is an enumn */
Run Code Online (Sandbox Code Playgroud)
什么集合支持删除所有?
我不想改变我的项目/模块结构.它只是我的pom文件变得越来越复杂(由于很多依赖)并且想要将它分成易于导航的子文件......这很容易吗?
我正在寻找类似于弹簧上下文定义文件可用的导入资源的东西.
说我们有这个
// This is trivially immutable.
public class Foo {
private String bar;
public Foo(String bar) {
this.bar = bar;
}
public String getBar() {
return bar;
}
}
Run Code Online (Sandbox Code Playgroud)
是什么让这个线程不安全?继这个问题之后.
java ×8
hibernate ×2
spring ×2
collections ×1
concurrency ×1
deployment ×1
equals ×1
extjs ×1
guava ×1
gwt ×1
gxt ×1
java-8 ×1
jenkins ×1
lambda ×1
maven ×1
mysql ×1
pom.xml ×1
spring-mvc ×1
tomcat ×1