Is there something like find_if in Java?
In C++, I can use find_if with a predicate to find an element in a container. Is there something like that in Java? The contains method on collections uses equals and can not be parameterized. ...
In C++, I can use find_if with a predicate to find an element in a container. Is there something like that in Java? The contains method on collections uses equals and can not be parameterized. ...
java.util.Collections has several unmodifiable methods that provide unmodifiable collection views by wrapping collections in decorators that prohibit mutation operations. Java 6 added support for java.util.NavigableSet and java.util.NavigableMap. I'd like to be able to have unmodifiable NavigableSets and NavigableMaps, but java.util.Co...
I've got a object that defines a 'natural sort order' using Comparable<>. These are being stored in TreeSets. Other than removing and re-adding the object, is there another way to update the sort when the members that are used to define the sort order are updated? ...
So, I have a new project I am planning on taking, and needed to know what skills will be required to achieve this project. The project is to do intensive data collection in the field where they don't have internet access. As part of the data collection, images will be uploaded as part of the data collection which will have to be resized...
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...
scala> val m = Map(1 -> 2) m: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2) scala> m.map{case (a, b) => (a+ 1, a+2, a+3)} res42: scala.collection.immutable.Iterable[(Int, Int, Int)] = List((2,3,4)) What I want is for the result type to be List[(Int, Int, Int)]. The only way I found is: scala> m.map{case (a, b) => (a+ 1, a+2...
i have a collection in the mapping: <bag name="Values" cascade="all-delete-orphan" lazy="false" inverse="true"> <key column="[TemplateId]"/> <one-to-many class="MyNamespace.Value, MyLib"/> </bag> the Value object has a foreign key [TemplateId]. both entities has their generator set to "identity". when i call session.Save() for th...
Hi, I'm trying to convert the following structure: Name Metadata Metadata Name Metadata Metadata with data such as Fred Surname, Bill Dob, 20/01/2009 Mike Surname, Jones Dob, 10/09/2000 into a collection of an anonymous class with the following properties: Name, Surname, Dob I'm trying to do it through Linq an...
Is there any Library for .NET that returns SPARQL results in some structured List instead of standard XML format? I am using SemWeb. I could not find any such method. ...
I want to convert the items to a String array or the type that I used to fill the ListBox.DataSource. The type has overridden ToString() but I can't seems to get it converted, not even to String[]. String[] a = (String[])ListBox1.Items; Contacts[] b = (Contacts[])ListBox1.Items; ...
I have come across a class that has an immutable property: MyObject[] allObjs The property is initialized like this: List<MyObject> objs = createAllMyObjects(); allObjs = objs.toArray(new MyObject[objs.size()]); When it is exposed through the accessor, it's done as a List: public List<MyObject> getAllMyObjects() { return Colle...
I find myself using the current pattern quite often in my code nowadays var dictionary = new Dictionary<type, IList<othertype>>(); // Add stuff to dictionary var somethingElse = dictionary.ContainsKey(key) ? dictionary[key] : new List<othertype>(); // Do work with the somethingelse variable Or sometimes var dictionary = new Dictiona...
I know that to be Traversable, you need only have a foreach method. Iterable requires an iterator method. Both the Scala 2.8 collections SID and the "Fighting Bitrot with Types" paper are basically silent on the subject of why Traversable was added. The SID only says "David McIver... proposed Traversable as a generalization of Iterable....
Collections.sort(someList, new Comparator<SomeObject>() { public int compare(final SomeObject object1, final SomeObject object2) { return (object1.getSomeDate()).compareTo(object2.getSomeDate()); }} ); Would it give me the objects with latest dates meaning the list will contain the set o...
I am trying to figure out a way to leverage generics so I can make the property Value be an actual type that initialized (not sure if this is the correct way of saying it) when my collection class is created. I would like to have the syntax be something like: var list = new ListItemCollection<Guid>(parameters would go here); I have t...
In Mongo my understanding is that you can have databases and collections. I'm working on a social-type app that will have blogs and comments (among other things) and had previously be using MySQL and pretty heavy partitioning in an attempt to limit possible concurrency issues. With MySQL I've stuffed all my user data into a _user databa...
I need a data structure that acts like a SortedDictionary<int, double> but is sorted based on the values rather than the keys. I need it to take about 1-2 microseconds to add and remove items when we have about 3000 items in the dictionary. My first thought was simply to switch the keys and values in my code. This very nearly works. ...
I have a collection that is binded to my Listview. I have provided options to user to "move up" "move down" the selected item in the list view. I have binded the selected item of the listview to my viewmodel, hence I get the item in the collection on which user want to do the operation. I have attached "move up" "move down" commands in...
I am sick of doing blocks of code like this for various bits of code I have: if (dict.ContainsKey[key]) { dict[key] = value; } else { dict.Add(key,value); } and for lookups (i.e. key -> list of value) if (lookup.ContainsKey[key]) { lookup[key].Add(value); } else { lookup.Add(new List<valuetype>); ...
Is it generally considered bad practice to provide Iterator implementations that are "infinite"; i.e. where calls to hasNext() always(*) return true? Typically I'd say "yes" because the calling code could behave erratically, but in the below implementation hasNext() will return true unless the caller removes all elements from the List t...