0
голосов
1ответов
150 просмотров

Modfying a collection (Generics) in a persistent object leads to exceptions or loss of data

What I have? An object that is saved in a static variable and called whenever needed This object interfaces with another application. I have two collections (Generic Lists) in this object Logs And "Data That Is PreFeteched" to be used later Problem is when more than one person is trying to u...

2
голосов
5ответов
127 просмотров

checking if list<myobject> is already in the collection</myobject>

normally with a hashtable I do: if(!myHash.Contains(someId)) { // insert to hash } If I have a List, how can I check using contains? Right now I am just creating a hashtable of user id's, and checking that, but is there a way just using just the List?

2
голосов
1ответов
563 просмотров

Using NHibernate Collection Filters with DDD collections

I am trying to map a domain model in NHibernate. The domain model is implemented with what I think is DDD style. The mapping works mostly but then when I try to use a collection filter on an a collection I get an exception which says: The collection was unreferenced. I know the problem comes fro...

3
голосов
5ответов
544 просмотров

Problem with synchronized collections of Java when doing equals() in the reverse order from multiple threads

Example scenario: Create two SynchronizedSets (s1 and s2) Pass them to two threads (T1 and T2) Start the threads T1's run() : while (forever) s1.equals(s2) T2's run() : while (forever) s2.equals(s1) What happens? - SynchronizedSet's equals acquires lock on itself It computes t...

6
голосов
3ответов
5716 просмотров

What is the meant by 'thread safe' object?

I have used generic queue in C# collection and everyone says that it is better to use the object of System.Collection.Generic.Queue because of thread safety. Please advise on the right decision to use Queue object, and how it is thread safe?

0
голосов
1ответов
556 просмотров

Several unusual errors when attempting to convert a string[] to a Dictionary<short string></short>

I have the following code that splits a string on newlines and converts it to a Dictionary for further processing: string[] splitProgram = program.Split(Environment.NewLine.ToCharArray()); short i = 0; Dictionary&lt;short, string&gt; programDictionary = splitProgram.ToDic...

62
голосов
9ответов
45836 просмотров

Comparing two List<string> for equality</string>

Other than stepping through the elements one by one, how do I compare two lists of strings for equality (in .NET 3.0): This fails: // Expected result. List&lt;string&gt; expected = new List&lt;string&gt;(); expected.Add( "a" ); expected.Add( "b" ); expected.Add( "c" ); // Actual result act...

12
голосов
6ответов
3667 просмотров

Custom Collection vs Generic Collection for public methods

What are the framework design guidelines for exposing a custom collection vs generic one? e.g public class ImageCollection : Collection&lt;Image&gt; { ... } public class Product { public ImageCollection {get; set;} } VS public class Product { public Collection&lt;Image&gt; Images{...

4
голосов
1ответов
898 просмотров

using Linq to generate a collection of things to be removed from another collection

I'm familiar with the problem of modifying a collection while looping over it with a foreach loop (i.e. "System.InvalidOperationException: Collection was modified"). However, it doesn't make sense to me that when I use Linq to create a List of keys to delete from a dictionary, then loop over my ...

0
голосов
3ответов
4338 просмотров

WCF returning a custom object with a collection of custom objects containing streams

I don't know if this could be done, but I have a WCF service that should return a custom object, the object has a collection of another custom object that contains a stream. when I try to return this object I get System.Runtime.Serialization.InvalidDataContractException: Type 'System.ServiceMod...

5
голосов
3ответов
223 просмотров

Problem with Random and Threads in .NET

I'm having trouble with the Random class in .NET, I'm implementing a threaded collection which is working fine, except for one smaller detail. The collection is a Skip list and those of you familiar with it know that for every node inserted I need to generate a new height that is &lt;= CurrentMax...

5
голосов
1ответов
1555 просмотров

Java - copying arraylist objects

I am trying to copy the contents of an arraylist into another object. I tried initializing the new ArrayList object in the following ways newArrList.addAll(oldArrList); and newArrList = new ArrayList(oldArrList); But every time I make a change to one of the array lists, the value also chang...

18
голосов
4ответов
10112 просмотров

A case-insensitive list

I need a case insensitive list or set type of collection (of strings). What is the easiest way to create one? You can specify the type of comparison you want to get on the keys of a Dictionary, but I can't find anything similar for a List.

1
голосов
1ответов
368 просмотров

c# - what collection type is recommended for self-referential many-to-many model?

What type of collection would be best in C# to implement the following requirements do you think? Need to model web file (e.g. class = "webfile"), so one class only preferred Model parent &amp; child relationship - In terms of associations a webfile can have multiple child webfiles, and child w...

7
голосов
8ответов
15168 просмотров

C# List.Find method - how can I pass a value into the predicate?

I can't work out how to do a "find" on a List I have based on use of a value that I'll pass in at run time. If you see my below code, I want to be able to find the CustomClass in the List for which it's Path parameter is equal to X, where X will be defined at run time. Any ideas how to do suc...

3
голосов
2ответов
4115 просмотров

Smalltalk collections

If I have an array of employees, how can I sorted based on employee last name?

116
голосов
8ответов
79695 просмотров

Converting a List<int> to a comma separated string</int>

Is there a way to take a List and convert it into a comma separated string? I know I can just loop and build it, but somehow I think some of you guys a more cool way of doing it? I really want to learn these types of 'tricks', so please explain or link to the docs on the method you use.

18
голосов
2ответов
10040 просмотров

CopyOnWriteArrayList throwing CurrentModificationException

I'm occasionally getting a ConcurrentModificationException when I iterate over a list. A Google search informs me that it's probably because I'm altering that list in another thread while iterating over it and that to make this problem go away I should use java.util.concurrent.CopyOnWriteArrayLi...

3
голосов
6ответов
213 просмотров

Reflection help. Make a collection from a class based on its properties?

I need a little help. I am fairly new to reflection. We're using a 3rd party api and it returns a class called "AddressList". It has public properties within it literally called Address1, Address1Name, Address1Desc, Address2, Address2Name, Address2Desc, Address3, Address3Name, Address3Desc,... Ad...

2
голосов
2ответов
630 просмотров

Can I use a C# collection to hold class instances with self-referential relationships?

I need to model in memory a collection web files, but that relationships between them. That is file A (e.g. html) may have a link to file B (e.g. css) and file C (e.g. javascript). Also file D may also require file B. If I wanted to delete file A I would need to make sure any files it uses ...

3
голосов
2ответов
949 просмотров

Generics and collections - method undefined for type

I'm working on a project, and I'm slightly stuck on one aspect of it. I need to create a class which can manipulate collections of instances of other classes. As part of this, it creates a wrapper object for each instance which has to be able to not only hold the instance, but perform certain o...

7
голосов
6ответов
5302 просмотров

Memory usage, SortedList vs List problem

I was using SortedList() in a class which stores about 15-100K data. Recently my requirements changed, data should not be stored as sorted any more so I switched to List(). However in this case I noticed that List() consumes about 20%+ more memory. 9K items: SortedList: 105MB List: 125MB ...

0
голосов
4ответов
274 просмотров

Problem with printing inside the loop: for

I have problem reading/println after the first two FOR loop in this method. This is strange. How can I solve this problem? private int spacing() { int n = numberOfTriangles(); ArrayList&lt;Double&gt; list_Xs1 = new ArrayList&lt;Double&gt;(); ArrayList&lt;Double&gt; list_Ys1 = ne...

5
голосов
2ответов
433 просмотров

Java Generics Curiosity

I have an interface A, which class B implements. The following generic method works public static &lt;T, U extends T&gt; List&lt;T&gt; listFactory(Collection&lt;U&gt; source) { return new ArrayList&lt;T&gt;(source); } but public static &lt;T&gt; List&lt;T&gt; listFactory(Collection&lt;? ...

2
голосов
1ответов
709 просмотров

WPF: How Do I edit the column properties of a base/parent class in the child class through the property editor/XAML?

I have created a class called ProductionDataUserControlBase and it derives from class UserControl. This base class has no XAML. Its purpose is to act as a base class for a grid that I encapsulate inside the class so that it can be modified when the class is inherited later. Inside the constructor...

1
голосов
2ответов
2508 просмотров

Join Collection of Objects with LINQ to SQL

Is this even possible? It seems like I should be able to. This is my issue. I need to run a web service method from a 3rd party to get a collection of available items where I need the ID and a Status property. Then I have method using LINQ to SQL that retrieves the items that are current. What ...

1
голосов
2ответов
85 просмотров

How can I see what exactly contains a proprieties variable?

I'm pretty new to Java, so don't kill me :) FileInputStream files = new FileInputStream(path); Properties prop = new Properties(); try { props.load(fis); ..... Let's say the files is: Mary goes to school, or, not. How can I see how the information was stocked i...

172
голосов
14ответов
268153 просмотров

how to get the one entry from hashmap without iterating

Is there a elegant way of obtaining only one Entry&lt;K,V&gt; from HashMap, without iterating, if key is not known. As order of entry of entry is not important, can we say something like hashMapObject.get(zeroth_index); Although I am aware that there exist no such get by index method. If I t...

8
голосов
3ответов
4861 просмотров

Hibernate/Ehcache: evicting collections from 2nd level cache not synchronized with other DB reads

I have an application using JPA, Hibernate and ehcache, as well as Spring's declarative transactions. The load on DB is rather high so everything is cached to speed things up, including collections. Now it is not a secret that collections are cached separately from the entities that own them so i...

31
голосов
11ответов
9776 просмотров

How to implement a multi-index dictionary?

Basically I want something like Dictionary, but not (as I've seen here in other question) with the keys in AND, but in OR. To better explain: I want to be able to find an element in the dictionary providing just one of the keys, not both. I also think we should consider thread-safety and the abi...