Search Results

Search found 2563 results on 103 pages for 'collections'.

Page 18/103 | < Previous Page | 14 15 16 17 18 19 20 21 22 23 24 25  | Next Page >

  • java: copy-on-write data structure?

    - by Jason S
    Is there anything in Java that implements something like the following interface MSet<T> extends Iterable<T> { /** * return a new set which consists of this set plus a new element. * This set is not changed. */ MSet<T> add(T t); /** * return a new set which consists of this set minus a designated element. * This set is not changed. */ MSet<T> remove(T t); }

    Read the article

  • Java Double entry table

    - by Tom
    Hi, Does anyone know a double entry table implementation in java I can download ? I need to do something like this 1 2 3 _______ a| x y z b| h l m c| o a k table.get(a,1) would return x Of course, it should use any Object as key, value, etc Thanks in advance

    Read the article

  • addAttributeToFilter and OR condition in Magento's Collection

    - by ÉricP
    Hi, I'd like to select products depending on several criteria from different attribute. I know how to user $collection->addAttributeToFilter('someattribute', array('like' => '%')); But I'd like to use several attribute for OR condition. Like: $collection->addAttributeToFilter('someattribute', array('like' => 'value'));` OR $collection->addAttributeToFilter('otherattribute', array('like' => 'value'));` To get products which either 'someattribute' OR 'otherattribute' set to 'value' Is it possible?

    Read the article

  • Populating and Using Dynamic Classes in C#/.NET 4.0

    - by Bob
    In our application we're considering using dynamically generated classes to hold a lot of our data. The reason for doing this is that we have customers with tables that have different structures. So you could have a customer table called "DOG" (just making this up) that contains the columns "DOGID", "DOGNAME", "DOGTYPE", etc. Customer #2 could have the same table "DOG" with the columns "DOGID", "DOG_FIRST_NAME", "DOG_LAST_NAME", "DOG_BREED", and so on. We can't create classes for these at compile time as the customer can change the table schema at any time. At the moment I have code that can generate a "DOG" class at run-time using reflection. What I'm trying to figure out is how to populate this class from a DataTable (or some other .NET mechanism) without extreme performance penalties. We have one table that contains ~20 columns and ~50k rows. Doing a foreach over all of the rows and columns to create the collection take about 1 minute, which is a little too long. Am I trying to come up with a solution that's too complex or am I on the right track? Has anyone else experienced a problem like this? Create dynamic classes was the solution that a developer at Microsoft proposed. If we can just populate this collection and use it efficiently I think it could work.

    Read the article

  • When to use LinkedList<> over ArrayList<>?

    - by sdellysse
    I've always been one to simply use List<String> names = new ArrayList<String>(); I use the interface as the type name for portability, so that when I ask questions such as these I can rework my code. When should LinkedList should be used over ArrayList and vice-versa?

    Read the article

  • Choosing design method for ladder-like word game.

    - by owca
    I'm trying to build a simple application, with the finished program looking like this : I will also have to implement two different GUI layouts for this. Now I'm trying to figure out the best method to perform this task. My professor told me to introduce Element class with 4 states : - empty - invisible (used in GridLayout) - first letter - other letter I've thought about following solutions (by List I mean any sort of Collection) : 1. Element is a single letter, and each line is Element[]. Game class will be array of arrays Element[]. I guess that's the dumbest way, and the validation might be troublesome. 2. Like previously but Line is a List of Element. Game is an array of Lines. 3. Like previously but Game is a List of Lines. Which one should I choose ? Or maybe do you have better ideas ? What collection would be best if to use one ?

    Read the article

  • Self-updating collection concurrency issues

    - by DEHAAS
    I am trying to build a self-updating collection. Each item in the collection has a position (x,y). When the position is changed, an event is fired, and the collection will relocate the item. Internally the collection is using a “jagged dictionary”. The outer dictionary uses the x-coordinate a key, while the nested dictionary uses the y-coordinate a key. The nested dictionary then has a list of items as value. The collection also maintains a dictionary to store the items position as stored in the nested dictionaries – item to stored location lookup. I am having some trouble making the collection thread safe, which I really need. Source code for the collection: public class PositionCollection<TItem, TCoordinate> : ICollection<TItem> where TItem : IPositionable<TCoordinate> where TCoordinate : struct, IConvertible { private readonly object itemsLock = new object(); private readonly Dictionary<TCoordinate, Dictionary<TCoordinate, List<TItem>>> items; private readonly Dictionary<TItem, Vector<TCoordinate>> storedPositionLookup; public PositionCollection() { this.items = new Dictionary<TCoordinate, Dictionary<TCoordinate, List<TItem>>>(); this.storedPositionLookup = new Dictionary<TItem, Vector<TCoordinate>>(); } public void Add(TItem item) { if (item.Position == null) { throw new ArgumentException("Item must have a valid position."); } lock (this.itemsLock) { if (!this.items.ContainsKey(item.Position.X)) { this.items.Add(item.Position.X, new Dictionary<TCoordinate, List<TItem>>()); } Dictionary<TCoordinate, List<TItem>> xRow = this.items[item.Position.X]; if (!xRow.ContainsKey(item.Position.Y)) { xRow.Add(item.Position.Y, new List<TItem>()); } xRow[item.Position.Y].Add(item); if (this.storedPositionLookup.ContainsKey(item)) { this.storedPositionLookup[item] = new Vector<TCoordinate>(item.Position); } else { this.storedPositionLookup.Add(item, new Vector<TCoordinate>(item.Position)); // Store a copy of the original position } item.Position.PropertyChanged += (object sender, PropertyChangedEventArgs eventArgs) => this.UpdatePosition(item, eventArgs.PropertyName); } } private void UpdatePosition(TItem item, string propertyName) { lock (this.itemsLock) { Vector<TCoordinate> storedPosition = this.storedPositionLookup[item]; this.RemoveAt(storedPosition, item); this.storedPositionLookup.Remove(item); } } } I have written a simple unit test to check for concurrency issues: [TestMethod] public void TestThreadedPositionChange() { PositionCollection<Crate, int> collection = new PositionCollection<Crate, int>(); Crate crate = new Crate(new Vector<int>(5, 5)); collection.Add(crate); Parallel.For(0, 100, new Action<int>((i) => crate.Position.X += 1)); Crate same = collection[105, 5].First(); Assert.AreEqual(crate, same); } The actual stored position varies every time I run the test. I appreciate any feedback you may have.

    Read the article

  • Having Issue with Bounded Wildcards in Generic

    - by Sanjiv
    I am new to Java Generics, and I'm currently experimenting with Generic Coding....final goal is to convert old Non-Generic legacy code to generic one... I have defined two Classes with IS-A i.e. one is sub-class of other. public class Parent { private String name; public Parent(String name) { super(); this.name = name; } } public class Child extends Parent{ private String address; public Child(String name, String address) { super(name); this.address = address; } } Now, I am trying to create a list with bounded Wildcard. and getting Compiler Error. List<? extends Parent> myList = new ArrayList<Child>(); myList.add(new Parent("name")); // compiler-error myList.add(new Child("name", "address")); // compiler-error myList.add(new Child("name", "address")); // compiler-error Bit confused. please help me on whats wrong with this ?

    Read the article

  • Multiple indexes for a Java Collection - most basic solution?

    - by chris_l
    Hi, I'm looking for the most basic solution to create multiple indexes on a Java Collection. Required functionality: When a Value is removed, all index entries associated with that value must be removed. Index lookup must be faster than linear search (at least as fast as a TreeMap). Side conditions: It should ideally work with JavaSE (6.0) alone - no extra libraries, if possible. If necessary, then only small (not something like Lucene), common and well tested libraries. No database! Of course, I could write a class that manages multiple Maps myself. But I'd like to know, if it can be done without - while still getting a simple usage similar to using a single indexed java.util.Map. Thanks, Chris

    Read the article

  • scala 2.8 breakout

    - by oxbow_lakes
    In Scala 2.8, there is an object in scala.collection.package.scala: def breakOut[From, T, To](implicit b : CanBuildFrom[Nothing, T, To]) = new CanBuildFrom[From, T, To] { def apply(from: From) = b.apply() ; def apply() = b.apply() } I have been told that this results in: > import scala.collection.breakOut > val map : Map[Int,String] = List("London", "Paris").map(x => (x.length, x))(breakOut) map: Map[Int,String] = Map(6 -> London, 5 -> Paris) What is going on here? Why is breakOut being called as an argument to my List?

    Read the article

  • Why is TreeSet<T> an internal type in .NET?

    - by Justin Niessner
    So, I was just digging around Reflector trying to find the implementation details of HashSet (out of sheer curiosity based on the answer to another question here) and noticed the following: internal class TreeSet<T> : ICollection<T>, IEnumerable<T>, ICollection, IEnumerable, ISerializable, IDeserializationCallback Without looking too deep into the details, it looks like a Self-Balancing Binary Search Tree. My question is, is there anybody out there with the insight as to why this class is internal? Is it simply because the other collection types use it internally and hide the complexities of a BST from the general masses...or am I way off base?

    Read the article

  • Initial capacity of collection types, i.e. Dictionary, List

    - by Neil N
    Certain collection types in .Net have an optional "Initial Capacity" constructor param. i.e. Dictionary<string, string> something = new Dictionary<string,string>(20); List<string> anything = new List<string>(50); I can't seem to find what the default initial capacity is for these objects on MSDN. If I know I will only be storing 12 or so items in a dictionary, doesn't it make sense to set the initial capacity to something like 20? My reasoning is, assuming the capacity grows like it does for a StringBuiler, which doubles each time the capacity is hit, and each re-allocation is costly, why not pre-set the size to something you know will hold your data, with some extra room just in case? If the initial capacity is 100, and I know I will only need a dozen or so, it seems as though the rest of that allocated RAM is allocated for nothing. Please spare me the "premature optimization" speil for the O(n^n)th time. I know it won't make my apps any faster or save any meaningful amount of memory, this is mostly out of curiosity.

    Read the article

  • Undo/Redo using Memento: Stack, Queue or just LinkedList?

    - by serhio
    What is the best having when implementing Memento pattern (for Undo/Redo) in witch collection to Keep Mementos? Basically, I need this(c = change, u = undo, r = redo): 0 *c -1 0 *c -2 -1 0 *c -3 -2 -1 0 <u -2 -1 0 1 *c -3 -2 -1 0 Variants: LinkedList - possible in principle, maybe not optimized. Queue - not adapted for this task, IMO. Stack - not adapted for undo AND redo; Double Stack - maybe optimal, but can't control the undo maximum size.

    Read the article

  • Scala 2.8.1 implicitly convert to java.util.List<java.util.Map<String, Object>>

    - by Ralph
    I have a Scala data structure created with the following: List(Map[String, Anyref]("a" -> someFoo, "b" -> someBar)) I would like to implicitly convert it (using scala.collection.JavaConversions or scala.collection.JavaConverters) to a java.util.List<java.util.Map<String, Object>> to be passed the a Java method that expects the latter. Is this possible? I have already created the following method that does it, but was wondering if it can be done automatically by the compiler? import scala.collection.JavaConversions._ def convertToJava(listOfMaps: List[Map[String, AnyRef]]): java.util.List[java.util.Map[String, Object]] = { asJavaList(listOfMaps.map(asJavaMap(_))) }

    Read the article

  • how to make accessor for Dictionary in a way that returned Dictionary cannot be changed C# / 2.0

    - by matti
    I thought of solution below because the collection is very very small. But what if it was big? private Dictionary<string, OfTable> _folderData = new Dictionary<string, OfTable>(); public Dictionary<string, OfTable> FolderData { get { return new Dictionary<string,OfTable>(_folderData); } } With List you can make: public class MyClass { private List<int> _items = new List<int>(); public IList<int> Items { get { return _items.AsReadOnly(); } } } That would be nice! Thanks in advance, Cheers & BR - Matti NOW WHEN I THINK THE OBJECTS IN COLLECTION ARE IN HEAP. SO MY SOLUTION DOES NOT PREVENT THE CALLER TO MODIFY THEM!!! CAUSE BOTH Dictionary s CONTAIN REFERENCES TO SAME OBJECT. DOES THIS APPLY TO List EXAMPLE ABOVE? class OfTable { private string _wTableName; private int _table; private List<int> _classes; private string _label; public OfTable() { _classes = new List<int>(); } public int Table { get { return _table; } set { _table = value; } } public List<int> Classes { get { return _classes; } set { _classes = value; } } public string Label { get { return _label; } set { _label = value; } } } so how to make this immutable??

    Read the article

  • How do I know if I'm iterating on the last item of the collection?

    - by Camilo Martin
    I want to do something different on the last KeyValuePair of the Dictionary I'm iterating on. For Each item In collection If ItsTheLastItem DoX() Else DoY() End If Next Is this possible? Edit: As Jon correctly remarks, Dictionaries are not the kind of thing that's sorted, so I should mention that I only want to do this when displaying results to the user, and it doesn't matter if later on the last item is different. In another note, I'll use my own answer but I'll accept the most upvoted one after I check back in some hours.

    Read the article

  • Unit Testing - Am I doing it right?

    - by baron
    Hi everyone, Basically I have been programing for a little while and after finishing my last project can fully understand how much easier it would have been if I'd have done TDD. I guess I'm still not doing it strictly as I am still writing code then writing a test for it, I don't quite get how the test becomes before the code if you don't know what structures and how your storing data etc... but anyway... Kind of hard to explain but basically lets say for example I have a Fruit objects with properties like id, color and cost. (All stored in textfile ignore completely any database logic etc) FruitID FruitName FruitColor FruitCost 1 Apple Red 1.2 2 Apple Green 1.4 3 Apple HalfHalf 1.5 This is all just for example. But lets say I have this is a collection of Fruit (it's a List<Fruit>) objects in this structure. And my logic will say to reorder the fruitids in the collection if a fruit is deleted (this is just how the solution needs to be). E.g. if 1 is deleted, object 2 takes fruit id 1, object 3 takes fruit id2. Now I want to test the code ive written which does the reordering, etc. How can I set this up to do the test? Here is where I've got so far. Basically I have fruitManager class with all the methods, like deletefruit, etc. It has the list usually but Ive changed hte method to test it so that it accepts a list, and the info on the fruit to delete, then returns the list. Unit-testing wise: Am I basically doing this the right way, or have I got the wrong idea? and then I test deleting different valued objects / datasets to ensure method is working properly. [Test] public void DeleteFruit() { var fruitList = CreateFruitList(); var fm = new FruitManager(); var resultList = fm.DeleteFruitTest("Apple", 2, fruitList); //Assert that fruitobject with x properties is not in list ? how } private static List<Fruit> CreateFruitList() { //Build test data var f01 = new Fruit {Name = "Apple",Id = 1, etc...}; var f02 = new Fruit {Name = "Apple",Id = 2, etc...}; var f03 = new Fruit {Name = "Apple",Id = 3, etc...}; var fruitList = new List<Fruit> {f01, f02, f03}; return fruitList; }

    Read the article

< Previous Page | 14 15 16 17 18 19 20 21 22 23 24 25  | Next Page >