collections

Bidirectional Map in .NET

Is there a .NET data structure I could use for bidirectional lookup? Here's the problem: Serialization. My object contains a field which points to one of 10 predefined static objects. When writing to the file, I write a single character representing which of the 10 objects is being referenced. At this point, I need a lookup datastructur...

Simple way to find if two different lists contain exactly the same elements?

What is the simplest way to find if two Lists contain exactly the same elements, in the standard Java libraries? It shouldn't matter if the two Lists are the same instance or not, and it shouldn't matter if the type parameter of the Lists are different. e.g. List list1 List<String> list2; // ... construct etc list1.add("A"); list2....

TransactionScope and rolling back object state

I'm looking for a solution to a design problem. This will take a bit of explaining. I would post code, but that woul make this even longer. I have a custom generic collection I use to hold Business Objects as needed. For easy of reference, call the business objects BO and the generic collection GC. Inside GC I have a private colle...

mutable fields for objects in a Java Set

Am I correct in assuming that if you have an object that is contained inside a Java Set<> (or as a key in a Map<> for that matter), any fields that are used to determine identity or relation (via hashCode(), equals(), compareTo() etc.) cannot be changed without causing unspecified behavior for operations on the collection? (edit: as allu...

pitfalls of collections of entities in Hibernate

OK, this is a follow-up question to this one, since I am really confused now. Suppose I have a one-to-many or many-to-many association between entities Person and Event such that a Person class in Java contains a Set<Event>. (Let's ignore whether Event contains a single Person or a Set<Person>.) Events are entities stored in a database...

Sorting a List of LIst by the Value of the sublist

private List<String> subList; private List<List<String>> records = new ArrayList<List<String>>(); for(....){ subList = new ArrayList<String>(); ...populate.. records.add(subList); } For example, subList has three Strings - a, b, and c. I want to sort the records by the value of b in subList. records at 0 has a list of "...

Has anyone else expierenced markup not being saved in Visual Studio 2008 in the ASP.NET designer?

Ok, I have a custom ASP.NET control that acts as a MenuBar. This control has a collection property called MenuBarItems. This collection contains essentially a collection of buttons that will be displayed on the MenuBar. Each MenuBarItem has a collection of cascading menu items. The idea is to create a recursive markup hierarchy that ...

C# How to make public getters and setters and private methods for a collection?

Hello All, I'd like to have a class "A" with a (for example) SortedList collection "SrtdLst" property, and inside this class "A" allow the addition or subtraction of "SrtdLst" items. But in a instance of the class "A", only allow to get or set the content of the items, not to add new items or subtract the existing ones. In code: class ...

Linq To Sql: Cannot implicitly convert type IEnumerable to IQueryable

Obfuscated Scenario: A person has zero, one or many pets. Using Linq to Sql, the need is to get an IQueryable list of pets for the given personID. Here's the poorly mangled/butchered/obfuscated portion of the ERD: Code: public IQueryable<Pet> GetPersonPets(int personID) { var personPets= from p in Person where ...

What is the difference between an ordered and a sorted collection?

Is there any difference between a sorted and an ordered collection? ...

Working around LinqToSQls "queries with local collections are not supported" exception

So, I'm trying to return a collection of People whose ID is contained within a locally created collection of ids ( IQueryable) When I specify "locally created collection", I mean that the Ids collection hasnt come from a LinqToSql query and has been programatically created (based upon user input). My query looks like this: var qry =...

How do I retrieve specific attributes of a relationship/collection?

Hi All, Is there a good way to retrieve all of a specific attribute from a relationship/collection? For instance, I want a list of all the names of a person's cars. Obviously I can't do the following: Person.Cars.Name(s) ...but does something of that nature exist in ruby (or is there an ActiveRecord helper method) that handles that?...

What does 'synchronized' mean?

Vector methods are synchronized. What does it mean programmatically and logically? ...

.NET HashTable Vs Dictionary - Can the Dictionary be as fast?

I am trying to figure out when and why to use a Dictionary or a HashTable. I have done a bit of a search on here and have found people talking about the generic advantages of the Dictionary which I totally agree with, which leads the boxing and unboxing advantage for a slight performance gain. But I have also read the Dictionary will n...

Read-only list of string

Is it good to use such approach for keeping read-only list of string, for example, a list of fields in ADO.NET. var list = new System.Collections.ObjectModel.ReadOnlyCollection<string>( new List<string>(4) { "type", "currency", "date", "amount" }); Or this is a superfluous solution? ...

Concurrent Modification Exception

I'm currently working on a multi-threaded application, and I occasionally receive a concurrently modification exception (approximately once or twice an hour on average, but occurring at seemingly random intervals). The faulty class is essentially a wrapper for a map -- which extends LinkedHashMap (with accessOrder set to true). The clas...

Java: how to convert HashMap<String, Object> to array

Hi, I need to convert a HashMap<String, Object> to an array; could anyone show me how it's done? ...

Hibernate: Query entities which contain a specified element in a CollectionOfElements?

Let's say I have this entity (for Hibernate): @Entity public class Person { @Id @GeneratedValue(strategy = GenerationType.AUTO) Long id; @CollectionOfElements @IndexColumn("phones_index") Set<String> phones; } For example, I want to get instances of Person where their phones contain "555-1234". How can I do a ...

Treeset to order elements in descending order

Here is the piece of code that I have used for Java 5.0 TreeSet<Integer> treeSetObj = new TreeSet<Integer>( Collections.reverseOrder() ) ; Collections.reverseOrder() is used to obtain a comparator in order to reverse the way the elements are stored and iterated. Is there a more optimized way of doing it? ...

Is there an equivalent of java.util.Properties for sets?

I want to read lines from a file into a Set or List. Is there a standard utility for doing this? If these lines are of the form [key]=[value] I can do: Properties properties = new Properties(); properties.load(new FileInputStream(file)); The values are single entries, one per line, each value becomes an entry in the Set/List I know ...