java-8

Why calling this function recursively does not throw a NullPointerException

我们两清 提交于 2020-01-15 06:42:07
问题 My question comes from this thread. Consider this code: public class Test { static Function<Integer, Integer> fibLambda = null; public static void main (String[] args) { fibLambda = n -> n <= 2 ? 1 : fibLambda.apply(n - 1) + fibLambda.apply(n - 2); System.out.println(fibLambda.apply(6)); } } The output above is 8. What I don't get is that how fibLamdba is initialized? It seems that I totally miss how the method invocation is done because I though that this code would produce a NPE. Hope my

visiting first level of directory and get Size of each directory Java

北城余情 提交于 2020-01-14 19:17:30
问题 I need the list of the directories in the C: And get size for each one. I am trying with this code: int[] count = {0}; try { Files.walkFileTree(Paths.get(dir.getPath()), new HashSet<FileVisitOption>(Arrays.asList(FileVisitOption.FOLLOW_LINKS)), Integer.MAX_VALUE, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file , BasicFileAttributes attrs) throws IOException { System.out.printf("Visiting file %s\n", file); ++count[0]; return FileVisitResult.CONTINUE; }

visiting first level of directory and get Size of each directory Java

偶尔善良 提交于 2020-01-14 19:16:08
问题 I need the list of the directories in the C: And get size for each one. I am trying with this code: int[] count = {0}; try { Files.walkFileTree(Paths.get(dir.getPath()), new HashSet<FileVisitOption>(Arrays.asList(FileVisitOption.FOLLOW_LINKS)), Integer.MAX_VALUE, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file , BasicFileAttributes attrs) throws IOException { System.out.printf("Visiting file %s\n", file); ++count[0]; return FileVisitResult.CONTINUE; }

LogManager.getLogger stalls Application for ~10-30 Seconds when using JDK8:

天大地大妈咪最大 提交于 2020-01-14 10:00:12
问题 // UPDATE 1: I did some more testing, removed most of the libs and commented out lib specific code resulting in the same behaviour which leeds me to the conclusion, that this problem is not (directly) caused by those libs but seems to be a general issue in my code and/or setup. The main problem here is that I do not understand why it runs perfectly when launched from within eclipse (instant startup, high performance, etc) while the same code has the described problems as soon as i launch it

Sort Javafx table on multiple columns

断了今生、忘了曾经 提交于 2020-01-14 06:29:10
问题 Can a default Javafx table sort on multiple fields by dragging the columns on a dropzone? My user need to select one or multiple columns to sort on different columns. The application is fully written in Java8 with JavaFX. The source code that I now use is: import java.util.Collections; import java.util.Comparator; import java.util.function.Function; import javafx.application.Application; import javafx.beans.property.SimpleObjectProperty; import javafx.geometry.Insets; import javafx.geometry

How to fix hibernate.transaction.flush_before_completion issue with JTA transactions in JBOSS EAP 7.2?

左心房为你撑大大i 提交于 2020-01-14 04:04:27
问题 We have recently migrated from JBOSS EAP 6.4 (JEE 6) to JBOSS EAP 7.2 (JEE 8). In the new version of EAP we are facing issues with the CMT transactions. The flush is not working until we explicitly add the method call entityManager.flush(). The same configuration was working fine in the old EAP server. The new version of container is not flushing the SQL queries during the commit of the transaction. We have setup the following properties in the persistence.xml. <persistence-unit name="ACCOUNT

Simple JSON value parsing for Java 8

人盡茶涼 提交于 2020-01-14 04:00:07
问题 Java 8 here though I have Jackson and Jettison on my classpath already (as dependencies). I am being given the following string of JSON (as an example): { "widgets": { "email": "someone@example.com", "maxSize": 50 }, "environments": { "LOCAL": { "maxSize": "40" }, "DEV": { "maxSize": "100" } }, "fruits": [ "apples", "oranges" ] } At runtime the values of the fields will be different. I am just trying to read the value of environments/DEV/maxSize from this string; what is the simplest code I

Simple JSON value parsing for Java 8

微笑、不失礼 提交于 2020-01-14 04:00:06
问题 Java 8 here though I have Jackson and Jettison on my classpath already (as dependencies). I am being given the following string of JSON (as an example): { "widgets": { "email": "someone@example.com", "maxSize": 50 }, "environments": { "LOCAL": { "maxSize": "40" }, "DEV": { "maxSize": "100" } }, "fruits": [ "apples", "oranges" ] } At runtime the values of the fields will be different. I am just trying to read the value of environments/DEV/maxSize from this string; what is the simplest code I

PriorityQueue returning elements in wrong order [duplicate]

拟墨画扇 提交于 2020-01-14 03:39:05
问题 This question already has answers here : The built-in iterator for java's PriorityQueue does not traverse the data structure in any particular order. Why? (5 answers) Sorting Priority Queue in Java [duplicate] (5 answers) Closed 7 days ago . I have a class Person which has two attributes Name( String ) and Weight( Integer ). I want to store elements in PriorityQueue according to their weight in descending order, i.e. higher the weight the top the element is in the queue. I have tried this so

Spring Integration DSL History issue

本小妞迷上赌 提交于 2020-01-14 02:59:17
问题 I have to setup the flows dynamically. Example: @Component @Slf4j public class FTPFlow { @Autowired private IntegrationFlowContext integrationFlowContext; @EventListener(ApplicationReadyEvent.class) public void setup(){ integrationFlowContext.registration(flow()).register(); } public IntegrationFlow flow() { DefaultFtpSessionFactory defaultFtpSessionFactory = new DefaultFtpSessionFactory(); defaultFtpSessionFactory.setHost("localhost"); defaultFtpSessionFactory.setPort(252);