小编Gon*_*ndy的帖子

在Java 8中将Null安全集合为Stream

我正在寻找可以使收集流,但是是安全的方法.如果collection为null,则返回空流.像这样:

Utils.nullSafeStream(collection).filter(...);
Run Code Online (Sandbox Code Playgroud)

我创建了自己的方法:

public static <T> Stream<T> nullSafeStream(Collection<T> collection) {
    if (collection == null) {
        return Stream.empty();
    }
    return collection.stream();
}
Run Code Online (Sandbox Code Playgroud)

但我很好奇,如果标准JDK中有这样的东西?

java collections null java-8 java-stream

41
推荐指数
6
解决办法
6万
查看次数

什么是.springBeans文件?

我最近创建了一个小的Spring项目,该文件出现在项目根文件夹中:

.springBeans

<?xml version="1.0" encoding="UTF-8"?>
<beansProjectDescription>
    <version>1</version>
    <pluginVersion><![CDATA[3.6.3.201411271034-RELEASE]]></pluginVersion>
    <configSuffixes>
        <configSuffix><![CDATA[xml]]></configSuffix>
    </configSuffixes>
    <enableImports><![CDATA[false]]></enableImports>
    <configs>
        <config>src/test/resources/eu/gondy/myproject/test-beans.xml</config>
    </configs>
    <autoconfigs>
        <config>java:eu.gondy.myproject.rest.RestApiController</config>
    </autoconfigs>
    <configSets>
    </configSets>
</beansProjectDescription>
Run Code Online (Sandbox Code Playgroud)

这个文件是什么,它的目的是什么?

我在这个项目中使用的技术:Spring 4.1.4,Spring Boot 1.2.1,Gradle 2.3,Eclipse Luna.

java spring spring-boot

17
推荐指数
1
解决办法
8188
查看次数

Java 整数类型常量声明 - 原语还是对象?

在 Java 中,通过对象方式声明的 int 常量有什么好处:

public final static Integer SOME_CONSTANT = Integer.valueOf(99);
Run Code Online (Sandbox Code Playgroud)

而不是经典

public final static int SOME_CONSTANT = 99;
Run Code Online (Sandbox Code Playgroud)

我知道对象和原语之间的基本区别,还有自动装箱。但是我在我们公司的代码中看到了这个声明,我想知道将整数常量声明为对象有什么特别的原因吗?

java

5
推荐指数
1
解决办法
9022
查看次数

使用UUID作为主键时,Hibernate会出现错误的ID值

我的实体:

@Entity
@Table(name = "eh_portal")
public class PortalEntity {

    @Id
    @Column(name = "id", columnDefinition = "CHAR(36)")
    private UUID id; //java.util.UUID;

    @Column(name = "name")
    private String name;

    @Column(name = "url")
    private String url;

    // -- Constructor for Hibernate --
    protected PortalEntity() {
    }

    // -- Constructor for new entity in service code --
    public PortalEntity(final UUID id) {
        this.id = id;
    }
    .... getters and setters ommited
}
Run Code Online (Sandbox Code Playgroud)

存储库是Spring DATA JPA:

public interface PortalRepository extends CrudRepository<PortalEntity, UUID> {

}
Run Code Online (Sandbox Code Playgroud)

MYSQL 5数据库表定义: …

java spring hibernate spring-data

3
推荐指数
1
解决办法
1258
查看次数

Maven build - surefire插件错误 - 文件名太长

我正常使用mvn clean install构建项目,并发生以下错误:

(File name too long) -> [Help 1]
Run Code Online (Sandbox Code Playgroud)

完整的maven输出:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:19 min
[INFO] Finished at: 2017-02-23T13:42:19+01:00
[INFO] Final Memory: 67M/544M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test (default-test) on project union-sme-webapp: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test failed: java.lang.RuntimeException: org.apache.maven.surefire.report.ReporterException: When writing report: /home/gondy/projects/xxxxxxx/xxxxxxxxx/webapp/target/surefire-reports/TEST-xx.xxxxx.xxxx.xxxx.webapp.service.document.generator.statics.arrangements.XxxxxxxxxxXxxxxxxXxxxxxxxxxxxXxxxxxxxXxxxxxxxxXxxx.xml (File name too long) -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] …
Run Code Online (Sandbox Code Playgroud)

ubuntu maven maven-surefire-plugin

3
推荐指数
1
解决办法
1403
查看次数

按项目名称长度排序列表的最佳方法

哪种方式最好,看速度和舒适度?

names.sort( (a,b) -> a.getName().length() - b.getName().length() );


Collections.sort(names, Comparator.comparing( s -> Celebrity.getName().length() ))


BiFunction<Celebrity,Celebrity,Integer> bifunc = (a,b) -> Integer.compare(a.getName().length(), b.getName().length());
Collections.sort( names, bifunc::apply );
Run Code Online (Sandbox Code Playgroud)

java performance list java-8

2
推荐指数
1
解决办法
95
查看次数

在SQL Server 2008中按用户名选择最新的记录组

我有一个包含这些数据的表格:

ID   voting_ID   username   timestamp              XMLBallot
1    9           voter01    23. 4. 2012 8:54:45    xmldata
2    9           voter01    21. 4. 2012 14:00:34   xmldata
3    9           voter02    20. 4. 2012 16:01:10   xmldata
4    11          voter01    23. 4. 2012 8:40:45    xmldata
5    9           voter03    19. 4. 2012 21:18:49   xmldata
Run Code Online (Sandbox Code Playgroud)

我需要为特定的每个选民(用户名)只获得一个最新的选票voting_ID.

例如,我需要返回数据 @voting_ID=9

ID   voting_ID   username   timestamp              XMLBallot
1    9           voter01    23. 4. 2012 8:54:45    xmldata
3    9           voter02    20. 4. 2012 16:01:10   xmldata
5    9           voter03    19. 4. 2012 21:18:49   xmldata …
Run Code Online (Sandbox Code Playgroud)

sql t-sql sql-server-2008

1
推荐指数
1
解决办法
2597
查看次数