Do you know a js library that implements a generic Iterator class for collections (be it Arrays or some abstract Enumerable) with a full set of features, like the Google Common or the Apache Commons?
I have a number of database table that looks like this:
EntityId int : 1
Countries1: "1,2,3,4,5"
Countries2: "7,9,10,22"
I would like to have NHibernate load the Country entities identifed as 1,2,3,4,5,7,9 etc. whenever my EntityId is loaded.
The reason for this is that we want to avoid a proliferation of joins, as there are scores of these collections.
I'd like to fill System.Windows.Forms.ListView with the items I've stored in a separate System.Collections.Generics.List<. I would like to avoid to store the data twice, once in the List< and once as a string in ListViewItem. Is there a way to make ListViewItem use some callback function to obtain the text to put in its columns from the Tag property, instead of using its Text property?
This compiles well for me - However other people on a different thread are saying that protected classes cannot be declared in c# at top level
Is that the case?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
protected class CsvReader
{
}
}
Consider I have an array of elements out of which I want to create a new 'iterable' which on every next applies a custom 'transformation'. What's the proper way of doing it under python 2.x?
For people familiar with Java, the equivalent is Iterables#transform from google's collections framework.
How to set up auto mapping to map System.Collections.Generics.ISet<T> correctly?
I tried implementing IHasManyConvention, but in intellisense it seems that IOneToManyCollectionInstance does not have anything for that(?)
I have a need to load an entire LINQ-to-SQL object graph from a certain point downwards, loading all child collections and the objects within them etc. This is going to be used to dump out the object structure and data to XML.
Is there a way to do this without generating a large hard coded set of DataLoadOptions to 'shape' my data?
ok I was going to edit my previous question but i wasnt sure if it was the right way to do it so i'll just give another question about Comparator, now i want to be able to sort with different ways. I have a bank checks and i want to sort with checkNumber then checkAmount
i managed to do it with checkNumber but couldnt figure out how with checkAmount
here is how i did it for checkNumber:
import java.util.Comparator;
public class Check implements Comparator {
private int checkNumber;
private String description;
private double checkAmount;
public Check() {
}
public Check(int newCheckNumber, double newAmountNumber) {
setCheckNumber(newCheckNumber);
setAmountNumber(newAmountNumber);
}
public String toString() {
return checkNumber + "\t\t" + checkAmount;
}
public void setCheckNumber(int checkNumber) {
this.checkNumber = checkNumber;
}
public int getCheckNumber() {
return checkNumber;
}
public void setAmountNumber(double amountNumber) {
this.checkAmount = amountNumber;
}
public double getAmountNumber() {
return checkAmount;
}
@Override
public int compare(Object obj1, Object obj2) {
int value1 = ((Check) obj1).getCheckNumber();
int value2 = ((Check) obj2).getCheckNumber();
int result = 0;
if (value1 > value2){
result = 1;
}
else if(value1 < value2){
result = -1;
}
return result;
}
}
import java.util.ArrayList;
import java.util.Collections;
import test.CheckValue;
public class TestCheck {
public static void main(String[] args) {
ArrayList List = new ArrayList();
List.add(new Check(445, 55.0));
List.add(new Check(101,43.12));
List.add(new Check(110,101.0));
List.add(new Check(553,300.21));
List.add(new Check(123,32.1));
Collections.sort(List, new Check());
System.out.println("Check Number - Check Amount");
for (int i = 0; i < List.size(); i++){
System.out.println(List.get(i));
}
}
}
thank you very much in advance and please tell me if im submiting things in the wrong way.
Hi All,
i am trying to figure out how to write a linq query that will return a child collections "name" property as a string.
I have a BO that has a "options" property where the options are the "name" property of each option in an "order" object.
I would like the result to look something like
order.id = 12312
order.date = 12/03/10
order.options = "Option 1 Name, Option 2 Name, Option 3 Name"
I hope this makes sense. thanks for any and all help!
I am working on a small GUI application written in Scala. There are a few settings that the user will set in the GUI and I want them to persist between program executions. Basically I want a scala.collections.mutable.Map that automatically persists to a file when modified.
This seems like it must be a common problem, but I have been unable to find a lightweight solution. How is this problem typically solved?
I am trying to deserialize a field:
"presenters":[{...},{...}]
but some of the rows come back with only:
"presenters":""
When the serializer gets to the row with that empty string I get:
Error converting value "" to type 'System.Collections.Generic.List`1[DataPrototype.Model.Presenter]'.
Am I right in thinking that I need a JsonConverter that will change the empty string into an empty List?
I have System.Collections.Generic.List _myList and many threads can read from it or add items to it simultaneously. From what I've read I should using 'BlockingCollection' so this will work. I also read about ReaderWriterLockSlim' and 'lock', but I don't figure out how to use them instead ofBlockingCollection`, so my question is can I do the same with:
ReaderWriterLockSlim
lock
instead of using 'BlockingCollection'. If YES, can you please provide simple example and what pros and cons of using BlockingCollection, ReaderWriterLockSlim, lock?
if anyone can help with with I would be grateful.
I am trying to make a program in c# that acts like an ATM with withdrawing, depositing money, displayed in Program.cs that is connected to Account.cs linked class programs.
At the moment it works if I manually input the data and tell it what to display, but I what to do is - Allow users to enter amounts to deposit and withdraw using overloaded implementations of the methods makeDeposit and makeWithdrawal.
I have tried many things, and can not get it to work, if anyone can help, I would be grateful if anyone can, thanks again
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Tut9
{
class Program
{
static void Main(string[] args)
{
Account myAcc = new Account();
myAcc.makeDeposit(10000);
myAcc.showBalance();
Console.WriteLine("Attempting to withdraw £" + 90);
myAcc.makeWithdrawal(90);
myAcc.showBalance();
myAcc.giveOverdraft(50);
myAcc.showBalance();
Account student = new Account(30, -100);
student.giveOverdraft(-500);
}
}
}
Account.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Tut9
{
class Account
{
////Need to know the balance & ovedraft
private int balance;
private int overdraft;
////Constructor
public Account()
{
balance = 0;
overdraft = 0;
}
public Account(int initial)
{
balance = initial;
}
public Account(int intial, int over)
{
balance = intial;
overdraft = over;
}
public void giveOverdraft(int amount)
{
overdraft = amount;
}
////Method to display the balance & overdraft
public void showBalance()
{
Console.WriteLine("The balance is now £" + balance);
if (overdraft != 0)
{
Console.WriteLine("You have an overdraft of £" + overdraft);
}
}
////Method to make a withdrawl
public void makeWithdrawal(int y)
{
balance = balance - y;
Console.WriteLine("Withdrew £" + y);
}
////Method to make deposit
public void makeDeposit(int x)
{
balance = balance + x;
Console.WriteLine("Desposited £" + x);
}
}
}
For example, "Don't return objects by value if they are expensive to copy" (RVO can't always be used). This advice might change because of rvalue references.
The same might be said about storing collections of pointers to objects, because copying them by value into the collection was too expensive; this reason might no longer be valid.
Or the use of enums might be discouraged in favour of "enum class".
What other practices or tips will change?
I have a simple function that creates a generic List:
function test()
{
$genericType = [Type] "System.Collections.Generic.List``1"
[type[]] $typedParameters = ,"System.String"
$closedType = $genericType.MakeGenericType($typedParameters)
[Activator]::CreateInstance($closedType)
}
$a = test
The problem is that $a is always null no matter what I try. If I execute the same code outside of the function it works properly.
Thoughts?
I have an IPEndPoint a and b, whose IPAddress and Port are exactly the same, but the == operator is on the IPEndPoint not returning true. To make things even stranger, I tried to circumvent the problem by simply comparing the IPAddress and Port individually and it is STILL not returning true.
Has anyone encountered this before? If so, I am all ears to performant solutions. We have collections of as many as 10k IPEndPoints and are querying into them via LINQ (PLINQ pretty soon).
I created a high memory utilization dump and using !dumpheap -stat and !dumpheap -mt I got the address of two large string generic list of 30 MB each.
I want to know more about these lists. What they contain or which piece of code is using them.
Is there a way to find them out?
0:000 !do 2b370038
Name: System.Object[]
MethodTable: 71e240bc
EEClass: 71c0da54
Size: 33554448(0x2000010) bytes
Array: Rank 1, Number of elements 8388608, Type CLASS
Element Type: System.Collections.Generic.List`1[[System.String, mscorlib]]
Fields:
None
I noticed in premium edition Data menu with Data Compare option which does everything I need. Just wondering whether there is a way to automate what's done in GUI from my application.
Ideally I'd like to get collections of different/left/right rows
If I deploy a solution at farm level, is there a way by which i can prevent the owners of the various site collections from activating the features present in that solution?
Talking about System.Collections.Generic.List here.
With example below can Method1 and Method2 execute and the same time, on different threads without any problems?
Thanks
class Test
{
private readonly List<MyData> _data;
public Test()
{
_data = LoadData();
}
private List<MyData> LoadData()
{
//Get data from dv.
}
public void Method1()
{
foreach (var list in _data)
{
//do something
}
}
public void Method2()
{
foreach (var list in _data)
{
//do something
}
}
}
I imported System.Collections namespace in my class, but I still cant use ArrayList type. The code editor says the "class not found". I am using VS2008 & VS2010.
So has MS stopped support for this type in framworks 3.5 and upwards ?
When I do System.out.println(map) in Java, I get a nice output in stdout. How can I obtain this same string representation of a Map in a variable without meddling with standard output? Something like String mapAsString = Collections.toString(map)?
I have a class that inherits from a generic dictionary as follows:
Class myClass : System.Collections.Generic.Dictionary<int, Object>
I have added a list of values to this in a particular order, but I now wish to change that order. Is there any way (without removing and re-adding) that I could effectively re-index the values; so change the object at index 1 to now be at index 10 for example? For example, this doesn't work:
myClass[1].Index = 10;