java-8

How to register Jackson Jdk8 module in Restlet

不羁岁月 提交于 2020-01-02 18:07:07
问题 Is it possible to register the jackson-datatype-jdk8 module in the Restlet org.restlet.ext.jackson extension package? I need to take advantage of the new Optional feature. My guess is that it should be accessible through the converter services ( getConverterService() ) but I can't find anything in the documentation that suggests exactly how setting a module is possible. 回答1: I eventually pieced together from a variety of sources an answer that works with Restlet 2.3. My guess is that this

Java 2D array into 2D ArrayList with stream

吃可爱长大的小学妹 提交于 2020-01-02 13:44:32
问题 So I have an Integer[][] data that I want to convert into an ArrayList<ArrayList<Integer>> , so I tried using streams and came up with the following line: ArrayList<ArrayList<Integer>> col = Arrays.stream(data).map(i -> Arrays.stream(i).collect(Collectors.toList())).collect(Collectors.toCollection(ArrayList<ArrayList<Integer>>::new)); But the last part collect(Collectors.toCollection(ArrayList<ArrayList<Integer>>::new)) gives me an error that it cannot convert ArrayList<ArrayList<Integer>> to

sum of BigDecimal List using streams and sum method

时光怂恿深爱的人放手 提交于 2020-01-02 13:44:23
问题 If we have all int or long or other primitive datatype value in list then we obtain sun of all values using return items.stream().mapToInt(i -> i).sum(); I have list of BigDecimal values,how to find the sum of all values using Java8 As there is no default method like mapToBigDecimal I tried to create plain map but then I cannot use sum() 回答1: List<BigDecimal> items = Arrays.asList(BigDecimal.ONE, BigDecimal.valueOf(1.5), BigDecimal.valueOf(100)); items.stream().reduce(BigDecimal.ZERO,

ajc wont compile lambda as an vararg argument

一世执手 提交于 2020-01-02 10:18:22
问题 I'm using ajc 1.8, java 8 and experiencing compiler issue. Here's the sample code. public class ExecutorTests { List<Runnable> tasks = Arrays.asList( () -> { System.out.println("task1 start"); try { Thread.sleep(1000); } catch (Exception ignored) {} System.out.println("task1 end"); }, () -> { System.out.println("task2 start"); try { Thread.sleep(1000); } catch (Exception ignored) {} System.out.println("task2 end"); }, () -> { System.out.println("task3 start"); try { Thread.sleep(1000); }

ajc wont compile lambda as an vararg argument

╄→гoц情女王★ 提交于 2020-01-02 10:18:09
问题 I'm using ajc 1.8, java 8 and experiencing compiler issue. Here's the sample code. public class ExecutorTests { List<Runnable> tasks = Arrays.asList( () -> { System.out.println("task1 start"); try { Thread.sleep(1000); } catch (Exception ignored) {} System.out.println("task1 end"); }, () -> { System.out.println("task2 start"); try { Thread.sleep(1000); } catch (Exception ignored) {} System.out.println("task2 end"); }, () -> { System.out.println("task3 start"); try { Thread.sleep(1000); }

configure a custom variant in HijrahChronology for date correction jdk 8

拥有回忆 提交于 2020-01-02 09:58:27
问题 I have used DatePicker in javafx - JDK 8 and used HijrahChronology.INSTANCE - so that the date picker shows both the calendar - everything work good enough but I am having a difference of 1 day between gregorian calendar and hijri calendar. Hijri Calendar is 1 day backward. I am trying to change the variant as per the following link https://bugs.openjdk.java.net/browse/JDK-8187987 but unable to succeed in it. Kindly explain or refer a better or a clear solution to this issue. Code:

Java Stream: difference between forEach and forEachOrdered

女生的网名这么多〃 提交于 2020-01-02 09:44:08
问题 Premise : I've already read this question and others, but I need some clarifications. I understand that Stream.forEach method makes the difference (not only) when dealing with parallel streams, and this explains why this //1 Stream.of("one ","two ","three ","four ","five ","six ") .parallel() .forEachOrdered(item -> System.out.print(item)); prints one two three four five six But when it comes to intermediate operations, the order is not guaranteed anymore when stream is parallelized. So this

Is it too costly to do a (Runnable & Serializable) when you want to send an anonymous function?

廉价感情. 提交于 2020-01-02 08:44:15
问题 I am doing sht like: executor.execute((Runnable & Serializable)func); Where func is an anonymous function, I have to heavily use this in the project otherwise I would have to create a class for every different function I want to call and implement Runnable and Serializable in each of those class, the advantage would be that I would have the type at compile time rather than casting it at run time, I would like to know if doing this cast is too costly or is trivial and does not represent a big

Java Regex - capture string with single dollar, but not when it has two successive ones

一笑奈何 提交于 2020-01-02 08:16:22
问题 I posted this question earlier. But that wasn't quite the end of it. All the rules that applied there still apply. So the strings: "%ABC%" would yield ABC as a result (capture stuff between percent signs) as would "$ABC." (capture stuff after $, giving up when another dollar or dot appears) "$ABC$XYZ" would too, and also give XYZ as a result. To add a bit more to this: "${ABC}" should yield ABC too. (ignore curly braces if present - non capture chars perhaps?). if you have two successive

Java 8 group by String

穿精又带淫゛_ 提交于 2020-01-02 08:04:15
问题 Here is my code: public class StudentData { public static List<Student> getData() { return Arrays.asList( new Student(1, "a1", 1, Arrays.asList("cricket", "football", "basketball")), new Student(2, "a2", 1, Arrays.asList("chess", "football")), new Student(3, "a3", 2, Arrays.asList("running")), new Student(4, "a4", 2, Arrays.asList("throwball", "football")), new Student(5, "a5", 3, Arrays.asList("cricket", "basketball")), new Student(6, "a6", 4, Arrays.asList("cricket")), new Student(7, "a7",