collections

Why is there a method iterator() on java.util.Collection

纵然是瞬间 提交于 2019-12-21 07:08:19
问题 Why is there the method iterator() defined on the interface java.util.Collection when it already extends java.util.Iterable which has this very method defined. I'm thinking some sort of backward compatability or an opportunity to write some JavaDoc on the method at the collection level. Any other ideas? 回答1: Backwards compatibility. Iterable was not introducted until 1.5 with the for(Object o : iterable) construct. Previously, all collections had to provide a means to iterate them. 回答2: I

Give me a practical use-case of Multi-set

拥有回忆 提交于 2019-12-21 07:06:32
问题 I would like to know a few practical use-cases (if they are not related/tied to any programming language it will be better).I can associate Sets, Lists and Maps to practical use cases. For example if you wanted a glossary of a book where terms that you want are listed alphabetically and a location/page number is the value, you would use the collection TreeMap(OrderedMap which is a Map) Somehow, I can't associate MultiSets with any "practical" usecase. Does someone know of any uses? http://en

Sort Eloquent Collection by created_at

时光怂恿深爱的人放手 提交于 2019-12-21 06:53:08
问题 I have a table named 'posts' with the columns: 'post_id int primary increments', 'poster_id int' and 'status text' as well as an array named friends with the columns: 'user_id int primary' and 'friend_ids text'. I need to grab all the IDs in the friends text column which is easy enough using: $friends = explode(',', \Friend::where('user_id', \Sentry::getUser()->id)->first()->friend_ids); Where the data in the text column would look like '1,2,3,' etc. Then I create an Eloquent Collection

Are there plans for ImmutableEnumSet in Java 7?

≯℡__Kan透↙ 提交于 2019-12-21 06:49:04
问题 I want to have all the efficiencies of EnumSet and pass it around without worrying that somebody would modify it. 回答1: You can get an immutable EnumSet with Google collections (Guava). Resources : Guava home page Google-collections bug tracker - immutable enum set convenience constructor Google documentation - Sets.immutableEnumSet() 回答2: What's wrong with Collections.unmodifiableSet() wrapping an EnumSet ? True, the original EnumSet is still mutable, but as long as you discard the original

generic Enumeration to Iterable converter [closed]

蓝咒 提交于 2019-12-21 06:46:38
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . HttpServletRequest is using a lot of java.util.Enumeration. I would like to use them in for-each, so i need to convert them into interable. this is not a problem, but I since I have more than one project needing this I need a library to do this. I would rather not make my own - is there any standard library that

Java 9: What are collection factory methods? [closed]

最后都变了- 提交于 2019-12-21 06:41:16
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . The arrival of Java 9 brings many new features to Java's Collections API, one of which being collection factory methods. What are they and how can I implement them properly? 回答1: Note 1: To prevent the use of raw-types, I have opted to provide a generic type for each class that I

Magento - get product collection of all products

会有一股神秘感。 提交于 2019-12-21 05:35:14
问题 I need a custom product collection of all products. Currently there are no categories which contain all products of the store (as there are 8000 products we can not add them in to one extra category). What I need is on a particular CMS page the product collection of all products is displayed. So far I have a CMS page with the block: {{block type="catalog/product_list" template="catalog/product/list.phtml"}} I have created an module to override 'Mage_Catalog_Block_Product_List' I believe the

Concurrent reading and processing file line by line in Scala

◇◆丶佛笑我妖孽 提交于 2019-12-21 05:24:14
问题 Suppose I need to apply two functions f: String => A and g: A => B to each line in a large text file to create eventually a list of B . Since the file is large and f and g are expensive I would like to make the processing concurrent. I can use "parallel collections" and do something like io.Source.fromFile("data.txt").getLines.toList.par.map(l => g(f(l)) but it does not execute reading the file, f , and g concurrently. What is the best way to implement concurrency in this example? 回答1: You

Collection with very fast iterating and good addition and remove speeds

帅比萌擦擦* 提交于 2019-12-21 05:02:08
问题 I'm after a collection that I can iterate through very fast. I'll also be adding items and removing (specific) items fairly regularly and so ideally would like those operations to be fast too. I'm developing on the xbox and so am restricted to the compact framework (more or less). It's very important that I keep garbage and object allocations to a minimum, so anything where i can pre-allocate space for my objects would be great. I'll be storing uint s (but can be int s if needed) in the

Filter product collection on two categories Magento 1.7

╄→гoц情女王★ 提交于 2019-12-21 04:52:19
问题 I want to get a product collection with products in Category A or Category B. I have been able to succesfully get these products with the following php-code: $collection = Mage::getModel('catalog/product') ->getCollection() ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left') ->addAttributeToFilter('category_id', array('in' => array('finset' => 4,19))) ->addAttributeToSelect('*'); However, if the product is in both category 4 AND 19,