collections

When is the unmodifiablemap (really) necessary?

I have a map of constants, like this: private static Map<String, Character> _typesMap = new HashMap<String, Character>() { { put ("string", 'S'); put ("normalizedString", 'N'); put ("token", 'T'); // (...) } Do I really need to use Collections.unmodifiableMap() to...

Java Collections Logic / Over coding issue

Below is an implementation of an exercise I've been asked to do (see comments). It works, and the reason I'm posting it is that the function checkMiracle looks like it should be contained in a much smaller loop of code - I'm writing out the same thing plus one ten times. The problem is, I can't seem to find a shorter way of doing it. My ...

Bounded, auto-discarding, non-blocking, concurrent collection

I'm looking for a collection that: is a Deque/List - i.e. supports inserting elements at "the top" (newest items go to the top) - deque.addFirst(..) / list.add(0, ..). It could be a Queue, but the iteration order should be reverse - i.e. the most recently added items should come first. is bounded - i.e. has a limit of 20 items auto-dis...

collections that track changes?

is there any collection that track changes made to the collection? say which object is deleted/modified/added? The ObservableCollection just give notifications, it will not keep the removed in say a RemovedItems property. I have to keep them somewhere. actually why i am asking the question is if i bind a collection to a datagrid, it see...

Map: How to get all keys associated with a value?

Given a Map, how do I look up all keys associated with a particular value? For example: Map<Integer, Integer> map = new HashMap<Integer, Integer>(); map.put(1, 5); map.put(2, 2); map.put(3, 5); Collection<Integer> keys = map.values(5); // should return {1, 3} I'm looking for something similar to Google Collections' BiMap where values...

.NET equivalent of Java's TreeSet operations tailSet and headSet?

Hello, I'm trying to use .NET 4's SortedSet<T> collection. It seems to have everything I need minus a couple things. Q: I want to be able to fetch all elements lower or higher in comparison to a given value. In Java's TreeSet, there are methods named tailSet and headSet, which perform these operations. I'd like to be able to do the...

Removing older values from a List

I have a list that I want to be able to store 20 values. What would be a good approach to deleting older values. A better example would be, imagine a change history and I wan't to be able to store 20 latest changes, while older ones go away. Is there a special thing in C# that will let me do that or do I have to either make my own or us...

Different collections for different data sorting

Hello. I have a task to play with Java Collections framework. I need to obtain a users list from a database, and store it in a collection. (This is finished and users are stored in a HashSet). Each user is an instance of Person class described with name, surname, birth date, join date, and some other parameters which are not important no...

Collection for storing objects with date

I have some objects with Date parameters. What collection will be best for storing them and later querying for object/objects with particular date ? (like given as a String or java.util.Date format) ? EDIT: I was trying to use TofuBear's solution, but cannot make it work. let's say I am calling my function (which returns Map) with a ...

Objective-C empty array performance

I have an application that iterates over an array every step and I seem to be getting surprisingly slow results when the array is empty. So, I investigated with some follow-up tests that went something like this: NSMutableArray* ar = [NSMutableArray array]; double time = CFAbsoluteTimeGetCurrent(); for (int i = 0; i < 10000; i++) { ...

Java: how to implement `toArray` for `Collection`

Right now, I have: public <T> T[] toArray(T[] old) { T[] arr = Arrays.copyOf(old, old.length + size()); int i = old.length; for(E obj : this) { arr[i] = old.getClass().getComponentType().cast(obj); ++i; } return arr; } (Note that this does not follow the contract ...

Storing group of objects with Dates in a Map

I have a group of Events that occurred at some Dates. Each event has a Date field. Now I'd like to create a Map where for each Date (taken from all dates of events) I will assign List of Events that occurred on that date. So in pseudocode : public Map<Date, List<Event>> function(List<Event> list){ Date[]dates = new Date(list.len())...

jQuery Collection Cache

Does anyone know a good way to cache a collection of objects returned by a selector. var $platforms = $(".platforms"); var i = 0, l = $platforms.length, current; for(;i<l;i++) { current = $($platforms[i]); //calling jQuery() in a loop. Should be cached } The above code creates a jQuery instance of each element returned by $("...

C#: Add child to collection and set child's parent in same call

I'm building a sort of domain layer and I would like to be able to implement the following methods: [Note: ISet is a collection class which doesn't permit duplicates, according to checking using .Equals().] public class Parent { public ISet Children = new HashedSet<Child>; public void AddChild() { ... } public void RemoveChild() { ... ...

Retrieve Collections and Enums Selected Value WPF Property Grid

Hi All, I am using WPF PropertyGrid (http://www.codeplex.com/wpg) in my project. But i have some problems with this component. 1) I can show my IList collections in a ComboBox. But i can't retrieve selected value. How can i get selected value? 2) Enums are automatically shown in combobox, but i can't retrieve selected value like #1. ...

Collection Framework

Difference between HashSet and TreeSet? ...

asp.net datalist data binding

I am using an asp.net/c# datalist. <asp:DataList ID="EquipmentList" RepeatColumns="5"..... I have the following line inside the <ItemTemplate> tag: <a href=""><%# {I want to put something here but dont know how} %> </a> In my code behind I have a NameValueCollection variable that contains all strings: NameValueCollection myListo...

Loop a collection with Realbasic

I'm work on a tool for learning purposes, it perform a search with google apis. Using HTTPSocket I get the results of the search in json format and then parse it to dictionary with the json.parser written by CharcoalDesign.co.uk This is how looks json results: {"responseData": { "results": [ { "GsearchResultClass": "GwebSearch",...

Are there good IList and IDictionary implementations in C# that support fail-safe iteration?

Per the title - are there good built-in options in C#/.NET for fail-safe iteration over an IList or an IDictionary? Where I'm running into problems is with code similar to the following: IList<Foo> someList = new List<Foo>(); //... foreach (Foo foo in someList) { if (foo.Bar) { someList.remove(foo); } } which throws the fol...

Join a Flat Table to an EAV Table with Magento?

Hi, I am trying to manke an Adminhtml Grid which joins a table that I made called "facility" to "customer_entity" and all of its attribtues. I'm noticing that since my table is flat, and the model inherits fomr Mage_Core_Model_Mysql4_Collection_Abstract, I'm not able to use all the class_methods that I've seen as examples on the back...