collections

Proper way for two-way sorting

时光怂恿深爱的人放手 提交于 2020-01-05 08:45:16
问题 I've got a simple java pojo which looks like this: class MyClass { public String getGroup(); public String getTitle(); } Now what I want to do is to primarily sort a list of MyClass pojo by the values returned by the getTitle() method. Easy going though using my own comparator. However, what I want is that instances with the same value returned by getGroup() being followed by each other. Now what I did was something like .. compare(MyClass c1, MyClass c2) { if (c1.getGroup().compareTo(c2

Listview to display ObservableSelection

蹲街弑〆低调 提交于 2020-01-05 05:55:33
问题 I have Student table, Course table and a StudentCourse table. On my WPF, I'm making "Student" selections with combo box. How can I display the corresponding Course and its properties(CourseID, CourseName, Credit) in a listview, using ObservableCollection?. Here's my code for the combo box SelectionChanged event private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e) { int MySelect = (int)this.comboBox1.SelectedValue; var SelectedStudent = db.Students.Include(

Memory mapped collections in Java

回眸只為那壹抹淺笑 提交于 2020-01-05 04:43:05
问题 I'm filling up the JVM Heap Space. Changing parameters to give more heap space to the JVM, or changing something in my algorithm in the code not to use so much space are two of the most recommended options. But, if those two have already been tried and applied, and I still get out of memory exceptions, I'd like to see what the other options are. I found out about this example of "Using a memory mapped file for a huge matrix" and a library called HugeCollections which are an interesting way to

Sorting in Hash Maps

不问归期 提交于 2020-01-05 04:09:21
问题 I'm trying to get familiar with Collections. I have a String which is my key, email address, and a Person object (firstName, lastName, telephone, email). I read in the Java collections chapter on Sun's webpages that if you had a HashMap and wanted it sorted, you could use a TreeMap. How does this sort work? Is it based on the compareTo() method you have in your Person class? I overrode the compareTo() method in my Person class to sort by lastName. But it isn't working properly and was

In C#, how can I order this list of objects by which item is greater?

心已入冬 提交于 2020-01-05 03:45:08
问题 I have a simple class called Team, that looks like this: public class Team { public Team ParentTeam; public string Name; } So it has a Name and a reference to another team that is its Parent Team. I now have a list of Teams that I am getting back from a function List<Team> list = GetTeamsList(); Given, a few assumptions: All teams have a ParentTeam except one (the top team) Every team returned in the list is part of the same hierarchy and its only a single hierarchy (no 2 teams at the same

Render a filtered checkbox collection in a form

老子叫甜甜 提交于 2020-01-05 03:36:42
问题 I want to render a filtered collection as a checkbox list. But i have trouble to get the collection shown. i get "Catchable Fatal Error: Object of class Doctrine\ORM\PersistentCollection could not be converted to string". Below is my formtype: class PropertyfilterType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('view', EntityType::class, [ 'class' => Propsearch::class, 'choice_label' => 'propsearchviews', 'expanded' => true,

Sort collection by another collection values

送分小仙女□ 提交于 2020-01-05 02:01:08
问题 I have List<SomeData> data; public class SomeData { public int Key { get; set;} public decimal Value { get; set;} } Also i have List<int> DataOrder; I need to sort List<SomeData>data by Key , placing it in same order as List<int> DataOrder values. Is there any common algorithms for that? Example: List<SomeData> data = new List<SomeData>(); data.Add(new SomeData{ Key = 10, Value = 14 }) data.Add(new SomeData{ Key = 25, Value = 22 }) data.Add(new SomeData{ Key = 567, Value = 3 }) data.Add(new

Best way to enumerate collection when elements may be deleted during enumeration [duplicate]

五迷三道 提交于 2020-01-05 01:31:48
问题 This question already has answers here : What is the best way to modify a list in a 'foreach' loop? (11 answers) Closed 6 years ago . There is a typical collection of some class objects e.g. string for a simplicity IList<string> collection = new List<string>(); During the program flow some function needs to operate on the collection, process class object and depending on the result of operation remove processed class object from collection. E.g. following example of strings if string is

how to Iterate through an arrayList of object and find duplicates in object properties? [closed]

≡放荡痞女 提交于 2020-01-04 18:40:06
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . I have the following class: class A { ArrayList<String> s = new ArrayList<>(); double d = Double.MAX_VALUE; } I've an arrayList of

Extending a non-generic class to a generic class

核能气质少年 提交于 2020-01-04 14:29:39
问题 The Java class CircularFifoBuffer in the package org.apache.commons.collections.buffer is non-generic, and can store objects of any class. I would like to create a generified version of this, that can only hold objects of class T. My first thought was to extend CircularFifoBuffer and simply write a new 'add' method: public class CircularFifoQueue<T> extends CircularFifoBuffer { public boolean add(T data) { return super.add(data); } } However, this leaves the old 'add' method in place,