collections

Is it Possible to Nest Collections within Collections using Wpf DataGrid?

北城余情 提交于 2019-12-22 11:28:36
问题 I want a simple sample program that nests collections within collections using Wpf DataGrid. 回答1: Here's an implementation using VB.Net codebehind. Code is needed only to create test data. Class MainWindow Public Property cs As New List(Of c1) Sub New() ' This call is required by the designer. InitializeComponent() For i1 = 1 To 3 Dim c1 = New c1 cs.Add(c1) c1.c1text = i1 For i2 = 1 To 3 Dim c2 = New c2 c1.c1col.Add(c2) c2.c2text = i1 & i2 For i3 = 1 To 3 Dim c3 = New c3 c2.c2col.Add(c3) c3

Java Program Statement : How to make a computer class having a list of printers available to it

六月ゝ 毕业季﹏ 提交于 2019-12-22 11:19:09
问题 Java Problem Statement : How to make a computer class having a list of printers available to it. I want to have a Computer class (something like this) which fullfills the problem statement public class Computers{ String computername; //printerlist public static ArrayList<String> printers=new ArrayList<String>(); // computername-Printerlist public Map<String,ArrayList<String>> printerDB=newHashMap<String,ArrayList<String>>(); public Computers(String computername){ this.computername

How to implement List, Set, and Map in null free design?

泪湿孤枕 提交于 2019-12-22 10:53:21
问题 Its great when you can return a null/empty object in most cases to avoid nulls, but what about Collection like objects? In Java, Map returns null if key in get(key) is not found in the map. The best way I can think of to avoid null s in this situation is to return an Entry<T> object, which is either the EmptyEntry<T> , or contains the value T . Sure we avoid the null , but now you can have a class cast exception if you don't check if its an EmptyEntry<T> . Is there a better way to avoid null

Hibernate - class level @Where annotation is not enforced on collections of that class?

雨燕双飞 提交于 2019-12-22 10:52:12
问题 I have annotated a Hibernate entity with a @Where attribute at the class level. This restricts which entities are loaded when I query it directly, but it does not seem to be applied to collections of that class. Is that to be expected? The docs are not clear on this: http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html#mapping-declaration-class where (optional): specifies an arbitrary SQL WHERE condition to be used when retrieving objects of this class. That sounds to me

Specifying type hints of overridden methods in generic collection

☆樱花仙子☆ 提交于 2019-12-22 10:16:23
问题 I have defined an abstract base class BaseRepository that acts as a collection of items with specified supertype Foo . The convenience classmethods in BaseRepository are annotated/type hinted to work with objects of type Foo . Here is a minimal example: from abc import ABCMeta, abstractmethod NoReturn = None class Foo(object): pass # simple data holding object class BaseRepository(object, metaclass=ABCMeta): # May be filled with subtypes of `Foo` later _items = None # type: List[Foo]

Iterable collection that can be mutated during iteration

一世执手 提交于 2019-12-22 10:12:20
问题 Is there a collection data structure in Java (and C# if you know) that can be iterated over, with the following properties: The current element can be removed without affecting the current iterator (the rest of the already-started iterator's iterations). New elements can be added, but will also not affect the current iterator—not be included as an iterated value while the current iterator's iteration is still going. In my case only one new element would be added per iteration, but none should

Processing time is exponential not linear? (VBA Collections)

时间秒杀一切 提交于 2019-12-22 09:49:12
问题 In the following code sample, I would expect the processing time to take twice as long if I change the collection's size from 10000 to 20000. Instead, the processing time is approximately 4 times as long when I make this change. It appears Dictionaries also have this kind of exponential behavior, but Arrays do not. Does anyone know why this is? Sub testing() Dim i As Long Dim coll As New Collection Dim startTime As Single For i = 1 To 10000 'change this value to 20000 to see nonlinear

How many collections are possible in a MongoDB without losing performance?

旧巷老猫 提交于 2019-12-22 09:15:38
问题 I saw that by default, a MongoDB has 24,000 collections available with a 16MB .ns file. If I increase that to 2GB (the max), can I then get 3,000,000 collections in a DB? Will there be any substantial performance decrease? 回答1: According to documentation large number of collections will not affect performance (almost not). having a large number of collections has no significant performance penalty, and results in very good performance If you need more collection you can increase .ns file via

Java 8 Stream - Find largest nested list

半腔热情 提交于 2019-12-22 08:55:15
问题 I have a Collection<List<SomeObject>> values How can I find the collection with the largest list using Streams? I have tried something like this, but it doesn't quite work values.stream().max(e -> e.stream().max(List::size).get()).get() But I get compilation error. Any ideas? 回答1: I think you want values.stream().max(Comparator.comparingInt(List::size)).get() If you need duplicates, the best solution I can think of would be something like values.stream() .collect(Collector.of( ArrayList::new,

How to combine two lists without using foreach?

爱⌒轻易说出口 提交于 2019-12-22 08:41:46
问题 Originally, I have this code: String[] A; String[] B; //... List<String> myList= new ArrayList<>(A.length + B.length); for (int i= 0; i< B.length; i++){ myList.add(A[i]); myList.add("*".equals(B[i]) ? B[i] : doSomethingWith(B[i])); } How to refactor if using, preferably, Java 8? If for instance I have these arrays A = {"one", "two", "three", "four"} B = {"five", "six", "seven", "eight"} At the end of the code, myList will be: myList = {"one", "five", "two", "six", "three", "seven", "four",