i have the following scenario:
public class Term{
private int _family;
public void setFamily(int family){
_family = family;
}
public int getFamily(){
return _family
}
}
public class Document{
private List<Term> _terms_in_document;
public void addTerm(Term t){
_terms_in_document.add(t);
}
}
in a different class...
Term t1 = new Term();
t1.setFamily(1);
Term t2 = new Term();
t2.setFamily(1);
Term t3 = new Term();
t3.setFamily(1);
Document d1 = new Document();
d1.addTerm(t1);
d1.addTerm(t2);
d1.addTerm(t3);
Term t4 = new Term();
t4.setFamily(1);
Term t5 = new Term();
t5.setFamily(2);
Term t6 = new Term();
t6.setFamily(3);
Document d2 = new Document();
d2.addTerm(t4);
d2.addTerm(t5);
d2.addTerm(t6);
I need to use LINQ to get those documents that contain terms with the biggest number of different families. In our example, d2 will come first because it's terms are of families 1, 2 and 3. While d1 has to come second because all of it's terms belong to the same family. I couldn't do this so far with linq, i believe it could be done without it, but it will be very complex and error prone code. Can you please help me..