collections

"Exception in thread "main" java.lang.NullPointerException when adding to a HashMapList

HashMapList keeps its elements inside a HashMap) and when I call add method this error message will be shown in the concole "Exception in thread "main" java.lang.NullPointerException public class HashMapList<K, V extends Product> extends AbstractList<Product> { public V element; public int index; Map<Integer, V> map; public HashMapLi...

When and why we have to implement Comparable interface??

in which situations we have to implement the Comparable interface? ...

Using JDOQL results in Scala

I'm trying to use a JDO with Google App Engine and Scala. The api for the execute returns Object (but it's really a java collection) and I want to get it into a scala list to iterate over it. My code looks like this so far: val pm = PMF.factory.getPersistenceManager val query = "select from User " val gamelist:List[User] = List(pm.ne...

Why the NullPointerException will be thrown here??

this is my collection which I make: Test<v> map = new Test<V>(); but when I call sort method which I override it in Test class and also map1 is one collection that I make it in the Test class which will keeps the elements that I add to the map collection,this exception will be thrown that it is for line 5:a[i] = map.get(new Integer(i)...

Custom collection question

I have a CustomerRepository class (in my BL), and I am returning a collection as follows: public static ICollection<Customer> FindCustomers() { Collection<Customer> customers = null; try { customers = DAL.GetCustomers(); } catch (Exception ex) { //l...

C# Generics and Collections

I have an two interfaces defined as follows: public interface IFoo { ... } Public interface IFooWrapper<T> where T : IFoo { T Foo {get;} } I want to be able to declare a collection of IFooWrappers but I don't want to specify the implementation of IFoo. Ideally I want to do something like the: IList<IFooWrapper<*>> myList; I can...

Can we modify properties of object which is in Queue - C# ?

I have used System.Collections.Queue and its object form_elements_queue if (form_elements_queue.Count > 0) queue_element = (RecordQueue)form_elements_queue.Peek(); I'm modifying the queue_element like below, queue_element.Children--; RecordQueue is my custom Type which I Enqueue in form_elements_queue. but its not referenci...

Criteria for selecting the right STL container for the job?

Do you just base your STL container selections on the following attributes? Searching/Updating Insertion and Deletion If not, what else do you base your selections upon? Is there any reference out there that lists how each container performs across all these different attributes? ...

C#: How should I use properties when dealing with List<T> members

When I want to make a value type read-only outside of my class I do this: public class myClassInt { private int m_i; public int i { get { return m_i; } } public myClassInt(int i) { m_i = i; } } What can I do to make a List<T> type readonly (so they can't add/remove elements to/from it) outside of my ...

Linq to SQL - Filter by "All Children" in "FilterCollection"

I want to return all the entities of a database where ALL child elements of a parent are found in the control collection. So, I thought something like this would work: var toInclude = new List<int>{1, 2, 3}; var result = allObjs.Where(obj => obj.Children.All(child => toInclude.Contains(child))); That doesn't work. It returns all ent...

How to check Array of strings contains a particular string?

I'm using .NET 2.0 I have a large array of string. I want to check whether a particular string is there in the array or not, I'm not sure, whether following code is optimized or I need to make it more optimized. please guide. string []test_arr= new string[]{"key1","key2","key3"}; Boolean testCondition = (new List<string>(test_arr)).Cont...

C#: Difference between List<T> and Collection<T> (CA1002, Do not expose generic lists)

Tried to run Run Code Analysis on a project here, and got a number of warnings that said something like this: CA1002 : Microsoft.Design : Change 'List<SomeType>' in 'SomeClass.SomeProtectedOrPublicProperty' to use Collection, ReadOnlyCollection or KeyedCollection Why should I use Collection<T> instead of List<T>? When I look at the...

WPF ICollectionView Refresh

Hi. Is there any way how to do ICollectionView.Refresh() or CollectionViewSource.GetDefaultView(args.NewValue).Refresh(); in a separate thread? I know I can use dispatcher, but this collection is binded to a ListView and it throws cross thread Exceptions. The reason why I need a second thread is, that I have Control which dis...

How to best represent selectable items in a collection within the M-V-VM design pattern?

I'm just beginning to explore the M-V-VM design pattern while redeveloping an application and I'm running across a consistent theme where I have collections that I need my ViewModel to expose to the View which contain items which are to be selected by the user. Please note that when I say "selected" what I mean is that they are chosen in...

Which approach is recommended : aggregateRoot.Items.Add(...) or aggregateRoot.AddItem(...)

Which approach is recommended in a DDD world... and why ? aggregateRoot.Items.Add(...) aggregateRoot.AddItem(...) I think the first option is better since it is more related to the ubiquitous language. Should I expose a readonly (IEnumerable) collection and some AddItem()/RemoveItem()/etc on the aggregateRoot (option 1) or expose a ...

Need a Java map/table with multiple keys to one value. Value is commonly altered

What I need is a collection which allows multiple keys to access a single object. I need to apply frequent alterations to this object. It also must be efficient for 500k+ entries. ...

.Net - Fastest way to sum a collection of numeric values

I have a method which summarizes a collection of decimal values using a method similar to this... Dim _amountCollection as New List(Of Decimal) _amountCollection.Add(145.12D) _amountCollection.Add(11.32D) _amountCollection.Add(6547.07D) Dim _totalAmount as Decimal For Each _individualAmount as Decimal in _amountCollection _totalAmou...

Helper in order to remove null reference in Java List ?

Hi, Suppose the following List List<String> list = new ArrayList<String>(); list.add("s1"); list.add("s2"); list.add(null); list.add("s3"); list.add(null); list.add("s4"); I need a Helper class that removes null references. Something like SomeHelper.removeNullReference(list); Now, list only contains "s1", "s2", "s4", "s4". Non-nul...

Java: Collection RemoveAll Ignoring Case?

Ok so here is my issue. I have to HashSet's, I use the Removeall method to delete values that exist in one set from the other. Prior to calling the method, I obviously add the values to the Sets. I call .toUpperCase() on each String before adding because the values are of different cases in both lists. There is no rhyme or reason to th...

removing from a collection

I have a collection of instances of class A. At some point an instance of A realizes that it should delete itself. I want to inform the collection of this, but I do not want A to know anything about the collection. What is the best way to go about this? It seems to me like A knowing about the collection is very bad coupling, but if I am...