collections

Map in Map in Guava

不羁岁月 提交于 2020-01-12 13:46:30
问题 I have some code with Map<String, Map<String, String>> objects, which works (it is instantiated as a HashMap of HashMaps), but I wonder whether there is a better way to represent this data structure in Guava. I have considered Multimap , but while there is ListMultimap and SetMultimap in Guava, I have found no "MapMultimap". I have also checked Table, which seems to be more like it, but its name is making me uncomfortable: what I have is definitely not a table but a tree. (There is no overlap

Why heap is better than binary tree to represent a priority queue?

心已入冬 提交于 2020-01-12 05:29:06
问题 In a (max) heap it is easy to find the biggest item in O(1) time, but to actually remove it you need complexity of O(log(n)) . So if the insertion and deletion from a heap is both O(log(n)) , what are the advantages of a heap over binary tree for representing a priority queue? 回答1: Heaps use less memory. They can be implemented as arrays and thus there is no overhead for storing pointers. (A binary tree CAN be implemented as an array, but there is likely to be many empty "gaps" which could

Union two ObservableCollection Lists

杀马特。学长 韩版系。学妹 提交于 2020-01-12 05:18:05
问题 I have two ObservableCollection lists, that i want to unite. My naive approach was to use the Union - Method: ObservableCollection<Point> unitedPoints = observableCollection1.Union(observableCollection2); ObservableCollection1/2 are of type ObservableCollection too. But the Compiler throws the following error for this line: The Type "System.Collections.Generic.IEnumerable" can't be converted implicit to "System.Collections.ObjectModel.ObservableCollection". An explicite conversion already

Laravel collection contains

人盡茶涼 提交于 2020-01-12 04:30:44
问题 I'm using the Laravel contains method on a collection https://laravel.com/docs/5.3/collections#method-contains. But it does not work for me. foreach ($this->options as $option) { if($options->contains($option->id)) { dd('test'); } } dd($options); looks like this: Collection {#390 #items: array:1 [ 0 => array:3 [ 0 => array:7 [ "id" => 10 "slug" => "test" "name" => "test" "poll_id" => 4 "created_at" => "2016-11-12 20:42:42" "updated_at" => "2016-11-12 20:42:42" "votes" => [] ] 1 => array:7 [

Laravel collection contains

回眸只為那壹抹淺笑 提交于 2020-01-12 04:30:21
问题 I'm using the Laravel contains method on a collection https://laravel.com/docs/5.3/collections#method-contains. But it does not work for me. foreach ($this->options as $option) { if($options->contains($option->id)) { dd('test'); } } dd($options); looks like this: Collection {#390 #items: array:1 [ 0 => array:3 [ 0 => array:7 [ "id" => 10 "slug" => "test" "name" => "test" "poll_id" => 4 "created_at" => "2016-11-12 20:42:42" "updated_at" => "2016-11-12 20:42:42" "votes" => [] ] 1 => array:7 [

Collections.emptyList() instead of null check?

本小妞迷上赌 提交于 2020-01-11 21:55:12
问题 If I have a rarely used collection in some class which may be instantiated many times, I may sometimes resort to the following "idiom" in order to save unnecessary object creations: List<Object> list = null; void add(Object object) { if (list == null) list = new ArrayList<Object>(); list.add(object); } // somewhere else if (list != null) for (Object object : list) ; Now I was wondering if I couldn't eliminate those null checks using Collections.emptyList() , however then I would have to alter

How to join collections in Magento?

这一生的挚爱 提交于 2020-01-11 18:50:38
问题 I am trying to join a custom collection with products to show the product name (not just the id) in the admin grid widget. So far i can't find the correct syntax. I am able to retrieve the products with the product name by the following: Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('name'); and i can retrieve my custom collection with: Mage::getResourceModel('xyz_mymodule/model_collection'); How do i join the two so that the module collection is the primary

How to join collections in Magento?

房东的猫 提交于 2020-01-11 18:49:26
问题 I am trying to join a custom collection with products to show the product name (not just the id) in the admin grid widget. So far i can't find the correct syntax. I am able to retrieve the products with the product name by the following: Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('name'); and i can retrieve my custom collection with: Mage::getResourceModel('xyz_mymodule/model_collection'); How do i join the two so that the module collection is the primary

Cool tricks and expressive snippets with ruby collections/enumerables [closed]

假如想象 提交于 2020-01-11 17:06:10
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . What are your favorite code snippets with ruby collections? Preferably they should be discovery for you, be expressive, readable and

Symfony3 - How to persist an object with its collections?

雨燕双飞 提交于 2020-01-11 13:00:44
问题 I have an object "person" with several collections ("documents", "contacts", "etc"). I would like to save "person" and automatically the collection too. This is my controller: $em = $this->getDoctrine()->getManager(); $persona = new Persona(); $formulario = $this->createForm( PersonaType::class, $persona, array('action' => $this->generateUrl('persona_create'), 'method' => 'POST') ); $formulario->handleRequest($request); $em->persist($persona); $em->flush(); When I dump "$persona", I have the