java-8

Return generic functional interface in Java 8

痞子三分冷 提交于 2020-02-24 04:40:20
问题 I want to write kind of function factory. It should be a function, which is called once which different strategies as parameters. It should return a function, which selects one of this strategies dependent on the parameter, which is to be fulfilled by a predicate. Well, better look at condition3 for better understanding. The problem is, that it is not compiling. I think because the compiler can't figure out, that the functional interface H can be realized by the implementation. Without

Java 8 collector for Guava ImmutableTable using HashBasedTable as accumulator gives IllegalAccessError

∥☆過路亽.° 提交于 2020-02-23 05:57:32
问题 Process list of string via method which returns ImmutableTable<R,C,V> . For instance ImmutableTable<Integer,String,Boolean> process(String item) { /*...*/} . Collect the result i.e, merge all results (individual table may contain duplicates) and return ImmutableTable . My current implementation works when there are no duplicates: final ImmutableTable<Integer, String, Boolean> result = itemsToProcess.parallelStream() .map(item -> ProcessorInstanceProvider.get() .buildTable(item)) .collect

Java 8 collector for Guava ImmutableTable using HashBasedTable as accumulator gives IllegalAccessError

隐身守侯 提交于 2020-02-23 05:57:07
问题 Process list of string via method which returns ImmutableTable<R,C,V> . For instance ImmutableTable<Integer,String,Boolean> process(String item) { /*...*/} . Collect the result i.e, merge all results (individual table may contain duplicates) and return ImmutableTable . My current implementation works when there are no duplicates: final ImmutableTable<Integer, String, Boolean> result = itemsToProcess.parallelStream() .map(item -> ProcessorInstanceProvider.get() .buildTable(item)) .collect

Sort map in descending order java8 [duplicate]

安稳与你 提交于 2020-02-22 08:29:17
问题 This question already has answers here : How to sort a LinkedHashMap by value in decreasing order in java stream? (4 answers) Closed 3 years ago . private static <K, V extends Comparable<? super V>> Map<K, V> sortByValue( Map<K, V> map ) { Map<K, V> result = new LinkedHashMap<>(); Stream<Map.Entry<K, V>> st = map.entrySet().stream(); st.sorted( Map.Entry.comparingByValue() ) .forEachOrdered( e -> result.put(e.getKey(), e.getValue()) ); return result; } This is an example from this post. It

Sort map in descending order java8 [duplicate]

て烟熏妆下的殇ゞ 提交于 2020-02-22 08:27:27
问题 This question already has answers here : How to sort a LinkedHashMap by value in decreasing order in java stream? (4 answers) Closed 3 years ago . private static <K, V extends Comparable<? super V>> Map<K, V> sortByValue( Map<K, V> map ) { Map<K, V> result = new LinkedHashMap<>(); Stream<Map.Entry<K, V>> st = map.entrySet().stream(); st.sorted( Map.Entry.comparingByValue() ) .forEachOrdered( e -> result.put(e.getKey(), e.getValue()) ); return result; } This is an example from this post. It

How to send parameters to a reference method in a stream (java 8)?

我与影子孤独终老i 提交于 2020-02-22 08:12:21
问题 I have a list of activities(Activity) and I want to determine a data structure of the form Map(String, DateTime) (not Duration or Period; DateTime it's a must) that maps. For each activity the total duration computed over the monitoring period. The class Activity has: activityLabel(String) , startTime(DateTime) , endTime(DateTime) . I use joda time. This is what I have done: Map<String, DateTime> durations = activities.stream().collect(Collectors.toMap( it -> it.activityLabel, it ->new

How to send parameters to a reference method in a stream (java 8)?

百般思念 提交于 2020-02-22 08:10:13
问题 I have a list of activities(Activity) and I want to determine a data structure of the form Map(String, DateTime) (not Duration or Period; DateTime it's a must) that maps. For each activity the total duration computed over the monitoring period. The class Activity has: activityLabel(String) , startTime(DateTime) , endTime(DateTime) . I use joda time. This is what I have done: Map<String, DateTime> durations = activities.stream().collect(Collectors.toMap( it -> it.activityLabel, it ->new

How to send parameters to a reference method in a stream (java 8)?

久未见 提交于 2020-02-22 08:10:11
问题 I have a list of activities(Activity) and I want to determine a data structure of the form Map(String, DateTime) (not Duration or Period; DateTime it's a must) that maps. For each activity the total duration computed over the monitoring period. The class Activity has: activityLabel(String) , startTime(DateTime) , endTime(DateTime) . I use joda time. This is what I have done: Map<String, DateTime> durations = activities.stream().collect(Collectors.toMap( it -> it.activityLabel, it ->new

How to send parameters to a reference method in a stream (java 8)?

孤人 提交于 2020-02-22 08:09:31
问题 I have a list of activities(Activity) and I want to determine a data structure of the form Map(String, DateTime) (not Duration or Period; DateTime it's a must) that maps. For each activity the total duration computed over the monitoring period. The class Activity has: activityLabel(String) , startTime(DateTime) , endTime(DateTime) . I use joda time. This is what I have done: Map<String, DateTime> durations = activities.stream().collect(Collectors.toMap( it -> it.activityLabel, it ->new

How to send parameters to a reference method in a stream (java 8)?

浪子不回头ぞ 提交于 2020-02-22 08:09:28
问题 I have a list of activities(Activity) and I want to determine a data structure of the form Map(String, DateTime) (not Duration or Period; DateTime it's a must) that maps. For each activity the total duration computed over the monitoring period. The class Activity has: activityLabel(String) , startTime(DateTime) , endTime(DateTime) . I use joda time. This is what I have done: Map<String, DateTime> durations = activities.stream().collect(Collectors.toMap( it -> it.activityLabel, it ->new