collections

What is the use case for flatMap vs map in kotlin

霸气de小男生 提交于 2019-12-20 17:38:27
问题 in https://try.kotlinlang.org/#/Kotlin%20Koans/Collections/FlatMap/Task.kt it has sample of using flatMap and map seems both are doing the same thing, is there a sample to show the difference of using flatMap and map ? the data type: data class Shop(val name: String, val customers: List<Customer>) data class Customer(val name: String, val city: City, val orders: List<Order>) { override fun toString() = "$name from ${city.name}" } data class Order(val products: List<Product>, val isDelivered:

TreeSet not adding all elements?

喜夏-厌秋 提交于 2019-12-20 17:36:07
问题 I have been looking into the speeds of different Java collection types and have come across something weird. I am adding 1,000,000 objects from a static array to a different collection type and returning the time required. This part of the code works fine. Under further investigation I noticed that the TreeSet is not receiving all of the 1,000,000 objects, and is receiving a different amount each time. Below is the method to transfer the objects from an array to the TreeSet : public int

nhibernate custom collection handling

孤街醉人 提交于 2019-12-20 17:29:54
问题 I have a working one to many relationship (NOT bbidirectional) where Resource has a set of many Allocations implented as shown below. The domain needs to do more with the collection of allocations that just manage it with AddAllocation, RemoveAllocation, etc. So from an object perspective, I'd like to put that extra logic that is not persistent related into a different class, AllocationCollection, and make that extra class transparent to NHib. I'd also like to flesh out the responibilities of

What is the use of LinkedHashMap.removeEldestEntry?

不打扰是莪最后的温柔 提交于 2019-12-20 17:19:07
问题 I am aware the answer to this question is easily available on the internet. I need to know what happens if I choose not to removeEldestEntry . Below is my code: package collection; import java.util.*; public class MyLinkedHashMap { private static final int MAX_ENTRIES = 2; public static void main(String[] args) { LinkedHashMap lhm = new LinkedHashMap(MAX_ENTRIES, 0.75F, false) { protected boolean removeEldestEntry(Map.Entry eldest) { return false; } }; lhm.put(0, "H"); lhm.put(1, "E"); lhm

WPF ListView Databound Drag/Drop Auto Scroll

一世执手 提交于 2019-12-20 14:06:19
问题 I've been working with Bea's solution here for a while and finding it very helpful. Problem now I'm having is when I drag-n-drop items within or to another ListView control and I want to scroll up/down "during" the drag (moving an item from index 30 to index 1), it's not happening. I would have to drag to the top of the visual items in the ListView, manually scroll up, then drag again, eventually ending at the position I want. This isn't very user friendly. Now I found the function

What's the difference between Hashtable and Dictionary?

被刻印的时光 ゝ 提交于 2019-12-20 11:19:14
问题 What's the difference between Dictionary and Hashtable and how do I work with the Dictionary class in Java? 回答1: Dictionary is an abstract base class of Hashtable . Both are still in JDK for backwards compatibility with old code. We are expected to use HashMap and other implementations of Map interface introduced in Java 1.2. 回答2: The javadoc for Dictionary has your answer. The Dictionary class is the abstract parent of any class, such as Hashtable, which maps keys to values. You don't work

WPF: Bind Collection with Collection to a ListBox with groups

我与影子孤独终老i 提交于 2019-12-20 10:44:45
问题 sometimes WPF is too complex for me. I've got my "Window1" holding a collection of "Group"s. "Group" is a class with a collection of "Person"s. In the end this should be a contact list. What I simply want to do is to show the groups with its person in a ListBox, where the group name of the list groups equals the Name Property of my class "Groups". I've tried with a CollectionViewSource bound to the "Collection". The groups are shown correct, but the items of the list are equal to the group

C# like List<T> in VBA

喜你入骨 提交于 2019-12-20 10:41:43
问题 I'd like to create a List<T> on VBA like you create on C#, there is any way I can do that? I looked for questions about it here on SO, but I could not find any. 回答1: Generics appeared in C# 2.0; in VB6/VBA the closest you get is a Collection . Lets you Add , Remove and Count , but you'll need to wrap it with your own class if you want more functionality, such as AddRange , Clear and Contains . Collection takes any Variant (i.e. anything you throw at it), so you'll have to enforce the <T> by

How to create a XAML markup extension that returns a collection

Deadly 提交于 2019-12-20 10:34:42
问题 I am using XAML serialization for an object graph (outside of WPF / Silverlight) and I am trying to create a custom markup extension that will allow a collection property to be populated using references to selected members of a collection defined elsewhere in XAML. Here's a simplified XAML snippet that demonstrates what I aim to achieve: <myClass.Languages> <LanguagesCollection> <Language x:Name="English" /> <Language x:Name="French" /> <Language x:Name="Italian" /> </LanguagesCollection> <

Symmetric difference of two sets in Java

断了今生、忘了曾经 提交于 2019-12-20 10:23:22
问题 There are two TreeSet s in my app: set1 = {501,502,503,504} set2 = {502,503,504,505} I want to get the symmetric difference of these sets so that my output would be the set: set = {501,505} 回答1: You're after the symmetric difference. This is discussed in the Java tutorial. Set<Type> symmetricDiff = new HashSet<Type>(set1); symmetricDiff.addAll(set2); // symmetricDiff now contains the union Set<Type> tmp = new HashSet<Type>(set1); tmp.retainAll(set2); // tmp now contains the intersection