collections

MongoDB Show all contents from all collections

拈花ヽ惹草 提交于 2019-12-17 17:24:21
问题 Is it possible to show all collections and its contents in MongoDB? Is the only way to show one by one? 回答1: Once you are in terminal/command line, access the database/collection you want to use as follows: show dbs use <db name> show collections choose your collection and type the following to see all contents of that collection: db.collectionName.find() More info here on the MongoDB Quick Reference Guide. 回答2: Step 1: See all your databases: show dbs Step 2: Select the database use your

How to create a HashSet<List<Int>> with distinct elements?

不问归期 提交于 2019-12-17 16:39:47
问题 I have a HashSet that contains multiple lists of integers - i.e. HashSet<List<int>> In order to maintain uniqueness I am currently having to do two things: 1. Manually loop though existing lists, looking for duplicates using SequenceEquals . 2. Sorting the individual lists so that SequenceEquals works currently. Is there a better way to do this? Is there an existing IEqualityComparer that I can provide to the HashSet so that HashSet.Add() can automatically handle uniqueness? var hashSet = new

Why is there no IArray(T) interface in .NET?

▼魔方 西西 提交于 2019-12-17 16:34:12
问题 Update 2011-Jan-06: Believe it or not, I went ahead and incorporated this interface into an open source library I've started, Tao.NET. I wrote a blog post explaining this library's IArray<T> interface, which not only addresses the issues I originally raised in this question (a year ago?!) but also provides a covariant indexed interface , something that's sorely lacking (in my opinion) in the BCL. Question (in short): I asked why .NET has IList<T> , which implements ICollection<T> and

DataGridView Selected Row Move UP and DOWN

混江龙づ霸主 提交于 2019-12-17 16:31:40
问题 How can I allow selected rows in a DataGridView (DGV) to be moved up or down. I have done this before with a ListView. Unfortunetly, for me, replacing the DGV is not an option ( curses ). By the way, the DGV datasource is a Generic Collection. The DGV has two buttons on the side, yes, UP & Down. Can anyone help point me in the right direction. I do have the code that I used for the ListView if it'll help (it did not help me). 回答1: If you programatically change the ordering of the items in

C# dictionary type with unique keys and values

冷暖自知 提交于 2019-12-17 16:27:52
问题 I was wondering if there was a built in type in C# that was like 'Dictionary' but where both TKey and TValue had to be unique. For example:: d.Add(1, "1"); d.Add(2, "1"); // This would not be OK because "1" has already been used as a value. I know this is kind of exotic, but it seems that since there are about a billion collection types in the BCL it might exist. Any ideas? 回答1: How about having Dictionary and HashSet/secondary reverse Dictionary - it will solve the issue and will perform

Java: Writing/Reading a Map from disk

亡梦爱人 提交于 2019-12-17 16:20:14
问题 I have a data structure that I would like to be able to write to a file before closing the program, and then read from the file to re-populate the structure the next time the application starts. My structure is HashMap<String, Object> . The Object is pretty simple; For member variables it has a String, and two small native arrays of type Boolean. This is a real simple application, and I wouldn't expect more than 10-15 <key,value> pairs at one time. I have been experimenting (unsuccessfully)

Recursively Get Properties & Child Properties Of An Object

痴心易碎 提交于 2019-12-17 15:57:22
问题 Ok so at first I thought this was easy enough, and maybe it is and I'm just too tired - but here's what I'm trying to do. Say I have the following objects: public class Container { public string Name { get; set; } public List<Address> Addresses { get; set; } } public class Address { public string AddressLine1 { get; set; } public string AddressLine2 { get; set; } public List<Telephone> Telephones { get; set; } } public class Telephone { public string CellPhone { get; set; } } What I need to

How would you implement the IEnumerator interface?

三世轮回 提交于 2019-12-17 15:50:40
问题 I have a class that map objects to objects, but unlike dictionary it maps them both ways. I am now trying to implement a custom IEnumerator interface that iterates through the values. public class Mapper<K,T> : IEnumerable<T>, IEnumerator<T> { C5.TreeDictionary<K,T> KToTMap = new TreeDictionary<K,T>(); C5.HashDictionary<T,K> TToKMap = new HashDictionary<T,K>(); public void Add(K key, T value) { KToTMap.Add(key, value); TToKMap.Add(value, key); } public int Count { get { return KToTMap.Count;

Scala List function for grouping consecutive identical elements

会有一股神秘感。 提交于 2019-12-17 15:44:43
问题 Given e.g.: List(5, 2, 3, 3, 3, 5, 5, 3, 3, 2, 2, 2) I'd like to get to: List(List(5), List(2), List(3, 3, 3), List(5, 5), List(3, 3), List(2, 2, 2)) I would assume there is a simple List function that does this, but am unable to find it. 回答1: This is the trick that I normally use: def split[T](list: List[T]) : List[List[T]] = list match { case Nil => Nil case h::t => val segment = list takeWhile {h ==} segment :: split(list drop segment.length) } Actually... It's not, I usually abstract over

Any implementation of Ordered Set in Java?

寵の児 提交于 2019-12-17 15:43:06
问题 If anybody is familiar with Objective-C there is a collection called NSOrderedSet that acts as Set and its items can be accessed as an Array 's ones. Is there anything like this in Java? I've heard there is a collection called LinkedHashMap, but I haven't found anything like it for a set. 回答1: Take a look at LinkedHashSet class From Java doc: Hash table and linked list implementation of the Set interface, with predictable iteration order . This implementation differs from HashSet in that it