The CompareTo() method for my class is dynamic, and can range from a simple comparison to comparisons on a number of columns. This is all determined at run time, and it works great.
But in some cases, I want any attempt to sort a collection of my objects using the default comparison to just do nothing.
Having CompareTo() just return a ...
I have a simple test object model in which there are schools
schools have a collection of students.
I would like to retrive a school and all its students who are above a certain age.
I carry out the following query in the following manner :
public School GetSchoolAndStudentsWithDOBAbove(int schoolid, DateTime dob)
{
va...
I have two String arrays a,b.
String a [] = {"one","two","three"};
String b [] = {"one","Two","Three","four"};
I need to check whether both arrays are same or not , with case Insensitive .
I know , the following piece of code is perfect for case sensitive.
List <String> l1 = Arrays.asList(a);
List <String> l2 = Arrays.asList(b);...
I have the following code:
private static final Set<String> allowedParameters;
static {
Set<String> tmpSet = new HashSet();
tmpSet.add("aaa");
allowedParameters = Collections.unmodifiableSet(tmpSet);
}
And it cause:
Note: mygame/Game.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for detai...
How to make a Array List read only, so no one can add, edit or delete, once after the initialization in Java
...
The scenario is really simple. I have a read-only collection property of my custom control, and I want set the items of the collection in XAML. Like this:
<l:CustomControl>
<l:CustomControl.ControlItems>
<l:CustomItem />
<l:CustomItem />
</l:CustomControl.ControlItems>
</l:CustomControl>
The ControlItems property has in...
I have a list of objects and I need to find an object as quickly as possible (by it's name property). What data-structure should I use? I know I can use a Dictionary, but there wont ever be more than 10 items in the list, and if I remember correctly the dictionary is implemented as an array if the collection contains 10 items or less.
T...
I have two classes: Employee and EmployeeGridViewAdapter. Employee is composed of several complex types. EmployeeGridViewAdapter wraps a single Employee and exposes its members as a flattened set of system types so a DataGridView can handle displaying, editing, etc.
I'm using VS's builtin support for turning a POCO into a data source, w...
I have the following decleration:
private Dictionary<string, Dictionary<string, File>> listFiles = new Dictionary<string,Dictionary<string,File>>();
How do i add an item to the dictionary? Is there a better way to do something like this?
Info: That stores a sourcefilename, destinationfilename, and the file itself.
Edit1: Just figured...
Best explained with code I think, this is just a simple example:
public class MyPOJO {
public String name;
public int age;
public MyPOJO(String name, int age) {
this.name = name;
this.age = age;
}
}
public class MyProcessor {
public List<MyPOJO> process(List<MyPOJO> mypojos) {
List<MyPOJO>...
Given a collection of named Foos from ActiveRecord, why does Array#include? not seem to call Foo.== but yet index does?
class Foo < ActiveRecord::Base
def ==(s)
self.name == s
end
end
class Bar < ActiveRecord::Base
has_many :foos
end
bar.foos << Foo.new( :name => 'hmm' )
bar.foos.all.include?('hmm') # does select all from ...
I read this article where Ayende states NHibernate can (compared to EF 4):
Collection with lazy=”extra” – Lazy extra means that NHibernate adapts to
the operations that you might run on
top of your collections. That means
that blog.Posts.Count will not force a
load of the entire collection, but
rather would create a “sel...
What is the pattern (best practice) for such problem -- modifying elements (values) in collection?
Conditions:
size of the collection is not changed (no element is deleted or added)
modification is in-place
In C++ it was easy and nice, I just iterated trough a collection and changed the elements. But in C# iterating (using enumerato...
I'm working on a java project that will allows users to parse multiple files with potentially thousands of lines. The information parsed will be stored in different objects, which then will be added to a collection.
Since the GUI won't require to load ALL these objects at once and keep them in memory, I'm looking for an efficient way t...
I have a list of users in local store that I need to update from a remote list of users every once in a while. Basically:
If a remote user already exists locally, update its fields.
If a remote user doesn't already exist locally, add the user.
If a local user doesn't appear in the remote list, deactivate or delete.
If a local user also...
I'm a C++ expert, but not at all for C#. I created a Dictionary<string, STATS>, where STATS is a simple struct. Once I built the dictionary with initial string and STATS pairs, I want to modify the dictionary's STATS value. In C++, it's very clear:
Dictionary<string, STATS*> benchmarks;
Initialize it...
STATS* stats = benchmarks[item.K...
I have problem with JavaConversions with 2.8 beta:
import scala.collection.JavaConversions._
class Utils(dbFile : File, sep: String) extends IUtils {
(...)
def getFeatures() : java.util.List[String] = csv.attributes.toList
}
And then exception:
[INFO] Utils.scala:20: error: type mismatch;
[INFO] found : List[String]
[IN...
So in Java, whenever an indexed range is given, the upper bound is almost always exclusive.
From java.lang.String:
substring(int beginIndex, int endIndex)
Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1
From java.util....
public class GamePiece {
public GamePiece(char cLetter, int nPointValue) {
m_cLetter=cLetter;
m_nPointValue=nPointValue;
m_nTurnPlaced=0; //has not been placed on game board yet.
}
public char GetLetter() {return m_cLetter;}
public int GetPointValue() {return m_nPointValue;}
public int GetT...
I have an ArrayList that I want to use to hold RaceCar objects that extend the Thread class as soon as they are finished executing. A class, called Race, handles this ArrayList using a callback method that the RaceCar object calls when it is finished executing. The callback method, addFinisher(RaceCar finisher), adds the RaceCar object t...